lase@odoo.com 7fa4f71b63 [FIX] mrp: Generate MOs for BOM with product repetition
Steps to reproduce:

- Create 4 products: Final product (FP), Product 1,2,3 (P1,P2 and P3)
- Set routes to manifacture on each product
- For P1, P2, P3 add a 0:0 reordering rule.
- Add a BOM for P2 with 1 unit of P1 as components
- Add a BOM for P3 with 1 unit of P2 as components
- Add a BOM for FP with 1 unit of P3 and of P2 as components

The MO overview of a FP shoud look like this :

                     FP
                     /\
                    /  \
                   P3   P2
                   |    |
                   P2   P1
                   |
                   P1

- Create and confirm a manufacturing order for a FP

Current behavior:

As the quantity on hand is not sufficient to manufacture a FP,
manufacturing orders are automatically created for P3, P2 and P1.
However, the quantity on each of these MOs is of 1 unit.

Expected behavior:

Since 2 units of P2 and of P1 will be required to manufacture the FP the
quantity of their respective MOs should be at 2.

Cause of the issue:

Confirming the MO for FP will  call the trigger_scheduler() on its raw
stock move:
https://github.com/odoo/odoo/blob/79813f08e5a2f0188ac7d184d000486f25319503/addons/mrp/models/mrp_production.py#L1291
https://github.com/odoo/odoo/blob/f3ef40da0406bb0fd683dce3a08739e247fd6dfc/addons/stock/models/stock_orderpoint.py#L495
In this method, we compute the qty to order for the orderpoints of P2
and P3. Since these ones are positive, procurement will be run for both
of these leading to the creation of 2 new MO's via the manufacture
route. The post process of the scheduler is then run
https://github.com/odoo/odoo/blob/f3ef40da0406bb0fd683dce3a08739e247fd6dfc/addons/stock/models/stock_orderpoint.py#L550
An override of this method in mrp will then find the created MO and
confirm these,  triggering the above process once more but now for the
MO's of P3 and P2 rather than FP: we start by computing the qty to order
for the orderpoints of P2 and P1 to manufacture P3 and P2. However, to
compute this quantity, we look at the forecast of these quantities and
this is where the problem comes in:
https://github.com/odoo/odoo/blob/f3ef40da0406bb0fd683dce3a08739e247fd6dfc/addons/stock/models/stock_orderpoint.py#L284
With the orderpoint of P2:
- `virtual_available` is at a value of -1 since there is currently 2
   stock moves taking this product (one to manufacture FP and one to
   manufacture P3) and one stock move bringing one unit of this product
   (the one coming from the MO of P2 we are currently trying to confirm)
- `orderpoint._quantity_in_progress()` has a value of 1 due to the MO
   of P2 that we are currently confirming.
Adding these quantities to one an other, the forecasted qty of P2 is at
0. This is a mistake since the incoming stock move for P2 is counted
twice in the forecast qty: once in each term. As a result no new
procurement will be generated for P2 hence the issue.

FIX:

Since this `_quantity_in_progress()` seems to have been introduced to
improve purchase flows rather than to interact with manufacturing flows:
https://github.com/odoo/odoo/commit/943da6df0f1d39e8e10869b25c5ba8cc13a2aa54
We decided to ignore its contribution during our manufacturing flow for
the forecast qty to be correctly computed. This requires to ignore the
contribution of each mo triggering the scheduler and those that already
triggered the scheduler since the confirmation of the MO of FP.

Notes: The test sets a little more complex MO overview than the
above use case to be sure to catch corner cases situations.

opw-3689920

closes odoo/odoo#158217

X-original-commit: 4c0b9ef2ad75d3f831fce0abaa62a1d660ba5ca6
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
2024-03-21 18:35:48 +00:00
…
…
…

Build Status Tech Doc Help Nightly Builds

Odoo

Odoo is a suite of web based open source business apps.

The main Odoo Apps include an Open Source CRM, Website Builder, eCommerce, Warehouse Management, Project Management, Billing & Accounting, Point of Sale, Human Resources, Marketing, Manufacturing, ...

Odoo Apps can be used as stand-alone applications, but they also integrate seamlessly so you get a full-featured Open Source ERP when you install several Apps.

Getting started with Odoo

For a standard installation please follow the Setup instructions from the documentation.

To learn the software, we recommend the Odoo eLearning, or Scale-up, the business game. Developers can start with the developer tutorials

S
Description
No description provided
Readme LGPL-3.0
3.4 GiB
Languages
Python 49.6%
JavaScript 47.8%
SCSS 2%
CSS 0.3%
HTML 0.2%