Odoo Mindscape. Understand Odoo faster. Explore modules, fields, dependencies and version differences in one place instead of digging through the source code.
Module: Expenses
Entity: hr.expense
Compute Method: _compute_price_unit
| Inputs | Method | Outputs |
|---|---|---|
|
"""
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
+ Otherwise it is always computed from the total_amount and the quantity else it would break the Receipt Entry
when edited after creation.
"""
for expense in self:
- if expense.state not in {'draft', 'reported'}:
+ if expense.state != 'draft':
continue
+
+ if not expense.company_id:
+ # This would be happening when emptying the required company_id field, triggering the "onchange"s.
+ # A traceback would occur because company_currency_id would be set to False.
+ # Instead of using the env company, recomputing the interface just to be blocked when trying to save
+ # we choose not to recompute anything and wait for a proper company to be inputted.
+ 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.
|
|
