From 96b5b6b5157f4c6911ada0e779778c92a90705a3 Mon Sep 17 00:00:00 2001 From: william Date: Thu, 27 Oct 2022 12:51:12 +0000 Subject: [PATCH] [FIX] hr_expense: expenses should be tax included MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: William André (wan) --- addons/hr_expense/models/account_move_line.py | 25 ++++++++++++++----- addons/hr_expense/tests/common.py | 3 --- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/addons/hr_expense/models/account_move_line.py b/addons/hr_expense/models/account_move_line.py index 6680057a171..bb9ca3613ab 100644 --- a/addons/hr_expense/models/account_move_line.py +++ b/addons/hr_expense/models/account_move_line.py @@ -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 diff --git a/addons/hr_expense/tests/common.py b/addons/hr_expense/tests/common.py index e88b0434e01..3604ed2d72a 100644 --- a/addons/hr_expense/tests/common.py +++ b/addons/hr_expense/tests/common.py @@ -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})