diff --git a/purchase_sale_link_by_origin/README.rst b/purchase_sale_link_by_origin/README.rst new file mode 100644 index 00000000000..19d92e36226 --- /dev/null +++ b/purchase_sale_link_by_origin/README.rst @@ -0,0 +1,99 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +============================= +Purchase/Sale: link by origin +============================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:d829b29f7e746e8a56c8baf4f79aa75a3cb3705da5af8b09d3586306e4039efd + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_sale_link_by_origin + :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_sale_link_by_origin + :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| + +By default since `Odoo +14.0 `__, +PO and SO are linked by their order lines. + +This module also link them by the PO's Origin field, to cover more +cases. For example: + +- If a user cancels a PO, by default the link would have been broken; + now it won't; +- Or if a user manually defines or updates the Origin field of a PO, it + will be taken into account. + +**Table of contents** + +.. contents:: + :local: + +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 +------- + +* Camptocamp +* CHEF PIXEL + +Contributors +------------ + +- Phuc (Kieu Hoang) +- `CHEF PIXEL `__ + +Other credits +------------- + +The development of this module has been financially supported by: + +- Camptocamp + +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_sale_link_by_origin/__init__.py b/purchase_sale_link_by_origin/__init__.py new file mode 100644 index 00000000000..82b4dce2cdb --- /dev/null +++ b/purchase_sale_link_by_origin/__init__.py @@ -0,0 +1,5 @@ +# Copyright 2023 Camptocamp SA +# Copyright 2026 CHEF PIXEL +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from . import models diff --git a/purchase_sale_link_by_origin/__manifest__.py b/purchase_sale_link_by_origin/__manifest__.py new file mode 100644 index 00000000000..ba7aac2fef9 --- /dev/null +++ b/purchase_sale_link_by_origin/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2023 Camptocamp SA +# Copyright 2026 CHEF PIXEL +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) +{ + "name": "Purchase/Sale: link by origin", + "summary": "Link PO/SO by the PO's Origin in addition to the default " + "behavior that only links them by their lines", + "version": "19.0.1.0.0", + "author": "Camptocamp, CHEF PIXEL, Odoo Community Association (OCA)", + "maintainer": "CHEF PIXEL", + "license": "AGPL-3", + "category": "Purchase", + "website": "https://github.com/OCA/purchase-workflow", + "support": "hello@chef-pixel.fr", + "depends": [ + "sale_purchase_stock", + ], + "data": [], + "application": False, + "installable": True, +} diff --git a/purchase_sale_link_by_origin/i18n/it.po b/purchase_sale_link_by_origin/i18n/it.po new file mode 100644 index 00000000000..f5c8eedb165 --- /dev/null +++ b/purchase_sale_link_by_origin/i18n/it.po @@ -0,0 +1,27 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_sale_link_by_origin +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-03-19 15:41+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 4.17\n" + +#. module: purchase_sale_link_by_origin +#: model:ir.model,name:purchase_sale_link_by_origin.model_purchase_order +msgid "Purchase Order" +msgstr "Ordine di acquisto" + +#. module: purchase_sale_link_by_origin +#: model:ir.model,name:purchase_sale_link_by_origin.model_sale_order +msgid "Sales Order" +msgstr "Ordine di vendita" diff --git a/purchase_sale_link_by_origin/i18n/pt_BR.po b/purchase_sale_link_by_origin/i18n/pt_BR.po new file mode 100644 index 00000000000..07e38d9e42c --- /dev/null +++ b/purchase_sale_link_by_origin/i18n/pt_BR.po @@ -0,0 +1,25 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_sale_link_by_origin +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 19.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: pt_BR\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" + +#. module: purchase_sale_link_by_origin +#: model:ir.model,name:purchase_sale_link_by_origin.model_purchase_order +msgid "Purchase Order" +msgstr "" + +#. module: purchase_sale_link_by_origin +#: model:ir.model,name:purchase_sale_link_by_origin.model_sale_order +msgid "Sales Order" +msgstr "" diff --git a/purchase_sale_link_by_origin/i18n/purchase_sale_link_by_origin.pot b/purchase_sale_link_by_origin/i18n/purchase_sale_link_by_origin.pot new file mode 100644 index 00000000000..95af0fcd724 --- /dev/null +++ b/purchase_sale_link_by_origin/i18n/purchase_sale_link_by_origin.pot @@ -0,0 +1,24 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_sale_link_by_origin +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 19.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_sale_link_by_origin +#: model:ir.model,name:purchase_sale_link_by_origin.model_purchase_order +msgid "Purchase Order" +msgstr "" + +#. module: purchase_sale_link_by_origin +#: model:ir.model,name:purchase_sale_link_by_origin.model_sale_order +msgid "Sales Order" +msgstr "" diff --git a/purchase_sale_link_by_origin/i18n/sl.po b/purchase_sale_link_by_origin/i18n/sl.po new file mode 100644 index 00000000000..f0346b4b39e --- /dev/null +++ b/purchase_sale_link_by_origin/i18n/sl.po @@ -0,0 +1,28 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_sale_link_by_origin +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 19.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2026-01-10 08:13+0000\n" +"Last-Translator: Matjaz Mozetic \n" +"Language-Team: none\n" +"Language: sl\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=4; plural=n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || " +"n%100==4 ? 2 : 3;\n" +"X-Generator: Weblate 5.10.4\n" + +#. module: purchase_sale_link_by_origin +#: model:ir.model,name:purchase_sale_link_by_origin.model_purchase_order +msgid "Purchase Order" +msgstr "Nabavni nalog" + +#. module: purchase_sale_link_by_origin +#: model:ir.model,name:purchase_sale_link_by_origin.model_sale_order +msgid "Sales Order" +msgstr "Prodajni nalog" diff --git a/purchase_sale_link_by_origin/models/__init__.py b/purchase_sale_link_by_origin/models/__init__.py new file mode 100644 index 00000000000..8d096d5501b --- /dev/null +++ b/purchase_sale_link_by_origin/models/__init__.py @@ -0,0 +1,6 @@ +# Copyright 2023 Camptocamp SA +# Copyright 2026 CHEF PIXEL +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from . import purchase_order +from . import sale_order diff --git a/purchase_sale_link_by_origin/models/purchase_order.py b/purchase_sale_link_by_origin/models/purchase_order.py new file mode 100644 index 00000000000..1e02b4e4b4b --- /dev/null +++ b/purchase_sale_link_by_origin/models/purchase_order.py @@ -0,0 +1,25 @@ +# Copyright 2023 Camptocamp SA +# Copyright 2026 CHEF PIXEL +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from odoo import api, models + + +class PurchaseOrder(models.Model): + _inherit = "purchase.order" + + @api.depends("origin") + def _compute_sale_order_count(self): + return super()._compute_sale_order_count() + + def _get_sale_orders(self): + origins = set() + for order in self: + if order.origin: + for origin_part in order.origin.split(", "): + if " - " in origin_part: + origins.add(origin_part.split(" - ")[-1].strip()) + else: + origins.add(origin_part.strip()) + so_origins = self.env["sale.order"].search([["name", "in", list(origins)]]) + return super()._get_sale_orders() | so_origins diff --git a/purchase_sale_link_by_origin/models/sale_order.py b/purchase_sale_link_by_origin/models/sale_order.py new file mode 100644 index 00000000000..0d8ff49b233 --- /dev/null +++ b/purchase_sale_link_by_origin/models/sale_order.py @@ -0,0 +1,21 @@ +# Copyright 2023 Camptocamp SA +# Copyright 2026 CHEF PIXEL +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from odoo import api, models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + @api.depends("origin") + def _compute_purchase_order_count(self): + return super()._compute_purchase_order_count() + + def _get_purchase_orders(self): + po_related = self.env["purchase.order"] + for order in self: + po_related |= self.env["purchase.order"].search( + [("origin", "ilike", order.name)] + ) + return super()._get_purchase_orders() | po_related diff --git a/purchase_sale_link_by_origin/pyproject.toml b/purchase_sale_link_by_origin/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/purchase_sale_link_by_origin/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/purchase_sale_link_by_origin/readme/CONTRIBUTORS.md b/purchase_sale_link_by_origin/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..94403fc1e6b --- /dev/null +++ b/purchase_sale_link_by_origin/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- Phuc (Kieu Hoang) \<\> +- [CHEF PIXEL](https://chef-pixel.fr) \<\> diff --git a/purchase_sale_link_by_origin/readme/CREDITS.md b/purchase_sale_link_by_origin/readme/CREDITS.md new file mode 100644 index 00000000000..705d3b30cad --- /dev/null +++ b/purchase_sale_link_by_origin/readme/CREDITS.md @@ -0,0 +1,3 @@ +The development of this module has been financially supported by: + +- Camptocamp diff --git a/purchase_sale_link_by_origin/readme/DESCRIPTION.md b/purchase_sale_link_by_origin/readme/DESCRIPTION.md new file mode 100644 index 00000000000..995d6e735c1 --- /dev/null +++ b/purchase_sale_link_by_origin/readme/DESCRIPTION.md @@ -0,0 +1,5 @@ +By default since [Odoo 14.0](https://github.com/odoo/odoo/commit/5a1645a8f8f3560eb778da90b6160b322ce0722e), PO and SO are linked by their order lines. + +This module also link them by the PO's Origin field, to cover more cases. For example: +- If a user cancels a PO, by default the link would have been broken; now it won't; +- Or if a user manually defines or updates the Origin field of a PO, it will be taken into account. diff --git a/purchase_sale_link_by_origin/static/description/icon.png b/purchase_sale_link_by_origin/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/purchase_sale_link_by_origin/static/description/icon.png differ diff --git a/purchase_sale_link_by_origin/static/description/index.html b/purchase_sale_link_by_origin/static/description/index.html new file mode 100644 index 00000000000..465448046d9 --- /dev/null +++ b/purchase_sale_link_by_origin/static/description/index.html @@ -0,0 +1,449 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + + +
+ + diff --git a/purchase_sale_link_by_origin/tests/__init__.py b/purchase_sale_link_by_origin/tests/__init__.py new file mode 100644 index 00000000000..a743c77fe8a --- /dev/null +++ b/purchase_sale_link_by_origin/tests/__init__.py @@ -0,0 +1,5 @@ +# Copyright 2023 Camptocamp SA +# Copyright 2026 CHEF PIXEL +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from . import test_sale_purchase diff --git a/purchase_sale_link_by_origin/tests/test_sale_purchase.py b/purchase_sale_link_by_origin/tests/test_sale_purchase.py new file mode 100644 index 00000000000..8cb2bbe3484 --- /dev/null +++ b/purchase_sale_link_by_origin/tests/test_sale_purchase.py @@ -0,0 +1,77 @@ +# Copyright 2023 Camptocamp SA +# Copyright 2026 CHEF PIXEL +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from odoo import Command + +from odoo.addons.base.tests.common import BaseCommon + + +class TestSalePurchaseOrder(BaseCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + cls.partner = cls.env["res.partner"].create({"name": "Test Partner"}) + cls.mto_route = cls.env["stock.route"].search( + [ + ("name", "=", "Replenish on Order (MTO)"), + "|", + ("active", "=", False), + ("active", "=", True), + ] + ) + cls.mto_route.active = True + cls.buy_route = cls.env["stock.route"].search([("name", "=", "Buy")]) + + cls.sale_order = cls.env["sale.order"].create( + { + "partner_id": cls.partner.id, + "order_line": [ + Command.create( + { + "product_id": cls.env["product.product"] + .create( + { + "name": "Product A", + "list_price": 100, + "seller_ids": [ + ( + 0, + 0, + {"partner_id": cls.partner.id, "delay": 5}, + ) + ], + "route_ids": [ + (4, cls.mto_route.id), + (4, cls.buy_route.id), + ], + } + ) + .id, + "name": "Product A", + } + ) + ], + } + ) + + def test_sale_purchase(self): + self.sale_order.action_confirm() + + purchase_order = self.env["purchase.order"].search( + [("id", "in", self.sale_order._get_purchase_orders().ids)] + ) + + purchase_order_count_after_confirm = len(self.sale_order._get_purchase_orders()) + sale_order_count_after_confirm = len(purchase_order._get_sale_orders()) + + purchase_order.button_cancel() + + purchase_order_count_after_cancel = len(self.sale_order._get_purchase_orders()) + sale_order_count_after_cancel = len(purchase_order._get_sale_orders()) + + self.assertEqual( + purchase_order_count_after_confirm, purchase_order_count_after_cancel + ) + self.assertEqual(sale_order_count_after_confirm, sale_order_count_after_cancel)