From 5bd8f97fa2fd572614f321a747b3cac140bb8a1d Mon Sep 17 00:00:00 2001 From: Damien Bouvy Date: Wed, 11 Jan 2017 11:59:29 +0100 Subject: [PATCH] [FIX] website_portal_sale: use correct company for invoice creation Invoices created automatically by the payment acquirer must use the correct accounts/journals, which may not always be the case if not explicitly set in the context. --- addons/website_portal_sale/models/payment.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/addons/website_portal_sale/models/payment.py b/addons/website_portal_sale/models/payment.py index 3b77d74b51e..243b3a52f27 100644 --- a/addons/website_portal_sale/models/payment.py +++ b/addons/website_portal_sale/models/payment.py @@ -15,8 +15,13 @@ class PaymentTransaction(models.Model): def _generate_and_pay_invoice(self, tx, acquirer_name): tx.sale_order_id._force_lines_to_invoice_policy_order() - created_invoice = tx.sale_order_id.action_invoice_create() - created_invoice = self.env['account.invoice'].browse(created_invoice) + # force company to ensure journals/accounts etc. are correct + # company_id needed for default_get on account.journal + # force_company needed for company_dependent fields + ctx_company = {'company_id': tx.sale_order_id.company_id.id, + 'force_company': tx.sale_order_id.company_id.id} + created_invoice = tx.sale_order_id.with_context(**ctx_company).action_invoice_create() + created_invoice = self.env['account.invoice'].browse(created_invoice).with_context(**ctx_company) if created_invoice: _logger.info('<%s> transaction completed, auto-generated invoice %s (ID %s) for %s (ID %s)',