From cbd395ec365f5f2f484d7137559a62a135bda5fa Mon Sep 17 00:00:00 2001 From: Nikunj Ladava Date: Tue, 20 Mar 2018 11:36:35 +0530 Subject: [PATCH] [IMP] payment, sale_payment: set invoice id in payment transaction form after payment being done from sale order. Until now invoice_id is filled on the transaction only when we make payments through invoice. However if we make payments through sale order then invoice_id is not filled. This commit fixes that issue. As there is no common point between sale_payment and account_payment except payment, a void method is added in payment and an override done in account_payment. That was when both modules are installed code is correctly triggered. This commit is related to task ID 1813602. Closes #22746 . --- addons/account_payment/models/payment.py | 7 +++++++ addons/payment/models/payment_acquirer.py | 4 ++++ addons/sale_payment/models/payment.py | 1 + 3 files changed, 12 insertions(+) diff --git a/addons/account_payment/models/payment.py b/addons/account_payment/models/payment.py index 0ad11d39788..389cfa206e1 100644 --- a/addons/account_payment/models/payment.py +++ b/addons/account_payment/models/payment.py @@ -175,3 +175,10 @@ class PaymentTransaction(models.Model): }) return tx + + def _post_process_after_done(self, **kwargs): + # set invoice id in payment transaction when payment being done from sale order + res = super(PaymentTransaction, self)._post_process_after_done() + if kwargs.get('invoice_id'): + self.account_invoice_id = kwargs['invoice_id'] + return res diff --git a/addons/payment/models/payment_acquirer.py b/addons/payment/models/payment_acquirer.py index 343e7ebd116..691de438072 100644 --- a/addons/payment/models/payment_acquirer.py +++ b/addons/payment/models/payment_acquirer.py @@ -684,6 +684,10 @@ class PaymentTransaction(models.Model): return True + @api.multi + def _post_process_after_done(self, **kwargs): + return True + # -------------------------------------------------- # SERVER2SERVER RELATED METHODS # -------------------------------------------------- diff --git a/addons/sale_payment/models/payment.py b/addons/sale_payment/models/payment.py index 857ff857dfb..8076addab09 100644 --- a/addons/sale_payment/models/payment.py +++ b/addons/sale_payment/models/payment.py @@ -103,6 +103,7 @@ class PaymentTransaction(models.Model): created_invoice.with_context(default_currency_id=self.currency_id.id).pay_and_reconcile(self.acquirer_id.journal_id, pay_amount=created_invoice.amount_total) if created_invoice.payment_ids: created_invoice.payment_ids[0].payment_transaction_id = self + self._post_process_after_done(invoice_id=created_invoice) else: _logger.warning('<%s> transaction completed, could not auto-generate invoice for %s (ID %s)', self.acquirer_id.provider, self.sale_order_id.name, self.sale_order_id.id)