From 46b8715806476dad22812c46df66e5b373960c09 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Wed, 8 Jan 2020 17:18:28 +0100 Subject: [PATCH] [FIX] contract: Handle properly multi-company setups If you have contracts in several companies, cron will create all of them, but property fields will be populated with incorrect data as the taken company is the main from the cron user (usually admin). --- contract/__manifest__.py | 2 +- contract/i18n/contract.pot | 30 +++++++++++++++--------------- contract/models/contract.py | 8 ++++++-- contract/models/contract_line.py | 4 +++- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/contract/__manifest__.py b/contract/__manifest__.py index 7bbf37036..ab25f8812 100644 --- a/contract/__manifest__.py +++ b/contract/__manifest__.py @@ -9,7 +9,7 @@ { 'name': 'Recurring - Contracts Management', - 'version': '12.0.5.1.3', + 'version': '12.0.5.2.0', 'category': 'Contract Management', 'license': 'AGPL-3', 'author': "OpenERP SA, " diff --git a/contract/i18n/contract.pot b/contract/i18n/contract.pot index 5c2cd098e..63e41afc7 100644 --- a/contract/i18n/contract.pot +++ b/contract/i18n/contract.pot @@ -256,7 +256,7 @@ msgid "Cancel allowed?" msgstr "" #. module: contract -#: code:addons/contract/models/contract_line.py:1054 +#: code:addons/contract/models/contract_line.py:1056 #, python-format msgid "Cancel not allowed for this line" msgstr "" @@ -305,7 +305,7 @@ msgid "Company" msgstr "" #. module: contract -#: code:addons/contract/models/contract.py:318 +#: code:addons/contract/models/contract.py:321 #, python-format msgid "Compose Email" msgstr "" @@ -398,7 +398,7 @@ msgid "Contract line '%s' start date can't be later than end date" msgstr "" #. module: contract -#: code:addons/contract/models/contract_line.py:1083 +#: code:addons/contract/models/contract_line.py:1085 #, python-format msgid "Contract line Un-canceled: %s
- " msgstr "" @@ -416,13 +416,13 @@ msgid "Contract line and its successor overlapped" msgstr "" #. module: contract -#: code:addons/contract/models/contract_line.py:1062 +#: code:addons/contract/models/contract_line.py:1064 #, python-format msgid "Contract line canceled: %s
- " msgstr "" #. module: contract -#: code:addons/contract/models/contract_line.py:854 +#: code:addons/contract/models/contract_line.py:856 #, python-format msgid "Contract line for {product}\n" " stopped:
\n" @@ -431,7 +431,7 @@ msgid "Contract line for {product}\n" msgstr "" #. module: contract -#: code:addons/contract/models/contract_line.py:934 +#: code:addons/contract/models/contract_line.py:936 #, python-format msgid "Contract line for {product}\n" " planned a successor:
\n" @@ -442,7 +442,7 @@ msgid "Contract line for {product}\n" msgstr "" #. module: contract -#: code:addons/contract/models/contract_line.py:1230 +#: code:addons/contract/models/contract_line.py:1232 #, python-format msgid "Contract line for {product}\n" " renewed:
\n" @@ -453,7 +453,7 @@ msgid "Contract line for {product}\n" msgstr "" #. module: contract -#: code:addons/contract/models/contract_line.py:1042 +#: code:addons/contract/models/contract_line.py:1044 #, python-format msgid "Contract line for {product}\n" " suspended:
\n" @@ -464,7 +464,7 @@ msgid "Contract line for {product}\n" msgstr "" #. module: contract -#: code:addons/contract/models/contract_line.py:1280 +#: code:addons/contract/models/contract_line.py:1282 #, python-format msgid "Contract line must be canceled before delete" msgstr "" @@ -986,7 +986,7 @@ msgid "Plan successor allowed?" msgstr "" #. module: contract -#: code:addons/contract/models/contract_line.py:917 +#: code:addons/contract/models/contract_line.py:919 #, python-format msgid "Plan successor not allowed for this line" msgstr "" @@ -997,7 +997,7 @@ msgid "Planned" msgstr "" #. module: contract -#: code:addons/contract/models/contract.py:273 +#: code:addons/contract/models/contract.py:274 #, python-format msgid "Please define a %s journal for the company '%s'." msgstr "" @@ -1208,7 +1208,7 @@ msgid "Stop allowed?" msgstr "" #. module: contract -#: code:addons/contract/models/contract_line.py:837 +#: code:addons/contract/models/contract_line.py:839 #, python-format msgid "Stop not allowed for this line" msgstr "" @@ -1219,7 +1219,7 @@ msgid "Stop/Plan successor allowed?" msgstr "" #. module: contract -#: code:addons/contract/models/contract_line.py:978 +#: code:addons/contract/models/contract_line.py:980 #, python-format msgid "Stop/Plan successor not allowed for this line" msgstr "" @@ -1311,7 +1311,7 @@ msgid "Un-cancel" msgstr "" #. module: contract -#: code:addons/contract/models/contract_line.py:1075 +#: code:addons/contract/models/contract_line.py:1077 #, python-format msgid "Un-cancel not allowed for this line" msgstr "" @@ -1402,7 +1402,7 @@ msgid "Year(s)" msgstr "" #. module: contract -#: code:addons/contract/models/contract_line.py:787 +#: code:addons/contract/models/contract_line.py:789 #, python-format msgid "You can't delay a contract line invoiced at least one time." msgstr "" diff --git a/contract/models/contract.py b/contract/models/contract.py index 1670cefea..caa289fa5 100644 --- a/contract/models/contract.py +++ b/contract/models/contract.py @@ -283,7 +283,9 @@ class ContractContract(models.Model): invoice_type = 'out_invoice' if self.contract_type == 'purchase': invoice_type = 'in_invoice' - vinvoice = self.env['account.invoice'].new({ + vinvoice = self.env['account.invoice'].with_context( + force_company=self.company_id.id, + ).new({ 'partner_id': self.invoice_partner_id.id, 'type': invoice_type, }) @@ -345,7 +347,9 @@ class ContractContract(models.Model): # taken from the invoice's journal in _onchange_product_id # This code is not in finalize_creation_from_contract because it's # not possible to create an invoice line with no account - new_invoice = self.env['account.invoice'].new(invoice_values) + new_invoice = self.env['account.invoice'].with_context( + force_company=invoice_values['company_id'], + ).new(invoice_values) for invoice_line in new_invoice.invoice_line_ids: name = invoice_line.name account_analytic_id = invoice_line.account_analytic_id diff --git a/contract/models/contract_line.py b/contract/models/contract_line.py index 7aeeca188..8969f881b 100644 --- a/contract/models/contract_line.py +++ b/contract/models/contract_line.py @@ -658,7 +658,9 @@ class ContractLine(models.Model): } if invoice_id: invoice_line_vals['invoice_id'] = invoice_id.id - invoice_line = self.env['account.invoice.line'].new(invoice_line_vals) + invoice_line = self.env['account.invoice.line'].with_context( + force_company=self.contract_id.company_id.id, + ).new(invoice_line_vals) # Get other invoice line values from product onchange invoice_line._onchange_product_id() invoice_line_vals = invoice_line._convert_to_write(invoice_line._cache)