[FIX] sale_stock_margin: compute purchase_price from correct company

- Install sale_stock_margin
- In a multi-company environment, create a Product (i.e. Product X)
with a different Cost in each Company
- Switch to Company that is not the main one
- Create a SO with Product X
- Make sure Cost (purchase_price) field is diplayed in Order Lines tab
- Confirm SO
After confirmation, the purchase_price of Product X switches from Cost configured
for current Company to Cost configured for the main Company.

opw-2389741

closes odoo/odoo#62997

X-original-commit: 82106350d3a7b82c6c529ae4ff9a2513ae34518e
Signed-off-by: Anh Thao PHAM <kitan191@users.noreply.github.com>
This commit is contained in:
Anh Thao Pham (pta)
2020-12-08 09:57:00 +00:00
parent e037852ce7
commit 38fd5f4eb9
@@ -14,5 +14,5 @@ class SaleOrderLine(models.Model):
if not line.move_ids:
lines_without_moves |= line
else:
line.purchase_price = line.product_id._compute_average_price(0, line.product_uom_qty, line.move_ids)
line.purchase_price = line.product_id.with_company(line.company_id)._compute_average_price(0, line.product_uom_qty, line.move_ids)
return super(SaleOrderLine, lines_without_moves)._compute_purchase_price()