diff --git a/sale_down_payment/models/account_move_line.py b/sale_down_payment/models/account_move_line.py index 601f3ef..347a12d 100644 --- a/sale_down_payment/models/account_move_line.py +++ b/sale_down_payment/models/account_move_line.py @@ -30,3 +30,8 @@ class AccountMoveLine(models.Model): def sale_advance_payement_account_id_change(self): if self.sale_id and self.account_id.user_type_id.type != 'receivable': self.sale_id = False + + def _sale_down_payment_hook(self): + # can be used for notifications + self.ensure_one() + diff --git a/sale_down_payment/models/account_payment.py b/sale_down_payment/models/account_payment.py index c789389..0eaaf49 100644 --- a/sale_down_payment/models/account_payment.py +++ b/sale_down_payment/models/account_payment.py @@ -25,6 +25,14 @@ class AccountPayment(models.Model): res['sale_id'] = self.sale_id.id return res + def _create_payment_entry(self, amount): + move = super()._create_payment_entry(amount) + if hasattr(self, 'sale_id') and self.sale_id: + for line in move.line_ids: + if line.sale_id and line.account_id.internal_type == 'receivable': + line._sale_down_payment_hook() + return move + class AccountAbstractPayment(models.AbstractModel): _inherit = "account.abstract.payment" diff --git a/sale_down_payment/wizard/account_bank_statement_sale.py b/sale_down_payment/wizard/account_bank_statement_sale.py index 8d86a85..5288dd7 100644 --- a/sale_down_payment/wizard/account_bank_statement_sale.py +++ b/sale_down_payment/wizard/account_bank_statement_sale.py @@ -64,7 +64,9 @@ class AccountBankStatementSale(models.TransientModel): self.ensure_one() for line in self.line_ids: if line.move_line_id.sale_id != line.sale_id: - line.move_line_id.sale_id = line.sale_id.id + line.move_line_id.write({'sale_id': line.sale_id.id or False}) + if line.sale_id: + line.move_line_id._sale_down_payment_hook() class AccountBankStatementSaleLine(models.TransientModel):