Skip to content

Commit

Permalink
[FIX] procurement_purchase_no_grouping: Take into account SO updates
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pedrobaeza committed Jun 17, 2022
1 parent c822713 commit 8df3b45
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 14 deletions.
8 changes: 8 additions & 0 deletions procurement_purchase_no_grouping/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
===========

Expand Down
2 changes: 1 addition & 1 deletion procurement_purchase_no_grouping/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 13 additions & 3 deletions procurement_purchase_no_grouping/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions procurement_purchase_no_grouping/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -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.
30 changes: 20 additions & 10 deletions procurement_purchase_no_grouping/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,12 @@ <h1 class="title">Procurement Purchase No Grouping</h1>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#configuration" id="id1">Configuration</a></li>
<li><a class="reference internal" href="#bug-tracker" id="id2">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id3">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id4">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id5">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id6">Maintainers</a></li>
<li><a class="reference internal" href="#known-issues-roadmap" id="id2">Known issues / Roadmap</a></li>
<li><a class="reference internal" href="#bug-tracker" id="id3">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id4">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id5">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id6">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id7">Maintainers</a></li>
</ul>
</li>
</ul>
Expand All @@ -401,25 +402,34 @@ <h1><a class="toc-backref" href="#id1">Configuration</a></h1>
<p>System default behaviour can be set up in System settings / Purchase / Procurement
Purchase Grouping</p>
</div>
<div class="section" id="known-issues-roadmap">
<h1><a class="toc-backref" href="#id2">Known issues / Roadmap</a></h1>
<ul class="simple">
<li>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.</li>
</ul>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
<h1><a class="toc-backref" href="#id3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/purchase-workflow/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/purchase-workflow/issues/new?body=module:%20procurement_purchase_no_grouping%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#id3">Credits</a></h1>
<h1><a class="toc-backref" href="#id4">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#id4">Authors</a></h2>
<h2><a class="toc-backref" href="#id5">Authors</a></h2>
<ul class="simple">
<li>AvanzOSC</li>
<li>Tecnativa</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#id5">Contributors</a></h2>
<h2><a class="toc-backref" href="#id6">Contributors</a></h2>
<ul class="simple">
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
<li>Pedro M. Baeza</li>
Expand All @@ -435,7 +445,7 @@ <h2><a class="toc-backref" href="#id5">Contributors</a></h2>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id6">Maintainers</a></h2>
<h2><a class="toc-backref" href="#id7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
Expand Down

0 comments on commit 8df3b45

Please sign in to comment.