[FIX] contract: multi-company assignment notification

Steps to reproduce the problem:

1. Log in as Mitchell Admin.
2. Create contract CNT-A for company CMP-A, assigned to Marc Demo.
3. Create contract CNT-B for company CMP-B, assigned to Marc Demo.
4. Run cron to create recurring invoices.

Actual results:

- Odoo sends automated assignment emails to Marc Demo, which indicate the name of the company activated for `__system__` user whlie the cron was being executed.

Expected results after this patch:

- Odoo sends automated assignment emails to Marc Demo, which indicate the invoice company.

@Tecnativa TT24657
This commit is contained in:
Jairo Llopis
2020-07-28 10:30:40 +02:00
parent 03c444e0b5
commit 48b0aefff6
6 changed files with 31 additions and 2 deletions

View File

@@ -546,8 +546,15 @@ class ContractContract(models.Model):
if not date_ref:
date_ref = fields.Date.context_today(self)
domain = self._get_contracts_to_invoice_domain(date_ref)
contracts_to_invoice = self.search(domain)
return contracts_to_invoice._recurring_create_invoice(date_ref)
invoices = self.env["account.invoice"]
# Invoice by companies, so assignation emails get correct context
companies_to_invoice = self.read_group(domain, ["company_id"], ["company_id"])
for row in companies_to_invoice:
contracts_to_invoice = self.search(row["__domain"]).with_context(
allowed_company_ids=[row["company_id"][0]]
)
invoices |= contracts_to_invoice._recurring_create_invoice(date_ref)
return invoices
@api.multi
def action_terminate_contract(self):