From 9cdb1814c918478c0f7510a99e6a3ddb9fd60b7f Mon Sep 17 00:00:00 2001 From: ps-tubtim Date: Mon, 17 Jul 2023 09:36:20 +0700 Subject: [PATCH] [FIX] hr_Expense_excluded_tax --- hr_expense_excluded_tax/models/hr_expense.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/hr_expense_excluded_tax/models/hr_expense.py b/hr_expense_excluded_tax/models/hr_expense.py index 2a00f06ad..3afa25c68 100644 --- a/hr_expense_excluded_tax/models/hr_expense.py +++ b/hr_expense_excluded_tax/models/hr_expense.py @@ -1,7 +1,7 @@ # Copyright 2023 Ecosoft Co., Ltd (http://ecosoft.co.th/) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import fields, models +from odoo import api, fields, models class HrExpense(models.Model): @@ -10,3 +10,20 @@ class HrExpense(models.Model): tax_ids = fields.Many2many( domain="[('company_id', '=', company_id), ('type_tax_use', '=', 'purchase')]", ) + + @api.depends("total_amount", "tax_ids", "currency_id") + def _compute_amount_tax(self): + """Calculate untaxed_amount if the user selects + excluded tax in a product that has a cost""" + res = super()._compute_amount_tax() + for expense in self: + if expense.product_has_cost: + taxes = expense.tax_ids.compute_all( + expense.unit_amount, + expense.currency_id, + expense.quantity, + expense.product_id, + expense.employee_id.user_id.partner_id, + ) + expense.untaxed_amount = taxes.get("total_excluded") + return res