diff --git a/addons/payment/models/payment_acquirer.py b/addons/payment/models/payment_acquirer.py index 5a57a90cb3c..14d4bc55f77 100644 --- a/addons/payment/models/payment_acquirer.py +++ b/addons/payment/models/payment_acquirer.py @@ -725,6 +725,12 @@ class PaymentTransaction(models.Model): if any(trans.state not in ('draft', 'authorized') for trans in self): raise ValidationError(_('Only draft/authorized transaction can be posted.')) + self.write({'state': 'done', 'date': datetime.now().strftime(DEFAULT_SERVER_DATETIME_FORMAT)}) + self._reconcile_after_transaction_done() + self._log_payment_transaction_received() + + @api.multi + def _reconcile_after_transaction_done(self): # Validate invoices automatically upon the transaction is posted. invoices = self.mapped('invoice_ids').filtered(lambda inv: inv.state == 'draft') invoices.action_invoice_open() @@ -746,9 +752,6 @@ class PaymentTransaction(models.Model): for company in payments: payments[company].with_context(force_company=company, company_id=company).post() - self.write({'state': 'done', 'date': datetime.now().strftime(DEFAULT_SERVER_DATETIME_FORMAT)}) - self._log_payment_transaction_received() - @api.multi def _set_transaction_cancel(self): '''Move the transaction's payment to the cancel state(e.g. Paypal).''' diff --git a/addons/sale_payment/models/payment.py b/addons/sale_payment/models/payment.py index 9c2afc96b72..1cc47bf45d5 100644 --- a/addons/sale_payment/models/payment.py +++ b/addons/sale_payment/models/payment.py @@ -59,14 +59,19 @@ class PaymentTransaction(models.Model): so.action_confirm() @api.multi - def _set_transaction_done(self): + def _reconcile_after_transaction_done(self): # Override of '_set_transaction_done' in the 'payment' module # to confirm the quotations automatically and to generate the invoices if needed. sales_orders = self.mapped('sale_order_ids').filtered(lambda so: so.state == 'draft') sales_orders.force_quotation_send() sales_orders = self.mapped('sale_order_ids').filtered(lambda so: so.state == 'sent') sales_orders.action_confirm() + # invoice the sale orders if needed + self._invoice_sale_orders() + return super(PaymentTransaction, self)._reconcile_after_transaction_done() + @api.multi + def _invoice_sale_orders(self): if self.env['ir.config_parameter'].sudo().get_param('website_sale.automatic_invoice'): for trans in self.filtered(lambda t: t.sale_order_ids): ctx_company = {'company_id': self.acquirer_id.company_id.id, @@ -75,7 +80,6 @@ class PaymentTransaction(models.Model): trans.sale_order_ids._force_lines_to_invoice_policy_order() invoices = trans.sale_order_ids.action_invoice_create() trans.invoice_ids = [(6, 0, invoices)] - return super(PaymentTransaction, self)._set_transaction_done() @api.model def _compute_reference_prefix(self, values):