summaryrefslogtreecommitdiff
path: root/addons/sale_mrp/models/account_move.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/sale_mrp/models/account_move.py
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/sale_mrp/models/account_move.py')
-rw-r--r--addons/sale_mrp/models/account_move.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/addons/sale_mrp/models/account_move.py b/addons/sale_mrp/models/account_move.py
new file mode 100644
index 00000000..6f338835
--- /dev/null
+++ b/addons/sale_mrp/models/account_move.py
@@ -0,0 +1,31 @@
+# -*- coding: utf-8 -*-
+
+from odoo import models
+
+
+class AccountMoveLine(models.Model):
+ _inherit = "account.move.line"
+
+ def _stock_account_get_anglo_saxon_price_unit(self):
+ price_unit = super(AccountMoveLine, self)._stock_account_get_anglo_saxon_price_unit()
+
+ so_line = self.sale_line_ids and self.sale_line_ids[-1] or False
+ if so_line:
+ bom = so_line.product_id.product_tmpl_id.bom_ids.filtered(lambda b: not b.company_id or b.company_id == so_line.company_id)[:1]
+ if bom and bom.type == 'phantom':
+ qty_to_invoice = self.product_uom_id._compute_quantity(self.quantity, self.product_id.uom_id)
+ qty_invoiced = sum([x.product_uom_id._compute_quantity(x.quantity, x.product_id.uom_id) for x in so_line.invoice_lines if x.move_id.state == 'posted'])
+ moves = so_line.move_ids
+ average_price_unit = 0
+ components = so_line._get_bom_component_qty(bom)
+ for product_id in components:
+ product = self.env['product.product'].browse(product_id)
+ factor = components[product_id]['qty']
+ prod_moves = moves.filtered(lambda m: m.product_id == product)
+ prod_qty_invoiced = factor * qty_invoiced
+ prod_qty_to_invoice = factor * qty_to_invoice
+ average_price_unit += factor * product._compute_average_price(prod_qty_invoiced, prod_qty_to_invoice, prod_moves)
+ price_unit = average_price_unit / bom.product_qty or price_unit
+ price_unit = self.product_id.uom_id._compute_price(price_unit, self.product_uom_id)
+ return price_unit
+