|
|
def has_manual_price(line):
# `line.currency_id` can be False for NewId records
currency = (
line.currency_id
or line.company_id.currency_id
or line.env.company.currency_id
)
return currency.compare_amounts(line.technical_price_unit, line.price_unit)
force_recompute = self.env.context.get('force_price_recomputation')
for line in self:
# Don't compute the price for deleted lines.
if not line.order_id:
continue
# check if the price has been manually set or there is already invoiced amount.
# if so, the price shouldn't change as it might have been manually edited.
if (
(not force_recompute and has_manual_price(line))
or line.qty_invoiced > 0
or (line.product_id.expense_policy == 'cost' and line.is_expense)
):
continue
line = line.with_context(sale_write_from_compute=True)
if not line.product_uom or not line.product_id:
line.price_unit = 0.0
line.technical_price_unit = 0.0
else:
line._reset_price_unit()
|
|