summaryrefslogtreecommitdiff
path: root/addons/sale_stock_margin/models
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_stock_margin/models
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/sale_stock_margin/models')
-rw-r--r--addons/sale_stock_margin/models/__init__.py4
-rw-r--r--addons/sale_stock_margin/models/sale_order_line.py28
2 files changed, 32 insertions, 0 deletions
diff --git a/addons/sale_stock_margin/models/__init__.py b/addons/sale_stock_margin/models/__init__.py
new file mode 100644
index 00000000..83c06ee1
--- /dev/null
+++ b/addons/sale_stock_margin/models/__init__.py
@@ -0,0 +1,4 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from . import sale_order_line
diff --git a/addons/sale_stock_margin/models/sale_order_line.py b/addons/sale_stock_margin/models/sale_order_line.py
new file mode 100644
index 00000000..cc023427
--- /dev/null
+++ b/addons/sale_stock_margin/models/sale_order_line.py
@@ -0,0 +1,28 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import api, fields, models
+
+
+class SaleOrderLine(models.Model):
+ _inherit = 'sale.order.line'
+
+ @api.depends('move_ids', 'move_ids.stock_valuation_layer_ids', 'order_id.picking_ids.state')
+ def _compute_purchase_price(self):
+ lines_without_moves = self.browse()
+ for line in self:
+ if not line.move_ids:
+ lines_without_moves |= line
+ elif line.product_id.categ_id.property_cost_method != 'standard':
+ purch_price = line.product_id.with_company(line.company_id)._compute_average_price(0, line.product_uom_qty, line.move_ids)
+ if line.product_uom and line.product_uom != line.product_id.uom_id:
+ purch_price = line.product_id.uom_id._compute_price(purch_price, line.product_uom)
+ to_cur = line.currency_id or line.order_id.currency_id
+ line.purchase_price = line.product_id.cost_currency_id._convert(
+ from_amount=purch_price,
+ to_currency=to_cur,
+ company=line.company_id or self.env.company,
+ date=line.order_id.date_order or fields.Date.today(),
+ round=False,
+ ) if to_cur and purch_price else purch_price
+ return super(SaleOrderLine, lines_without_moves)._compute_purchase_price()