summaryrefslogtreecommitdiff
path: root/addons/mrp_account
diff options
context:
space:
mode:
authorArnold Moyaux <arm@odoo.com>2021-01-29 16:11:46 +0000
committerArnold Moyaux <arm@odoo.com>2021-01-29 16:28:10 +0000
commit827f65f70634ba7a2e4175f20e5301e514ada0a0 (patch)
treedb1660e705947012a1b1f6fc47b2b62404f43feb /addons/mrp_account
parente63fef3236da793668f8060f45ceee31d2833757 (diff)
[FIX] mrp_account: wrong kit cost
Usecase to reproduce - Create a KIT with COMP A (15$) COMP B (25$) - Enable Margin on SO - Set the cost on the KIT with compute cost button (40$) - Create a quotation with the KIT (cost is correct 40$) - Confirm the quotation -> Cost is updated to 15$ (first component) It happens because the function to compute the average price doesn't expect a kit and compute everything from the valuation layer of first component opw-2413246 closes odoo/odoo#65292 Signed-off-by: Arnold Moyaux <amoyaux@users.noreply.github.com>
Diffstat (limited to 'addons/mrp_account')
-rw-r--r--addons/mrp_account/models/product.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/addons/mrp_account/models/product.py b/addons/mrp_account/models/product.py
index 72f32617d02..d9c9d0f8524 100644
--- a/addons/mrp_account/models/product.py
+++ b/addons/mrp_account/models/product.py
@@ -40,6 +40,23 @@ class ProductProduct(models.Model):
if bom:
self.standard_price = self._compute_bom_price(bom, boms_to_recompute=boms_to_recompute)
+ def _compute_average_price(self, qty_invoiced, qty_to_invoice, stock_moves):
+ self.ensure_one()
+ if stock_moves.product_id == self:
+ return super()._compute_average_price(qty_invoiced, qty_to_invoice, stock_moves)
+ bom = self.env['mrp.bom']._bom_find(product=self, company_id=stock_moves.company_id.id, bom_type='phantom')
+ if not bom:
+ return super()._compute_average_price(qty_invoiced, qty_to_invoice, stock_moves)
+ dummy, bom_lines = bom.explode(self, 1)
+ bom_lines = {line: data for line, data in bom_lines}
+ value = 0
+ for move in stock_moves:
+ bom_line = move.bom_line_id
+ bom_line_data = bom_lines[bom_line]
+ bom_line_qty = bom_line_data['qty']
+ value += move.product_id._compute_average_price(qty_invoiced * bom_line_qty, qty_to_invoice * bom_line_qty, move)
+ return value
+
def _compute_bom_price(self, bom, boms_to_recompute=False):
self.ensure_one()
if not bom: