Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][FIX] hr_expense_advance_clearing: clear advance partial #250

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion hr_expense_advance_clearing/models/account_move.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2022 Ecosoft Co., Ltd. (https://ecosoft.co.th)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import _, models
from odoo import _, api, models
from odoo.exceptions import UserError


Expand Down Expand Up @@ -36,3 +36,44 @@ def _reverse_moves(self, default_values_list=None, cancel=False):
return super()._reverse_moves(
default_values_list=default_values_list, cancel=cancel
)

@api.depends(
"line_ids.matched_debit_ids.debit_move_id.move_id.payment_id.is_matched",
"line_ids.matched_debit_ids.debit_move_id.move_id.line_ids.amount_residual",
"line_ids.matched_debit_ids.debit_move_id.move_id.line_ids.amount_residual_currency",
"line_ids.matched_credit_ids.credit_move_id.move_id.payment_id.is_matched",
"line_ids.matched_credit_ids.credit_move_id.move_id.line_ids.amount_residual",
"line_ids.matched_credit_ids.credit_move_id.move_id.line_ids.amount_residual_currency",
"line_ids.balance",
"line_ids.currency_id",
"line_ids.amount_currency",
"line_ids.amount_residual",
"line_ids.amount_residual_currency",
"line_ids.payment_id.state",
"line_ids.full_reconcile_id",
"state",
)
def _compute_amount(self):
"""Compute amount residual for advance clearing case."""
res = super()._compute_amount()
for move in self:
total_residual = 0.0
total_residual_currency = 0.0
for line in move.line_ids:
if line.account_type not in ("asset_receivable", "liability_payable"):
continue
# Line residual amount.
clearing = line.expense_id.sheet_id.filtered(
lambda sheet: sheet.advance_sheet_id
)
if clearing:
# Residual amount.
total_residual += line.amount_residual
total_residual_currency += line.amount_residual_currency

# Update amount residual for case clearing
if total_residual and total_residual_currency:
sign = move.direction_sign
move.amount_residual = -sign * total_residual
move.amount_residual_signed = total_residual_currency
return res
10 changes: 8 additions & 2 deletions hr_expense_advance_clearing/models/hr_expense_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,16 @@ def _check_advance_expense(self):

@api.depends("account_move_id.payment_state")
def _compute_payment_state(self):
"""After clear advance. payment state will change to 'paid'"""
"""After clear advance.
if amount residual is zero, payment state will change to 'paid'
"""
res = super()._compute_payment_state()
for sheet in self:
if sheet.advance_sheet_id and sheet.account_move_id.state == "posted":
if (
sheet.advance_sheet_id
and sheet.account_move_id.state == "posted"
and not sheet.amount_residual
):
sheet.payment_state = "paid"
return res

Expand Down
Loading