From 8df3b459da7c5f8d51c21831a186a4f43b927489 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Sat, 27 Nov 2021 13:30:27 +0100 Subject: [PATCH] [FIX] procurement_purchase_no_grouping: Take into account SO updates Steps to reproduce: - Create a product with MTO route and "No line grouping" product category. - Create an SO with such product and quantity = 1. - Confirm it. - A purchase order is created with such product and qty = 1. - Edit the sales order, and change quantity = 2. Current behavior: A new purchase line is created with quantity = 2, having ordered 3 units instead of 2. Expected behavior: The same existing purchase line is updated with quantity = 2. ------ For solving this problem, we are going to group by procurement group instead of simply discarding any possible line grouping. NOTE: This makes that if you manually assign the same procurement group to several different sales orders, the grouping will be done no matter the grouping criteria, but this is the only way to do it without having to put a lot of glue modules, and on standard operation mode, procurement groups are not reused between sales orders. TT33031 --- procurement_purchase_no_grouping/README.rst | 8 +++++ .../__manifest__.py | 2 +- .../models/purchase_order.py | 16 ++++++++-- .../readme/ROADMAP.rst | 4 +++ .../static/description/index.html | 30 ++++++++++++------- 5 files changed, 46 insertions(+), 14 deletions(-) create mode 100644 procurement_purchase_no_grouping/readme/ROADMAP.rst diff --git a/procurement_purchase_no_grouping/README.rst b/procurement_purchase_no_grouping/README.rst index 5c8c6b444b3..10b7f7ce51d 100644 --- a/procurement_purchase_no_grouping/README.rst +++ b/procurement_purchase_no_grouping/README.rst @@ -52,6 +52,14 @@ Go to each product category, and select one of these values in the field System default behaviour can be set up in System settings / Purchase / Procurement Purchase Grouping +Known issues / Roadmap +====================== + +- If you reuse the same procurement group between several sales orders, and + using "No line grouping", they will be grouped anyways, as the criteria for + grouping or not should be kept to the same procurement group, as it's the only + way to get proper quantities updates after confirming the sales order. + Bug Tracker =========== diff --git a/procurement_purchase_no_grouping/__manifest__.py b/procurement_purchase_no_grouping/__manifest__.py index db069e664b1..b82e1c084a2 100644 --- a/procurement_purchase_no_grouping/__manifest__.py +++ b/procurement_purchase_no_grouping/__manifest__.py @@ -5,7 +5,7 @@ { "name": "Procurement Purchase No Grouping", - "version": "14.0.1.0.0", + "version": "14.0.1.0.1", "author": "AvanzOSC, Tecnativa, Odoo Community Association (OCA)", "website": "https://github.com/OCA/purchase-workflow", "category": "Procurements", diff --git a/procurement_purchase_no_grouping/models/purchase_order.py b/procurement_purchase_no_grouping/models/purchase_order.py index 427d6afba1c..4057a6f1f20 100644 --- a/procurement_purchase_no_grouping/models/purchase_order.py +++ b/procurement_purchase_no_grouping/models/purchase_order.py @@ -1,6 +1,6 @@ # Copyright 2015 AvanzOsc (http://www.avanzosc.es) -# Copyright 2015-2016 Tecnativa - Pedro M. Baeza # Copyright 2018 Tecnativa - Carlos Dauden +# Copyright 2015-2021 Tecnativa - Pedro M. Baeza # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) from odoo import models @@ -20,9 +20,19 @@ def _find_candidate( company_id, values, ): + """If not grouping by line, we should make an exception when you update an + existing sales order line, so we filter a bit more by procurement group. + + NOTE: This makes that if you manually assign the same procurement group to + several different sales orders, the grouping will be done no matter the grouping + criteria, but this is the only way to do it without having to put a lot of glue + modules, and on standard operation mode, procurement groups are not reused + between sales orders. + """ + obj = self if values.get("grouping") == "line": - return False - return super()._find_candidate( + obj = self.filtered(lambda x: x.order_id.group_id == values.get("group_id")) + return super(PurchaseOrderLine, obj)._find_candidate( product_id, product_qty, product_uom, diff --git a/procurement_purchase_no_grouping/readme/ROADMAP.rst b/procurement_purchase_no_grouping/readme/ROADMAP.rst new file mode 100644 index 00000000000..2cffa937137 --- /dev/null +++ b/procurement_purchase_no_grouping/readme/ROADMAP.rst @@ -0,0 +1,4 @@ +- If you reuse the same procurement group between several sales orders, and + using "No line grouping", they will be grouped anyways, as the criteria for + grouping or not should be kept to the same procurement group, as it's the only + way to get proper quantities updates after confirming the sales order. diff --git a/procurement_purchase_no_grouping/static/description/index.html b/procurement_purchase_no_grouping/static/description/index.html index 55b322fcfa5..7a5a25edebb 100644 --- a/procurement_purchase_no_grouping/static/description/index.html +++ b/procurement_purchase_no_grouping/static/description/index.html @@ -375,11 +375,12 @@

Procurement Purchase No Grouping

+
+

Known issues / Roadmap

+ +
-

Bug Tracker

+

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 smashing it by providing a detailed and welcomed @@ -410,16 +420,16 @@

Bug Tracker

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

-

Credits

+

Credits

-

Authors

+

Authors

  • AvanzOSC
  • Tecnativa
-

Contributors

+

Contributors

-

Maintainers

+

Maintainers

This module is maintained by the OCA.

Odoo Community Association

OCA, or the Odoo Community Association, is a nonprofit organization whose