Skip to content

Commit

Permalink
[FIX] Improved code.
Browse files Browse the repository at this point in the history
  • Loading branch information
murtuzasaleh committed Mar 9, 2022
1 parent df43dc3 commit 92a2c27
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
10 changes: 6 additions & 4 deletions account_banking_ach_discount/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ def _prepare_payment_line_vals(self, payment_order):
amount_currency = vals.get("amount_currency")
# No discount for open invoices
if (
"payment_line_state" in self._context
and self._context.get("payment_line_state") != "open"
("payment_line_state" in self._context
and self._context.get("payment_line_state") != "open")
or self._context.get("is_new_order")
or self._context.get("is_update_order")
):
if (
invoice
Expand All @@ -25,15 +27,15 @@ def _prepare_payment_line_vals(self, payment_order):
discount_information = (
invoice.invoice_payment_term_id._check_payment_term_discount(
invoice,
self._context.get("payment_date") or invoice.date_invoice,
self._context.get("payment_date") or invoice.invoice_date,
)
)
discount_amt = discount_information[0]
vals.update(
{
"discount_amount": discount_amt,
"amount_currency": amount_currency - discount_amt,
"writeoff_account_id": discount_information[1]
}
)

return vals
5 changes: 5 additions & 0 deletions account_banking_ach_discount/models/account_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ class AccountPaymentLine(models.Model):
"account.move", related="move_line_id.move_id", store=True
)

@api.onchange("discount_amount")
def _onchange_discount_amount(self):
if self.discount_amount:
self.amount_currency = self.amount_currency - self.discount_amount

@api.depends("amount_currency", "discount_amount")
def _compute_total_amount(self):
for line in self:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ def _prepare_move(self, bank_lines=None):
# Discount Taken Update
line.move_id.discount_taken = discount


if invoice_close and round(writeoff, 2):
if use_debit:
temp_vals["debit"] = amount + discount + round(writeoff, 2)
Expand Down

0 comments on commit 92a2c27

Please sign in to comment.