Skip to content

Commit

Permalink
[FIX] ACH Payment Unbalanced Entry
Browse files Browse the repository at this point in the history
  • Loading branch information
atchuthan committed Sep 3, 2021
1 parent 49b55ed commit 2be02ad
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
13 changes: 6 additions & 7 deletions account_banking_ach_discount/models/account_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ def action_validate_invoice_payment(self):
class AccountPaymentLine(models.Model):
_inherit = "account.payment.line"

discount_amount = fields.Monetary(currency_field="currency_id")
total_amount = fields.Monetary(
compute="_compute_total_amount", currency_field="currency_id"
)
discount_amount = fields.Monetary(currency_field="currency_id",readonly=True)
total_amount = fields.Monetary(currency_field="currency_id",readonly=True)
payment_difference_handling = fields.Selection(
[("open", "Keep open"), ("reconcile", "Mark invoice as fully paid")],
default="reconcile",
Expand All @@ -73,10 +71,11 @@ class AccountPaymentLine(models.Model):
"account.move", related="move_line_id.move_id", store=True
)

@api.depends("amount_currency", "discount_amount")
def _compute_total_amount(self):
@api.onchange("amount_currency")
def _onchange_amount_currency(self):
for line in self:
line.total_amount = line.amount_currency + line.payment_difference
if not line.total_amount and not line.payment_difference:
line.total_amount = line.amount_currency

@api.model
def same_fields_payment_line_and_bank_payment_line(self):
Expand Down
30 changes: 16 additions & 14 deletions account_banking_ach_discount/models/account_payment_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ def _prepare_move(self, bank_lines=None):

temp_vals = vals[2].copy()
amount = line.amount_currency
total_amount = line.total_amount
amount_difference = round((total_amount - amount),2)
discount = line.discount_amount
payment_difference = line.payment_difference
line.payment_difference = payment_difference = amount_difference
writeoff = (
payment_difference and payment_difference - discount or 0.0
)
Expand All @@ -29,16 +31,15 @@ def _prepare_move(self, bank_lines=None):
"in_invoice",
"out_refund",
)

temp_vals["move_id"] = line.move_id.id
if use_debit:
temp_vals["debit"] = amount + discount
temp_vals["debit"] = total_amount - payment_difference
else:
temp_vals["credit"] = amount + discount
temp_vals["credit"] = total_amount - payment_difference

line_ids.append((0, 0, temp_vals))

if discount > 0:
if discount > 0 and discount == payment_difference:
discount_information = line.move_id.invoice_payment_term_id._check_payment_term_discount(
line.move_id, line.date
)
Expand All @@ -55,17 +56,18 @@ def _prepare_move(self, bank_lines=None):
if discount_vals:
line_ids.append((0, 0, discount_vals))

if invoice_close and round(writeoff, 2):
if invoice_close :
if use_debit:
temp_vals["debit"] = amount + discount + round(writeoff, 2)
temp_vals["debit"] = amount + payment_difference
else:
temp_vals["credit"] = amount + discount + round(writeoff, 2)
writeoff_vals = line.move_id._prepare_writeoff_move_line(
line, temp_vals.copy()
)
writeoff_vals["bank_payment_line_id"] = False
if writeoff_vals:
line_ids.append((0, 0, writeoff_vals))
temp_vals["credit"] = amount + payment_difference
if round(writeoff, 2):
writeoff_vals = line.move_id._prepare_writeoff_move_line(
line, temp_vals.copy()
)
writeoff_vals["bank_payment_line_id"] = False
if writeoff_vals:
line_ids.append((0, 0, writeoff_vals))
# payment order line
else:
line_ids.append(vals)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def make_payments(self):
"communication_type": "normal",
"amount_currency": line.amount,
"payment_difference": line.payment_difference,
"total_amount": line.amount + line.payment_difference,
}
)
return action
Expand Down

0 comments on commit 2be02ad

Please sign in to comment.