diff --git a/account_banking_ach_discount/models/account_move_line.py b/account_banking_ach_discount/models/account_move_line.py index 683cdf18..3ac68887 100644 --- a/account_banking_ach_discount/models/account_move_line.py +++ b/account_banking_ach_discount/models/account_move_line.py @@ -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 @@ -25,7 +27,7 @@ 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] @@ -33,7 +35,7 @@ def _prepare_payment_line_vals(self, payment_order): { "discount_amount": discount_amt, "amount_currency": amount_currency - discount_amt, + "writeoff_account_id": discount_information[1] } ) - return vals diff --git a/account_banking_ach_discount/models/account_payment.py b/account_banking_ach_discount/models/account_payment.py index cf76d50d..dead2639 100644 --- a/account_banking_ach_discount/models/account_payment.py +++ b/account_banking_ach_discount/models/account_payment.py @@ -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: diff --git a/account_banking_ach_discount/models/account_payment_order.py b/account_banking_ach_discount/models/account_payment_order.py index 329e3d64..8664e976 100644 --- a/account_banking_ach_discount/models/account_payment_order.py +++ b/account_banking_ach_discount/models/account_payment_order.py @@ -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)