[IMP] hr_expense: use all taxes as price_included

In expense flow the taxes are calculated as included in price.
Prior, to guarantee it, we had domain - ('price_include', '=', True) on taxes.
That could be inconvenient from user's point of view, as they first needed to
define taxes with price_include = True. That led to users duplicating taxes
between included/excluded just so that they could use taxes in expense.

Now we force taxes to act like price_include = True. This way, user does not
need to define taxes just for expense's purposes and still taxes will be calculated
as it supposed to be - included in price.

task - 2850882

closes odoo/odoo#94392

Signed-off-by: Kevin Baptiste <kba@odoo.com>
This commit is contained in:
sofiagvaladze
2022-06-29 12:19:18 +02:00
parent 86959e5865
commit bcea427c02
3 changed files with 5 additions and 5 deletions
+3 -3
View File
@@ -76,7 +76,7 @@ class HrExpense(models.Model):
quantity = fields.Float(required=True, states={'done': [('readonly', True)]}, digits='Product Unit of Measure', default=1)
tax_ids = fields.Many2many('account.tax', 'expense_tax', 'expense_id', 'tax_id',
compute='_compute_from_product_id_company_id', store=True, readonly=False,
domain="[('company_id', '=', company_id), ('type_tax_use', '=', 'purchase'), ('price_include', '=', True)]", string='Included taxes')
domain="[('company_id', '=', company_id), ('type_tax_use', '=', 'purchase')]", string='Included taxes')
amount_tax = fields.Monetary(string='Tax amount in Currency', help="Tax amount in currency", compute='_compute_amount_tax', store=True, currency_field='currency_id')
amount_tax_company = fields.Monetary('Tax amount', help="Tax amount in company currency", compute='_compute_total_amount_company', store=True, currency_field='company_currency_id')
amount_residual = fields.Monetary(string='Amount Due', compute='_compute_amount_residual')
@@ -187,7 +187,7 @@ class HrExpense(models.Model):
def _get_taxes(self, price, quantity):
self.ensure_one()
return self.tax_ids.compute_all(price_unit=price, currency=self.currency_id, quantity=quantity, product=self.product_id, partner=self.employee_id.user_id.partner_id)
return self.tax_ids.with_context(force_price_include=True).compute_all(price_unit=price, currency=self.currency_id, quantity=quantity, product=self.product_id, partner=self.employee_id.user_id.partner_id)
@api.depends("sheet_id.account_move_id.line_ids")
def _compute_amount_residual(self):
@@ -621,7 +621,7 @@ Or send your receipts at <a href="mailto:%(email)s?subject=Lunch%%20with%%20cust
unit_amount = expense.total_amount
quantity = 1
taxes = expense.tax_ids.with_context(round=True).compute_all(unit_amount, expense.currency_id, quantity, expense.product_id)
taxes = expense._get_taxes(price=unit_amount, quantity=quantity)
total_amount = 0.0
total_amount_currency = 0.0
partner_id = expense.employee_id.sudo().address_home_id.commercial_partner_id.id
+1 -1
View File
@@ -538,7 +538,7 @@
</group>
<group string="Accounting">
<field name="property_account_expense_id" groups="account.group_account_readonly"/>
<field name="supplier_taxes_id" domain="[('price_include', '=', True)]" widget="many2many_tags"
<field name="supplier_taxes_id" widget="many2many_tags"
context="{'default_type_tax_use':'purchase', 'default_price_include': 1}"
options="{'no_quick_create': True}"/>
</group>
+1 -1
View File
@@ -41,7 +41,7 @@ class HrExpenseSplit(models.TransientModel):
@api.depends('total_amount', 'tax_ids')
def _compute_amount_tax(self):
for split in self:
taxes = split.tax_ids.compute_all(price_unit=split.total_amount, currency=split.currency_id, quantity=1, product=split.product_id)
taxes = split.tax_ids.with_context(force_price_include=True).compute_all(price_unit=split.total_amount, currency=split.currency_id, quantity=1, product=split.product_id)
split.amount_tax = taxes['total_included'] - taxes['total_excluded']
@api.depends('product_id')