diff --git a/contract/README.rst b/contract/README.rst index 8dbbfda0f..80b3b2058 100644 --- a/contract/README.rst +++ b/contract/README.rst @@ -74,6 +74,7 @@ Known issues / Roadmap ====================== * Recover states and others functional fields in Contracts. +* Remove ``models/ir_ui_view.py`` in v13, where the workaround it contains is supported upstream. Bug Tracker =========== diff --git a/contract/models/__init__.py b/contract/models/__init__.py index e1b4b30cb..89a5171d1 100644 --- a/contract/models/__init__.py +++ b/contract/models/__init__.py @@ -13,3 +13,4 @@ from . import contract_tag from . import res_company from . import res_config_settings from . import contract_terminate_reason +from . import ir_ui_view diff --git a/contract/models/contract.py b/contract/models/contract.py index 0090d8c7f..1445f2f73 100644 --- a/contract/models/contract.py +++ b/contract/models/contract.py @@ -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): diff --git a/contract/models/ir_ui_view.py b/contract/models/ir_ui_view.py new file mode 100644 index 000000000..6897ad1c1 --- /dev/null +++ b/contract/models/ir_ui_view.py @@ -0,0 +1,19 @@ +# Copyright 2020 Tecnativa - Jairo Llopis +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class IrUiView(models.Model): + _inherit = "ir.ui.view" + + @api.model + def _prepare_qcontext(self): + """Patch context to use fw-compatible v13 company.""" + # TODO Delete this method in v13; it's upstream there + result = super()._prepare_qcontext() + if self.env.context.get("allowed_company_ids"): + result["res_company"] = self.env["res.company"].browse( + self.env.context["allowed_company_ids"][0] + ).sudo() + return result diff --git a/contract/readme/ROADMAP.rst b/contract/readme/ROADMAP.rst index 9fcacdf41..4420af044 100644 --- a/contract/readme/ROADMAP.rst +++ b/contract/readme/ROADMAP.rst @@ -1 +1,2 @@ * Recover states and others functional fields in Contracts. +* Remove ``models/ir_ui_view.py`` in v13, where the workaround it contains is supported upstream. diff --git a/contract/static/description/index.html b/contract/static/description/index.html index ea92b8ee2..db1637220 100644 --- a/contract/static/description/index.html +++ b/contract/static/description/index.html @@ -425,6 +425,7 @@ To use it, just select the template on the contract and fields will be filled au

Known issues / Roadmap