[FIX] {purchase_,}mrp: prevent kit structure changes
When changing the structure of a kit, it lead to undesirable behaviors on Odoo Issue 01: 1. Create 3 products P_kit, P_compo01, P_compo02 - Type: Storable - Category: PC 2. Create a bill of materials: - Product: P_kit - Type: Kit - Components: - 1 x P_compo01 3. Create a purchase order PO with 2 x P_kit 4. Confirm PO and process the receipt 5. Edit the bill of materials of P_kit: - Add 1 x P_compo02 in components 6. Return 1 x P_compo01 7. Go back to the PO Error: The received quantity is 0 while it should be 1.0 When processing the return, the received quantity is recomputed, which lead to: https://github.com/odoo/odoo/blob/59fcb31f5a0b8136dae26b70ca0087f9b5cf3d24/addons/purchase_mrp/models/purchase_mrp.py#L29 However, since in the mean time the user added a new line in the BoM, `_compute_kit_quantities` doesn't find any associated SM (`bom_line_moves` is empty in [3]) and thus returns 0. Issue 02: (Need account_accountant. Use demo data) 1. Create a product category PC: - Costing Method: AVCO - Inventory Valuation: Automated - Set up the Price Difference Account 2. Create 3 products P_kit, P_compo01, P_compo02 - Type: Storable - Category: PC 3. Create a bill of materials: - Product: P_kit - Type: Kit - Components: - 1 x P_compo01 4. Create a purchase order PO with 1 x P_kit 5. Confirm PO and process the receipt 6. Edit the bill of materials of P_kit: - Add 1 x P_compo02 in components 7. Create and Post the bill Error: an Odoo Error is raised "ZeroDivisionError: float division by zero" While confirming the bill, some anglo saxo lines are generated. To do so, the valuation of the kit is computed: [1]. In the above case, it will lead to [2]. However, since in the mean time the user added a new line in the BoM, `_compute_kit_quantities` doesn't find any associated SM (`bom_line_moves` is empty in [3]) and thus returns 0. Back to [1], the quantity is used to divide the total price -> it will raise an error if this quantity is zero Suggestion: Such situations should not happen: once a product is used at least once, it should not become a kit nor have a new structure (if it was already a kit). Otherwise, `_compute_kit_quantities` will not correctly work since it is not possible to take the BoM changes into consideration. [1] https://github.com/odoo/odoo/blob/abfe37fcea5b20f77799d9331d4d011530880669/addons/purchase_stock/models/account_invoice.py#L72-L74 [2] https://github.com/odoo/odoo/blob/75191404788ab83645ee35b779991ea6fcdfa406/addons/purchase_mrp/models/stock_move.py#L19 [3] https://github.com/odoo/odoo/blob/7d1af314320547ab5e37c1d97cad22992c98565b/addons/mrp/models/stock_move.py#L275-L294 OPW-2780855 closes odoo/odoo#86821 X-original-commit: 33fa43f7 Signed-off-by:William Henrotin (whe) <whe@odoo.com> Signed-off-by:
Adrien Widart <awt@odoo.com>
Showing
- addons/mrp/i18n/mrp.pot 9 additions, 0 deletionsaddons/mrp/i18n/mrp.pot
- addons/mrp/models/mrp_bom.py 12 additions, 0 deletionsaddons/mrp/models/mrp_bom.py
- addons/purchase_mrp/i18n/purchase_mrp.pot 8 additions, 0 deletionsaddons/purchase_mrp/i18n/purchase_mrp.pot
- addons/purchase_mrp/models/stock_move.py 5 additions, 1 deletionaddons/purchase_mrp/models/stock_move.py
Please register or sign in to comment