Skip to content

Commit

Permalink
Merge pull request #464 from ecosoft-odoo/16.0-fix-budget_control_exp…
Browse files Browse the repository at this point in the history
…ense-tax_return

[FIX] budget_control_expense: no return tax line
  • Loading branch information
Saran440 authored Sep 24, 2024
2 parents 5368a56 + 38f131e commit afba62a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 14 deletions.
3 changes: 2 additions & 1 deletion budget_control/models/budget_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ def check_budget_precommit(self, doclines, doc_type="account"):
if budget_move:
budget_moves.append(budget_move)
# Update database, so we can check budget with query
budget_move.flush_model()
if budget_move:
budget_move.flush_model()
# Check Budget
self.env["budget.period"].check_budget(doclines, doc_type=doc_type)
# Remove commits
Expand Down
2 changes: 1 addition & 1 deletion budget_control_expense/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
"name": "Budget Control on Expense",
"version": "16.0.1.0.0",
"version": "16.0.1.0.1",
"license": "AGPL-3",
"author": "Ecosoft, Odoo Community Association (OCA)",
"website": "https://github.com/ecosoft-odoo/budgeting",
Expand Down
21 changes: 14 additions & 7 deletions budget_control_expense/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,27 @@ 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):
"""Uncommit the budget for related expenses when the vendor bill is in a valid state."""
Expense = self.env["hr.expense"]
for ml in self:
inv_state = ml.move_id.state
if not ml.move_id.expense_sheet_id:
# Skip if not expense or tax line
if not ml.move_id.expense_sheet_id or ml.display_type == "tax":
continue
if inv_state == "posted":
expense = ml.expense_id.filtered("amount_commit")
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 afba62a

Please sign in to comment.