19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:32:12 +01:00
parent 79f83631d5
commit 73afc09215
6267 changed files with 1534193 additions and 1130106 deletions

View file

@ -7,23 +7,28 @@ from odoo import api, fields, models
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
@api.depends('move_ids', 'move_ids.stock_valuation_layer_ids', 'move_ids.picking_id.state')
@api.depends('move_ids', 'move_ids.value', 'move_ids.picking_id.state')
def _compute_purchase_price(self):
lines_without_moves = self.browse()
line_ids_to_pass = set()
for line in self:
product = line.product_id.with_company(line.company_id)
if not line.move_ids:
lines_without_moves |= line
elif product.categ_id.property_cost_method != 'standard':
purch_price = product._compute_average_price(0, line.product_uom_qty, line.move_ids.with_company(line.company_id))
if line.product_uom and line.product_uom != product.uom_id:
purch_price = product.uom_id._compute_price(purch_price, line.product_uom)
to_cur = line.currency_id or line.order_id.currency_id
line.purchase_price = product.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()
if not line.has_valued_move_ids():
line_ids_to_pass.add(line.id)
elif line.product_id and line.product_id.categ_id and line.product_id.categ_id.property_cost_method != 'standard':
# don't overwrite any existing value unless non-standard cost method
qty_from_delivery = line.qty_delivered
price_unit_from_delivery = line.move_ids.filtered(lambda m: m.state == 'done')._get_price_unit() if qty_from_delivery > 0 else 0
if qty_from_delivery <= 0:
purch_price = product.standard_price
else:
qty_from_std_price = max(line.product_uom_qty - qty_from_delivery, 0)
purch_price = (qty_from_delivery * price_unit_from_delivery + qty_from_std_price * product.standard_price) / (qty_from_delivery + qty_from_std_price)
purch_price_uom = line.product_id.uom_id._compute_price(purch_price, line.product_uom_id)
line.purchase_price = line._convert_to_sol_currency(
purch_price_uom,
product.cost_currency_id,
)
elif not line.product_uom_qty and line.qty_delivered:
# if line added from delivery and standard price, pass to super
line_ids_to_pass.add(line.id)
return super(SaleOrderLine, self.browse(line_ids_to_pass))._compute_purchase_price()