|
|
"""
Note: as total_amount_currency can be set directly by the user (for product without cost)
or needs to be computed (for product with cost), `untaxed_amount_currency` can't be computed in the same method as `total_amount_currency`.
"""
AccountTax = self.env['account.tax']
for expense in self:
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
base_line = expense._prepare_base_line_for_taxes_computation(
price_unit=expense.total_amount_currency,
quantity=1.0,
)
AccountTax._add_tax_details_in_base_line(base_line, expense.company_id)
AccountTax._round_base_lines_tax_details([base_line], expense.company_id)
tax_details = base_line['tax_details']
expense.tax_amount_currency = tax_details['total_included_currency'] - tax_details['total_excluded_currency']
expense.untaxed_amount_currency = tax_details['total_excluded_currency']
|
|