[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 Francisco Ivan Anton Prieto
parent d39629a1ef
commit 46b8715806
4 changed files with 25 additions and 19 deletions

View File

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