[FIX] hr_expense: expenses should be tax included
During a refactoring [1], the behavior of having the taxes included in the price for all expenses was broken/removed. All the fields related to taxes are computed should be computed with the correct context key when computing entries related to expenses. This is preferred to adding the context key only when creating because it will then keep the behavior even when editing the document. task-3043252 [1]: https://github.com/odoo/odoo/commit/d8d47f9ff8554f4b39487fd2f13c153c7d6f958d closes odoo/odoo#104746 X-original-commit: 6e944ac5fe108d5f2bc2d3f41ab547efd88a5ede Signed-off-by: Laurent Smet <las@odoo.com> Signed-off-by: William André (wan) <wan@odoo.com>
This commit is contained in:
@@ -34,15 +34,28 @@ class AccountMoveLine(models.Model):
|
||||
line.tax_key = frozendict(**line.tax_key, expense_id=line.expense_id.id)
|
||||
|
||||
def _compute_all_tax(self):
|
||||
super()._compute_all_tax()
|
||||
for line in self:
|
||||
if line.expense_id:
|
||||
for key in list(line.compute_all_tax.keys()):
|
||||
new_key = frozendict(**key, expense_id=line.expense_id.id)
|
||||
line.compute_all_tax[new_key] = line.compute_all_tax.pop(key)
|
||||
expense_lines = self.filtered('expense_id')
|
||||
super(AccountMoveLine, expense_lines.with_context(force_price_include=True))._compute_all_tax()
|
||||
super(AccountMoveLine, self - expense_lines)._compute_all_tax()
|
||||
for line in expense_lines:
|
||||
for key in list(line.compute_all_tax.keys()):
|
||||
new_key = frozendict(**key, expense_id=line.expense_id.id)
|
||||
line.compute_all_tax[new_key] = line.compute_all_tax.pop(key)
|
||||
|
||||
def _compute_totals(self):
|
||||
expenses = self.filtered('expense_id')
|
||||
super(AccountMoveLine, expenses.with_context(force_price_include=True))._compute_totals()
|
||||
super(AccountMoveLine, self - expenses)._compute_totals()
|
||||
|
||||
def _compute_term_key(self):
|
||||
super()._compute_term_key()
|
||||
for line in self:
|
||||
if line.expense_id:
|
||||
line.term_key = line.term_key and frozendict(**line.term_key, expense_id=line.expense_id.id)
|
||||
|
||||
def _convert_to_tax_base_line_dict(self):
|
||||
result = super()._convert_to_tax_base_line_dict()
|
||||
if self.move_id.expense_sheet_id:
|
||||
result.setdefault('extra_context', {})
|
||||
result['extra_context']['force_price_include'] = True
|
||||
return result
|
||||
|
||||
@@ -55,6 +55,3 @@ class TestExpenseCommon(AccountTestInvoicingCommon):
|
||||
|
||||
# Ensure products can be expensed.
|
||||
(cls.product_a + cls.product_b).write({'can_be_expensed': True})
|
||||
# Taxes on the products are included in price
|
||||
(cls.product_a.supplier_taxes_id + cls.product_b.supplier_taxes_id).write({'price_include': True})
|
||||
cls.company_data['default_tax_purchase'].write({'price_include': True})
|
||||
|
||||
Reference in New Issue
Block a user