Skip to content

Commit

Permalink
[FIX] advance_clearing when draft move of return advance
Browse files Browse the repository at this point in the history
  • Loading branch information
Saran440 committed Oct 16, 2023
1 parent b447bab commit 856876a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
30 changes: 28 additions & 2 deletions budget_control_advance_clearing/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,38 @@
class AccountMove(models.Model):
_inherit = "account.move"

def action_post(self):
res = super().action_post()
BudgetMove = self.env["advance.budget.move"]
moves_inbound = self.filtered(lambda l: l.payment_id.payment_type == "inbound")
# Unlink advance return commit
if moves_inbound:
return_advances = BudgetMove.search(
[
("move_id", "in", moves_inbound.ids),
("debit", ">", 0.0),
]
)
return_advances.unlink()
return res

def button_draft(self):
"""Unlink return advance budget"""
res = super().button_draft()
BudgetMove = self.env["advance.budget.move"]
moves_inbound = self.filtered(lambda l: l.payment_id.payment_type == "inbound")
if moves_inbound:
return_advances = BudgetMove.search([("move_id", "in", moves_inbound.ids)])
return_advances.unlink()
return_advances = BudgetMove.search(
[
("move_id", "in", moves_inbound.ids),
("credit", ">", 0.0),
]
)
# Commit budget again
for ret in return_advances:
ret.expense_id.commit_budget(
amount_currency=ret.amount_currency,
move_line_id=ret.move_line_id.id,
date=ret.date,
)
return res
8 changes: 4 additions & 4 deletions budget_control_advance_clearing/models/hr_expense.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def _get_return_budget_moves(self):
[("sheet_id", "=", av_sheet.id), ("move_line_id", "!=", False)]
)
return_budget_moves += [
(x.move_line_id, x.amount_currency, x.expense_id)
(x.move_line_id, x.amount_currency, x.expense_id, x.credit)
for x in return_advances
]
return return_budget_moves
Expand Down Expand Up @@ -150,7 +150,7 @@ def recompute_budget_move(self):
# Recompute budget moves for advances
self._get_recompute_advances()
# Return advance, commit again because it will lose from clearing uncommit
for move_line, amount, advance in return_budget_moves:
for move_line, amount, advance, credit in return_budget_moves:
origin_clearing_amount = amount
# Find new advance if amount_commit <= 0.0
if (
Expand Down Expand Up @@ -183,7 +183,7 @@ def recompute_budget_move(self):
!= 1
):
advance.commit_budget(
reverse=True,
reverse=bool(credit),
amount_currency=origin_clearing_amount,
move_line_id=move_line.id,
analytic_account_id=advance.fwd_analytic_account_id or False,
Expand All @@ -195,7 +195,7 @@ def recompute_budget_move(self):
)
origin_clearing_amount -= return_advance_amount
advance.commit_budget(
reverse=True,
reverse=bool(credit),
amount_currency=return_advance_amount,
move_line_id=move_line.id,
analytic_account_id=advance.fwd_analytic_account_id or False,
Expand Down

0 comments on commit 856876a

Please sign in to comment.