diff --git a/purchase_representative/README.rst b/purchase_representative/README.rst new file mode 100644 index 00000000000..98361681742 --- /dev/null +++ b/purchase_representative/README.rst @@ -0,0 +1,92 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +======================= +Purchase Representative +======================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:c3c1ec9335e5b0afa9656edfba111c93467e0e0334ac02b21f895b74fdfb8b3f + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/purchase-workflow/tree/19.0/purchase_representative + :alt: OCA/purchase-workflow +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/purchase-workflow-19-0/purchase-workflow-19-0-purchase_representative + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/purchase-workflow&target_branch=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module makes the field *Purchase Representative* in Purchase Orders +default to the user doing a procurement to overcome the known flaw of +Odoo user in the transaction when using SUPERUSER_ID. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Just set the *Purchase Representative* in the Purchase Order header. +Then when sending the RFQ/PO to the vendor the Purchase Representative +will be the contact person (email from and reply to). + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* ForgeFlow + +Contributors +------------ + +- Lois Rilo +- `Heliconia Solutions Pvt. Ltd. `__ + + - Bhavesh Heliconia + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/purchase-workflow `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/purchase_representative/__init__.py b/purchase_representative/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/purchase_representative/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/purchase_representative/__manifest__.py b/purchase_representative/__manifest__.py new file mode 100644 index 00000000000..da5e984345c --- /dev/null +++ b/purchase_representative/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2020 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Purchase Representative", + "summary": "Purchase Representatives will be the point of contact for " + "RFQ's and PO's", + "version": "19.0.1.0.0", + "category": "Purchases", + "website": "https://github.com/OCA/purchase-workflow", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": ["purchase_stock"], +} diff --git a/purchase_representative/i18n/it.po b/purchase_representative/i18n/it.po new file mode 100644 index 00000000000..a9a9ce34641 --- /dev/null +++ b/purchase_representative/i18n/it.po @@ -0,0 +1,22 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_representative +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2025-08-07 14:25+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.10.4\n" + +#. module: purchase_representative +#: model:ir.model,name:purchase_representative.model_stock_rule +msgid "Stock Rule" +msgstr "Regola di giacenza" diff --git a/purchase_representative/i18n/purchase_representative.pot b/purchase_representative/i18n/purchase_representative.pot new file mode 100644 index 00000000000..f7fd672ad7b --- /dev/null +++ b/purchase_representative/i18n/purchase_representative.pot @@ -0,0 +1,19 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_representative +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: purchase_representative +#: model:ir.model,name:purchase_representative.model_stock_rule +msgid "Stock Rule" +msgstr "" diff --git a/purchase_representative/models/__init__.py b/purchase_representative/models/__init__.py new file mode 100644 index 00000000000..55eae1720e2 --- /dev/null +++ b/purchase_representative/models/__init__.py @@ -0,0 +1 @@ +from . import stock_rule diff --git a/purchase_representative/models/stock_rule.py b/purchase_representative/models/stock_rule.py new file mode 100644 index 00000000000..a85d58a180e --- /dev/null +++ b/purchase_representative/models/stock_rule.py @@ -0,0 +1,21 @@ +# Copyright 2020-21 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class StockRule(models.Model): + _inherit = "stock.rule" + + def _run_buy(self, procurements): + for procurement, _rule in procurements: + procurement.values["propagate_create_uid"] = self.env.uid + return super()._run_buy(procurements) + + def _prepare_purchase_order(self, company_id, origins, values): + vals = super()._prepare_purchase_order(company_id, origins, values) + create_uids = [v.get("propagate_create_uid") for v in values] + create_uids = list(set(create_uids)) + if len(create_uids) == 1: + vals.update({"user_id": create_uids[0]}) + return vals diff --git a/purchase_representative/pyproject.toml b/purchase_representative/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/purchase_representative/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/purchase_representative/readme/CONTRIBUTORS.md b/purchase_representative/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..53edefdf30e --- /dev/null +++ b/purchase_representative/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- Lois Rilo \ +- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io) + - Bhavesh Heliconia diff --git a/purchase_representative/readme/DESCRIPTION.md b/purchase_representative/readme/DESCRIPTION.md new file mode 100644 index 00000000000..7b29f64844d --- /dev/null +++ b/purchase_representative/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This module makes the field *Purchase Representative* in Purchase Orders +default to the user doing a procurement to overcome the known flaw of +Odoo user in the transaction when using SUPERUSER_ID. diff --git a/purchase_representative/readme/USAGE.md b/purchase_representative/readme/USAGE.md new file mode 100644 index 00000000000..bfff31fe0cc --- /dev/null +++ b/purchase_representative/readme/USAGE.md @@ -0,0 +1,3 @@ +Just set the *Purchase Representative* in the Purchase Order header. +Then when sending the RFQ/PO to the vendor the Purchase Representative +will be the contact person (email from and reply to). diff --git a/purchase_representative/static/description/icon.png b/purchase_representative/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/purchase_representative/static/description/icon.png differ diff --git a/purchase_representative/static/description/index.html b/purchase_representative/static/description/index.html new file mode 100644 index 00000000000..e946689b72f --- /dev/null +++ b/purchase_representative/static/description/index.html @@ -0,0 +1,442 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Purchase Representative

+ +

Beta License: AGPL-3 OCA/purchase-workflow Translate me on Weblate Try me on Runboat

+

This module makes the field Purchase Representative in Purchase Orders +default to the user doing a procurement to overcome the known flaw of +Odoo user in the transaction when using SUPERUSER_ID.

+

Table of contents

+ +
+

Usage

+

Just set the Purchase Representative in the Purchase Order header. +Then when sending the RFQ/PO to the vendor the Purchase Representative +will be the contact person (email from and reply to).

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • ForgeFlow
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/purchase-workflow project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+
+ + diff --git a/purchase_representative/tests/__init__.py b/purchase_representative/tests/__init__.py new file mode 100644 index 00000000000..b8809dd06ff --- /dev/null +++ b/purchase_representative/tests/__init__.py @@ -0,0 +1 @@ +from . import test_purchase_representative diff --git a/purchase_representative/tests/test_purchase_representative.py b/purchase_representative/tests/test_purchase_representative.py new file mode 100644 index 00000000000..dad78468531 --- /dev/null +++ b/purchase_representative/tests/test_purchase_representative.py @@ -0,0 +1,73 @@ +from odoo import Command, fields +from odoo.tests import new_test_user + +from odoo.addons.base.tests.common import BaseCommon + + +class TestPurchaseRepresentative(BaseCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.user_test = new_test_user( + cls.env, + login="test_user", + groups="purchase.group_purchase_user", + name="Test User", + email="testuser@testuser.com", + ) + + cls.product = cls.env["product.product"].create( + { + "name": "Product Test", + "is_storable": True, + "route_ids": [ + Command.set([cls.env.ref("purchase_stock.route_warehouse0_buy").id]) + ], + "standard_price": 50.0, + } + ) + + cls.env["product.supplierinfo"].create( + { + "partner_id": cls.partner.id, + "product_tmpl_id": cls.product.product_tmpl_id.id, + "min_qty": 1.0, + "price": 45.0, + } + ) + + cls.location = cls.env.ref("stock.stock_location_stock") + cls.picking_type = cls.env.ref("stock.picking_type_in") + + def test_create_procurement(self): + """Test that the user_id field is filled automatically""" + procurement = self.env["stock.rule"].Procurement( + self.product, + 10, + self.product.uom_id, + self.location, + name="Procurement Test", + origin="Test Origin", + company_id=self.env.company, + values={ + "company_id": self.env.company, + "date_planned": fields.Datetime.now(), + "warehouse_id": self.env.ref("stock.warehouse0").id, + "procure_method": "make_to_order", + }, + ) + rule = self.env["stock.rule"].search([("action", "=", "buy")], limit=1) + if not rule: + rule = self.env["stock.rule"].search([], limit=1) + self.env["stock.rule"].with_user(self.user_test)._run_buy([(procurement, rule)]) + + purchase_orders = self.env["purchase.order"].search( + [("origin", "=", "Test Origin")] + ) + self.assertEqual(len(purchase_orders), 1) + po = purchase_orders[0] + self.assertEqual(po.partner_id, self.partner) + self.assertEqual(len(po.order_line), 1) + self.assertEqual(po.order_line[0].product_id, self.product) + + self.assertEqual(po.user_id.id, self.user_test.id)