diff --git a/purchase_line_procurement_group/README.rst b/purchase_line_procurement_group/README.rst new file mode 100644 index 00000000000..d534603f372 --- /dev/null +++ b/purchase_line_procurement_group/README.rst @@ -0,0 +1,104 @@ +=============================== +Purchase Line Procurement Group +=============================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:b684c8e5da20b7ea4fc93d22766564269ca83f6e875df7e8e431b81cd82b7edc + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/licence-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/18.0/purchase_line_procurement_group + :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-18-0/purchase-workflow-18-0-purchase_line_procurement_group + :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=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module changes the way procurements generate purchase order lines. +If some procurements are run for the same products and locations, but +have different procurement groups, these won't be merged in the same +purchase order line and will instead generate a purchase order line per +procurement group. + +Moreover this module ensures that generated stock move won't be merged +together if they come from purchase order lines with different +procurement groups. + +**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 + +Contributors +------------ + +- Akim Juillerat + +- Kitti Upariphutthiphong + +- `Trobz `__: + + - Phuc Tran + - Jack Le + +- `Binhex `__: + + - Deriman Alonso + +- `DEC `__: + + - Yann Papouin + +Other credits +------------- + + + +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_line_procurement_group/__init__.py b/purchase_line_procurement_group/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/purchase_line_procurement_group/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/purchase_line_procurement_group/__manifest__.py b/purchase_line_procurement_group/__manifest__.py new file mode 100644 index 00000000000..01144e9d542 --- /dev/null +++ b/purchase_line_procurement_group/__manifest__.py @@ -0,0 +1,13 @@ +# Copyright 2018 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "Purchase Line Procurement Group", + "summary": "Group purchase order line according to procurement group", + "version": "18.0.1.0.0", + "category": "Purchase", + "website": "https://github.com/OCA/purchase-workflow", + "author": "Camptocamp, Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": ["purchase_stock"], + "data": ["views/purchase.xml"], +} diff --git a/purchase_line_procurement_group/i18n/es.po b/purchase_line_procurement_group/i18n/es.po new file mode 100644 index 00000000000..750ea2f2da2 --- /dev/null +++ b/purchase_line_procurement_group/i18n/es.po @@ -0,0 +1,32 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_line_procurement_group +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-02-11 19:34+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\n" +"Language: es\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_line_procurement_group +#: model:ir.model.fields,field_description:purchase_line_procurement_group.field_purchase_order_line__procurement_group_id +msgid "Procurement Group" +msgstr "Grupo de Adquisiciones" + +#. module: purchase_line_procurement_group +#: model:ir.model,name:purchase_line_procurement_group.model_purchase_order_line +msgid "Purchase Order Line" +msgstr "Línea de Orden de Compra" + +#. module: purchase_line_procurement_group +#: model:ir.model,name:purchase_line_procurement_group.model_stock_move +msgid "Stock Move" +msgstr "Movimiento de Existencias" diff --git a/purchase_line_procurement_group/i18n/fr.po b/purchase_line_procurement_group/i18n/fr.po new file mode 100644 index 00000000000..db2097355e9 --- /dev/null +++ b/purchase_line_procurement_group/i18n/fr.po @@ -0,0 +1,35 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_line_procurement_group +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2020-10-04 16:24+0000\n" +"Last-Translator: Yann Papouin \n" +"Language-Team: none\n" +"Language: fr\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 3.10\n" + +#. module: purchase_line_procurement_group +#: model:ir.model.fields,field_description:purchase_line_procurement_group.field_purchase_order_line__procurement_group_id +msgid "Procurement Group" +msgstr "Groupe d'approvisionnement" + +#. module: purchase_line_procurement_group +#: model:ir.model,name:purchase_line_procurement_group.model_purchase_order_line +msgid "Purchase Order Line" +msgstr "Ligne de commande d'achat" + +#. module: purchase_line_procurement_group +#: model:ir.model,name:purchase_line_procurement_group.model_stock_move +msgid "Stock Move" +msgstr "Mouvement de stock" + +#~ msgid "Stock Rule" +#~ msgstr "Règle de stock" diff --git a/purchase_line_procurement_group/i18n/it.po b/purchase_line_procurement_group/i18n/it.po new file mode 100644 index 00000000000..534f97f4be1 --- /dev/null +++ b/purchase_line_procurement_group/i18n/it.po @@ -0,0 +1,32 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_line_procurement_group +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-12-22 14:36+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_line_procurement_group +#: model:ir.model.fields,field_description:purchase_line_procurement_group.field_purchase_order_line__procurement_group_id +msgid "Procurement Group" +msgstr "Gruppo di approvvigionamento" + +#. module: purchase_line_procurement_group +#: model:ir.model,name:purchase_line_procurement_group.model_purchase_order_line +msgid "Purchase Order Line" +msgstr "Riga ordine di acquisto" + +#. module: purchase_line_procurement_group +#: model:ir.model,name:purchase_line_procurement_group.model_stock_move +msgid "Stock Move" +msgstr "Movimento di magazzino" diff --git a/purchase_line_procurement_group/i18n/ja.po b/purchase_line_procurement_group/i18n/ja.po new file mode 100644 index 00000000000..b639ad66c66 --- /dev/null +++ b/purchase_line_procurement_group/i18n/ja.po @@ -0,0 +1,32 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_line_procurement_group +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-12-05 11:34+0000\n" +"Last-Translator: \"Ivy Liu (QRTL)\" \n" +"Language-Team: none\n" +"Language: ja\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=1; plural=0;\n" +"X-Generator: Weblate 4.17\n" + +#. module: purchase_line_procurement_group +#: model:ir.model.fields,field_description:purchase_line_procurement_group.field_purchase_order_line__procurement_group_id +msgid "Procurement Group" +msgstr "調達グループ" + +#. module: purchase_line_procurement_group +#: model:ir.model,name:purchase_line_procurement_group.model_purchase_order_line +msgid "Purchase Order Line" +msgstr "購買明細行" + +#. module: purchase_line_procurement_group +#: model:ir.model,name:purchase_line_procurement_group.model_stock_move +msgid "Stock Move" +msgstr "在庫移動" diff --git a/purchase_line_procurement_group/i18n/purchase_line_procurement_group.pot b/purchase_line_procurement_group/i18n/purchase_line_procurement_group.pot new file mode 100644 index 00000000000..ec306616822 --- /dev/null +++ b/purchase_line_procurement_group/i18n/purchase_line_procurement_group.pot @@ -0,0 +1,29 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_line_procurement_group +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.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_line_procurement_group +#: model:ir.model.fields,field_description:purchase_line_procurement_group.field_purchase_order_line__procurement_group_id +msgid "Procurement Group" +msgstr "" + +#. module: purchase_line_procurement_group +#: model:ir.model,name:purchase_line_procurement_group.model_purchase_order_line +msgid "Purchase Order Line" +msgstr "" + +#. module: purchase_line_procurement_group +#: model:ir.model,name:purchase_line_procurement_group.model_stock_move +msgid "Stock Move" +msgstr "" diff --git a/purchase_line_procurement_group/i18n/zh_CN.po b/purchase_line_procurement_group/i18n/zh_CN.po new file mode 100644 index 00000000000..b8173a50849 --- /dev/null +++ b/purchase_line_procurement_group/i18n/zh_CN.po @@ -0,0 +1,35 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_line_procurement_group +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2019-09-02 14:40+0000\n" +"Last-Translator: 黎伟杰 <674416404@qq.com>\n" +"Language-Team: none\n" +"Language: zh_CN\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=1; plural=0;\n" +"X-Generator: Weblate 3.8\n" + +#. module: purchase_line_procurement_group +#: model:ir.model.fields,field_description:purchase_line_procurement_group.field_purchase_order_line__procurement_group_id +msgid "Procurement Group" +msgstr "补货组" + +#. module: purchase_line_procurement_group +#: model:ir.model,name:purchase_line_procurement_group.model_purchase_order_line +msgid "Purchase Order Line" +msgstr "采购订单行" + +#. module: purchase_line_procurement_group +#: model:ir.model,name:purchase_line_procurement_group.model_stock_move +msgid "Stock Move" +msgstr "库存移动" + +#~ msgid "Stock Rule" +#~ msgstr "库存规则" diff --git a/purchase_line_procurement_group/models/__init__.py b/purchase_line_procurement_group/models/__init__.py new file mode 100644 index 00000000000..fa0fd52e455 --- /dev/null +++ b/purchase_line_procurement_group/models/__init__.py @@ -0,0 +1,2 @@ +from . import purchase_order_line +from . import stock_move diff --git a/purchase_line_procurement_group/models/purchase_order_line.py b/purchase_line_procurement_group/models/purchase_order_line.py new file mode 100644 index 00000000000..c31b35f180e --- /dev/null +++ b/purchase_line_procurement_group/models/purchase_order_line.py @@ -0,0 +1,76 @@ +# Copyright 2018 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import fields, models + + +class PurchaseOrderLine(models.Model): + _inherit = "purchase.order.line" + + procurement_group_id = fields.Many2one("procurement.group") + + def _find_candidate( + self, + product_id, + product_qty, + product_uom, + location_id, + name, + origin, + company_id, + values, + ): + """Do not merge PO lines if procurement group is different or not set.""" + _self = self + if "group_id" in values: + pg_id = values["group_id"] + if isinstance(pg_id, models.Model): + pg_id = pg_id.id + _self = self.filtered(lambda pol: pol.procurement_group_id.id == pg_id) + return super(PurchaseOrderLine, _self)._find_candidate( + product_id=product_id, + product_qty=product_qty, + product_uom=product_uom, + location_id=location_id, + name=name, + origin=origin, + company_id=company_id, + values=values, + ) + + def _prepare_stock_moves(self, picking): + res = super()._prepare_stock_moves(picking) + if self.procurement_group_id: + for vals in res: + if vals and "group_id" in vals: + # override the procurement group with the one from the PO line + vals["group_id"] = self.procurement_group_id.id + return res + + def _prepare_purchase_order_line_from_procurement( + self, + product_id, + product_qty, + product_uom, + location_dest_id, + name, + origin, + company_id, + values, + po, + ): + """Add procurement group to values""" + res = super()._prepare_purchase_order_line_from_procurement( + product_id, + product_qty, + product_uom, + location_dest_id, + name, + origin, + company_id, + values, + po, + ) + procurement_group = values.get("group_id") + if procurement_group: + res["procurement_group_id"] = procurement_group.id + return res diff --git a/purchase_line_procurement_group/models/stock_move.py b/purchase_line_procurement_group/models/stock_move.py new file mode 100644 index 00000000000..b5d1c12479a --- /dev/null +++ b/purchase_line_procurement_group/models/stock_move.py @@ -0,0 +1,13 @@ +# Copyright 2018 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import api, models + + +class StockMove(models.Model): + _inherit = "stock.move" + + @api.model + def _prepare_merge_moves_distinct_fields(self): + res = super()._prepare_merge_moves_distinct_fields() + res.append("group_id") + return res diff --git a/purchase_line_procurement_group/pyproject.toml b/purchase_line_procurement_group/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/purchase_line_procurement_group/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/purchase_line_procurement_group/readme/CONTRIBUTORS.md b/purchase_line_procurement_group/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..8947e25dd8e --- /dev/null +++ b/purchase_line_procurement_group/readme/CONTRIBUTORS.md @@ -0,0 +1,14 @@ +- Akim Juillerat \<\> + +- Kitti Upariphutthiphong \<\> + +- [Trobz](https://trobz.com): + + - Phuc Tran \<\> + - Jack Le \<\> + +- [Binhex](https://binhex.cloud/): + - Deriman Alonso + +- [DEC](https://decgroupe.com/): + - Yann Papouin \<\> diff --git a/purchase_line_procurement_group/readme/CREDITS.md b/purchase_line_procurement_group/readme/CREDITS.md new file mode 100644 index 00000000000..e69de29bb2d diff --git a/purchase_line_procurement_group/readme/DESCRIPTION.md b/purchase_line_procurement_group/readme/DESCRIPTION.md new file mode 100644 index 00000000000..0bc43ad39d7 --- /dev/null +++ b/purchase_line_procurement_group/readme/DESCRIPTION.md @@ -0,0 +1,9 @@ +This module changes the way procurements generate purchase order lines. +If some procurements are run for the same products and locations, but +have different procurement groups, these won't be merged in the same +purchase order line and will instead generate a purchase order line per +procurement group. + +Moreover this module ensures that generated stock move won't be merged +together if they come from purchase order lines with different +procurement groups. diff --git a/purchase_line_procurement_group/static/description/icon.png b/purchase_line_procurement_group/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/purchase_line_procurement_group/static/description/icon.png differ diff --git a/purchase_line_procurement_group/static/description/index.html b/purchase_line_procurement_group/static/description/index.html new file mode 100644 index 00000000000..077e26ecab4 --- /dev/null +++ b/purchase_line_procurement_group/static/description/index.html @@ -0,0 +1,448 @@ + + + + + +Purchase Line Procurement Group + + + +
+

