[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).
This commit is contained in:
Pedro M. Baeza
2020-01-08 17:18:28 +01:00
committed by Christopher Rogos
parent d1e7dde56e
commit abf30c16b4
4 changed files with 25 additions and 19 deletions

View File

@@ -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