Steps to reproduce the bug:
- Create a storable product “P1”:
- Price at “Wood corner”:
- $5, min qty =1
- Price at “Open wood:
- $6, min qty = 1
- $4, min qty = 10
- Create a purchase order at wood corner:
- 100 units
> the price is automatically computed at $500
- Go to Alternative tab in the PO:
- Create a one for “Openwood” and copy lines
Problem:
The price for 100 units is computed as $600 instead of $400.
When we create the alternative purchase order, in the "create" function
of “purchase.order.line,” we receive only the quantity as "qty=100" in
the values. Therefore, the missing fields should be prepared.
https://github.com/odoo/odoo/blob/a9cbd2a2ae2e21f1ba14379aecd908c44497b8ab/addons/purchase/models/purchase.py#L1102
https://github.com/odoo/odoo/blob/a9cbd2a2ae2e21f1ba14379aecd908c44497b8ab/addons/purchase/models/purchase.py#L1102
First, the line is created with the received values (“qty=100”), and
the price_unit is computed correctly as $4.
https://github.com/odoo/odoo/blob/a9cbd2a2ae2e21f1ba14379aecd908c44497b8ab/addons/purchase/models/purchase.py#L1400
So, the price_unit is computed correctly at $4
However, the “onchange_product_id” function is then called, resetting
the price_unit and product_qty to 0.
https://github.com/odoo/odoo/blob/a9cbd2a2ae2e21f1ba14379aecd908c44497b8ab/addons/purchase/models/purchase.py#L1401
https://github.com/odoo/odoo/blob/a9cbd2a2ae2e21f1ba14379aecd908c44497b8ab/addons/purchase/models/purchase.py#L1176
Afterward, the “_suggest_quantity()” function is called
https://github.com/odoo/odoo/blob/a9cbd2a2ae2e21f1ba14379aecd908c44497b8ab/addons/purchase/models/purchase.py#L1180
suggesting a minimal quantity based on the seller (so=1).
https://github.com/odoo/odoo/blob/a9cbd2a2ae2e21f1ba14379aecd908c44497b8ab/addons/purchase/models/purchase.py#L1363
Therefore, the price_unit is computed based on qty=1, resulting in $6.
Finally, the price is returned because it is the only missing field.
opw-3497825
closes odoo/odoo#137774
X-original-commit: 0781198f1b5e5d6a4e2722ea3c663b74fb131bc3
Signed-off-by: Djamel Touati (otd) <otd@odoo.com>