Purchase Line Procurement Group

+ + +

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

+

This module changes the way procurements generate purchase order lines. +If some procurements are run for the same products and locations, but +have different procurement groups, these won’t be merged in the same +purchase order line and will instead generate a purchase order line per +procurement group.

+

Moreover this module ensures that generated stock move won’t be merged +together if they come from purchase order lines with different +procurement groups.

+

Table of contents

+ +
+

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
  • +
+
+
+

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_line_procurement_group/tests/__init__.py b/purchase_line_procurement_group/tests/__init__.py new file mode 100644 index 00000000000..268993b79ea --- /dev/null +++ b/purchase_line_procurement_group/tests/__init__.py @@ -0,0 +1 @@ +from . import test_po_line_proc_group diff --git a/purchase_line_procurement_group/tests/test_po_line_proc_group.py b/purchase_line_procurement_group/tests/test_po_line_proc_group.py new file mode 100644 index 00000000000..54dd42fca41 --- /dev/null +++ b/purchase_line_procurement_group/tests/test_po_line_proc_group.py @@ -0,0 +1,211 @@ +# Copyright 2018 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo.tests import TransactionCase + + +class TestPOLineProcurementGroup(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + + def _create_orderpoint(product, qty_min, qty_max, location): + orderpoint_model = cls.env["stock.warehouse.orderpoint"] + return orderpoint_model.create( + { + "name": f"OP/{product.name}", + "product_id": product.id, + "product_min_qty": qty_min, + "product_max_qty": qty_max, + "location_id": location.id, + } + ) + + cls.stock_location = cls.env.ref("stock.stock_location_stock") + + # Create supplier + cls.pyromaniacs = cls.env["res.partner"].create( + {"name": "Pyromaniacs Inc", "company_type": "company"} + ) + cls.lighter = ( + cls.env["product.template"] + .create( + { + "name": "Lighter", + "type": "consu", + "is_storable": True, + "purchase_ok": True, + "seller_ids": [ + ( + 0, + 0, + { + "partner_id": cls.pyromaniacs.id, + "min_qty": 1, + "price": 1.0, + }, + ) + ], + } + ) + .product_variant_ids + ) + + cls.warehouse = cls.env.ref("stock.warehouse0") + cls.warehouse.write({"reception_steps": "three_steps"}) + wh2 = cls.env["stock.warehouse"].create( + {"name": "WH2", "code": "WH2", "partner_id": False} + ) + # Create WH > WH2 PG and route + cls.wh_wh2_pg = cls.env["procurement.group"].create( + {"name": "WH > WH2", "move_type": "direct"} + ) + wh_wh2_route = cls.env["stock.route"].create( + { + "name": "WH > WH2", + "product_selectable": True, + "rule_ids": [ + ( + 0, + 0, + { + "name": "WH>WH2", + "action": "pull", + "location_dest_id": wh2.lot_stock_id.id, + "location_src_id": cls.warehouse.lot_stock_id.id, + "procure_method": "make_to_order", + "picking_type_id": cls.env.ref( + "stock.picking_type_internal" + ).id, + "group_propagation_option": "fixed", + "group_id": cls.wh_wh2_pg.id, + "propagate_cancel": True, + }, + ) + ], + } + ) + cls.lighter.write({"route_ids": [(4, wh_wh2_route.id)]}) + _create_orderpoint(cls.lighter, 15, 30, cls.warehouse.lot_stock_id) + _create_orderpoint(cls.lighter, 10, 20, wh2.lot_stock_id) + + # Force parent store computation after creation of WH2 because location + # quantities are computed using parent_left _right in domain + cls.env["stock.location"]._parent_store_compute() + + def test_po_line_find_candidate_with_group(self): + """Ensure that our `_find_candidate` override gives a right match when + comparing the procurement group""" + + def create_po_line_in_new_po(product, qty, group=False): + """Shortcut to create a draft purchase of a `product`. A new + purchase order is created with a single line.""" + po = self.env["purchase.order"].create( + { + "partner_id": self.pyromaniacs.id, + "group_id": group and group.id or False, + } + ) + po_line = self.env["purchase.order.line"].create( + { + "order_id": po.id, + "product_id": product.id, + "product_qty": qty, + "product_uom": product.uom_id.id, + "price_unit": 1.0, + "procurement_group_id": group and group.id or False, + } + ) + return po_line + + def find_candidate(po_lines, values): + """Shortcut to call `_find_candidate` with pre-filled values""" + return po_lines._find_candidate( + product_id=self.lighter, + product_qty=1.0, + product_uom=self.lighter.uom_id.id, + location_id=self.stock_location, + name="", + origin="", + company_id=self.env.company.id, + values=values, + ) + + # Procurement group that will be used as a filter + my_group = self.env["procurement.group"].create( + {"name": "Group", "move_type": "direct"} + ) + + # Create a first purchase for our lighter without procurement group + po1_line = create_po_line_in_new_po(self.lighter, 1.0, False) + + # Create a second purchase for our lighter with a dedicated + # procurement group + po2_line = create_po_line_in_new_po(self.lighter, 1.0, my_group) + + # Create a pool of purchase order lines + po_lines = po1_line + po2_line + + # Check match when no procurement group is given + match_lines_1 = find_candidate( + po_lines, + values={ + "orderpoint_id": False, + "propagate_cancel": True, + }, + ) + self.assertEqual(len(match_lines_1), 1) + self.assertEqual(match_lines_1.id, po1_line.id) + + # Check match when an empty procurement group is given + match_lines_2 = find_candidate( + po_lines, + values={ + "orderpoint_id": False, + "propagate_cancel": True, + "group_id": False, + }, + ) + self.assertEqual(len(match_lines_2), 1) + self.assertEqual(match_lines_2.id, po1_line.id) + + # Check match when a specific procurement group is given + match_lines_3 = find_candidate( + po_lines, + values={ + "orderpoint_id": False, + "propagate_cancel": True, + "group_id": my_group, + }, + ) + self.assertEqual(len(match_lines_3), 1) + self.assertEqual(match_lines_3.id, po2_line.id) + + def test_po_line_proc_group(self): + # Ensure PO lines generated by the scheduler have proper PG + self.env["procurement.group"].run_scheduler() + po = self.env["purchase.order"].search( + [("partner_id", "=", self.pyromaniacs.id)] + ) + self.assertEqual(len(po.order_line), 2) + for line in po.order_line: + self.assertEqual(line.product_id, self.lighter) + if line.procurement_group_id == self.wh_wh2_pg: + self.assertAlmostEqual(line.product_qty, 20) + else: + self.assertAlmostEqual(line.product_qty, 30) + # Ensure stock moves generated by PO confirmation have proper PG + po.button_confirm() + input_moves = self.env["stock.move"].search( + [ + ("product_id", "=", self.lighter.id), + ("location_dest_id", "=", self.warehouse.wh_input_stock_loc_id.id), + ] + ) + self.assertEqual(len(input_moves), 2) + for move in input_moves: + self.assertEqual(move.product_id, self.lighter) + if move.group_id == self.wh_wh2_pg: + self.assertAlmostEqual(move.product_uom_qty, 20.0) + else: + self.assertAlmostEqual(move.product_uom_qty, 30.0) diff --git a/purchase_line_procurement_group/views/purchase.xml b/purchase_line_procurement_group/views/purchase.xml new file mode 100644 index 00000000000..8986fa25a8f --- /dev/null +++ b/purchase_line_procurement_group/views/purchase.xml @@ -0,0 +1,26 @@ + + + + purchase.order.form.inherit + purchase.order + + + + + + + + + + +