Skip to content
Snippets Groups Projects
Commit a816c632 authored by Adrien Widart (awt)'s avatar Adrien Widart (awt)
Browse files

[FIX] mrp_account: avoid deleting a BoM in use

Deleting a kit BoM will lead to an error if the kit is in the middle
of a sale process

To reproduce the issue:
1. In Settings, enable UoM
2. Create a product category PC:
   - AVCO
   - Auto
3. Create three storable products P_kit, P_01, P_02
   - UoM of P_01: `m`
   - UoM of P_02: `kg`
4. Create a BoM:
   - Product: P_kit
   - Type: kit
   - Components:
     - 1 x P_01
     - 1 x P_02
5. Create and confirm a SO with 1 x P_kit
6. Force the delivery
7. Delete the BoM
8. Create and confirm the SO's invoice

Error: a traceback appears "ValueError: Expected singleton: uom.uom..."

Because of the configuration, when posting the invoice, we compute
the COGS. During that process, we need the average price of P_kit
https://github.com/odoo/odoo/blob/640907ec1852c4e477957c865549a87d3ae840dd/addons/sale_stock/models/account_move.py#L133
We give to that method the components' SMs. In
`_compute_average_price`, since we don't find a BoM, we will bypass
the mrp override
https://github.com/odoo/odoo/blob/419e42132d9526e9d98c2126158d4f88716d17c4/addons/mrp_account/models/product.py#L48-L50
As a result, it leads to
https://github.com/odoo/odoo/blob/640907ec1852c4e477957c865549a87d3ae840dd/addons/stock_account/models/product.py#L680-L684
Where we will have the candidates of all components (i.e., several
different products). But that method is not designed for such a
situation. This is the reason why, when calling `_consume_all`, it
will fail:
https://github.com/odoo/odoo/blob/858d24a611c4c8af0dcae82a6eb4077e391398ed/addons/stock_account/models/stock_valuation_layer.py#L85


We try to get the rounding of the product, but there are actually
two of them (the two components) -> singleton error

OPW-3218141

closes odoo/odoo#119944

Signed-off-by: default avatarWilliam Henrotin (whe) <whe@odoo.com>
parent 06a6e78b
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment