|
|
"""
The price_unit is the unit price of the product if no product is set and no attachment overrides it.
Otherwise it is always computed from the total_amount and the quantity else it would break the vendor bill
when edited after creation.
"""
for expense in self:
if expense.state not in {'draft', 'reported'}:
continue
product_id = expense.product_id
if expense._needs_product_price_computation():
expense.price_unit = product_id._price_compute(
'standard_price',
uom=expense.product_uom_id,
company=expense.company_id,
)[product_id.id]
else:
expense.price_unit = expense.company_currency_id.round(expense.total_amount / expense.quantity) if expense.quantity else 0.
|
|