Skip to content

Commit

Permalink
[FIX] budget_control_expense: compute without tax
Browse files Browse the repository at this point in the history
  • Loading branch information
Saran440 committed Sep 24, 2024
1 parent 561ee88 commit d83fdaa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
18 changes: 12 additions & 6 deletions budget_control_expense/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@ def _init_docline_budget_vals(self, budget_vals, analytic_id):
self.ensure_one()
res = super()._init_docline_budget_vals(budget_vals, analytic_id)
expense = self.expense_id
if expense: # case expense (support with include tax)
budget_vals["amount_currency"] = (
(expense.quantity * expense.unit_amount)
if expense.product_has_cost
else expense.total_amount
)
if expense:
# Amount from expense is tax included, need to convert to amount_untaxed
base_lines = [
expense._convert_to_tax_base_line_dict(
price_unit=expense.unit_amount, quantity=expense.quantity
)
]
taxes_totals = self.env["account.tax"]._compute_taxes(base_lines)["totals"][
expense.currency_id
]
total_amount = taxes_totals["amount_untaxed"]
budget_vals["amount_currency"] = total_amount
return res

def uncommit_expense_budget(self):
Expand Down
16 changes: 11 additions & 5 deletions budget_control_expense/models/hr_expense.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,18 @@ def recompute_budget_move(self):
def _init_docline_budget_vals(self, budget_vals, analytic_id):
self.ensure_one()
if not budget_vals.get("amount_currency", False):
# Amount expense is always include tax. so, we need to compute amount without tax
base_lines = [
self._convert_to_tax_base_line_dict(
price_unit=self.unit_amount, quantity=self.quantity
)
]
taxes_totals = self.env["account.tax"]._compute_taxes(base_lines)["totals"][
self.currency_id
]
total_amount = taxes_totals["amount_untaxed"]
# Percent analytic
percent_analytic = self[self._budget_analytic_field].get(str(analytic_id))
total_amount = (
(self.quantity * self.unit_amount)
if self.product_has_cost
else self.total_amount
)
budget_vals["amount_currency"] = total_amount * percent_analytic / 100
budget_vals["tax_ids"] = self.tax_ids.ids
# Document specific vals
Expand Down
1 change: 1 addition & 0 deletions budget_control_expense/tests/test_budget_expense.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def _create_expense_sheet(self, ex_lines):
ex.total_amount = ex_line["price_unit"] * ex_line["product_qty"]
ex.analytic_distribution = ex_line["analytic_distribution"]
expense = ex.save()
expense.tax_ids = False # test without tax
expense_ids.append(expense.id)
expense_sheet = self.env["hr.expense.sheet"].create(
{
Expand Down

0 comments on commit d83fdaa

Please sign in to comment.