diff --git a/energy_communities/__manifest__.py b/energy_communities/__manifest__.py index 18c1e21dcd9f850b8e7ec2b23fc771e3bcc291fe..118b55ed88e4da1095a9a187e681e0caa3bf6986 100644 --- a/energy_communities/__manifest__.py +++ b/energy_communities/__manifest__.py @@ -1,6 +1,6 @@ { "name": "Energy Community", - "version": "16.0.0.2.1", + "version": "16.0.0.2.2", "depends": [ "account", "account_banking_mandate", diff --git a/energy_communities/utils.py b/energy_communities/utils.py index f430ddd23f62d4d98ca1eb1ead15e619eb15e9da..fda66fed4ba01577486e223455ee33afdeac9f1b 100644 --- a/energy_communities/utils.py +++ b/energy_communities/utils.py @@ -6,6 +6,7 @@ from odoo.tools.translate import code_translations from odoo.addons.component.core import Component, WorkContext from odoo.addons.contract.models.contract import ContractContract +from odoo.addons.sale.models.sale_order import SaleOrder def _get_component( @@ -34,8 +35,9 @@ def contract_utils( @contextmanager def sale_order_utils( env: Environment, + sale_order_id: SaleOrder = None, ) -> Component: - yield _get_component(env, "sale.order", "sale.order.utils") + yield _get_component(env, "sale.order", "sale.order.utils", sale_order_id) def get_translation(source, lang, mods): diff --git a/energy_communities_cooperator/__manifest__.py b/energy_communities_cooperator/__manifest__.py index b6b2a5f58e6d0963cab08681432a8e73f22067d0..35367bca1633f590c633d2ba61c92c08160b5136 100644 --- a/energy_communities_cooperator/__manifest__.py +++ b/energy_communities_cooperator/__manifest__.py @@ -12,7 +12,7 @@ # Check https://github.com/odoo/odoo/blob/14.0/odoo/addons/base/data/ir_module_category_data.xml # for the full list "category": "Cooperative management", - "version": "16.0.0.1.8", + "version": "16.0.0.1.9", "license": "AGPL-3", # any module necessary for this one to work correctly "depends": [ diff --git a/energy_communities_crm/__manifest__.py b/energy_communities_crm/__manifest__.py index 1dee8ef87e585a33d9d5fb22f80094d51a1357e0..57454cacbe13f8c854ca884db7dea758a21aea0c 100644 --- a/energy_communities_crm/__manifest__.py +++ b/energy_communities_crm/__manifest__.py @@ -12,7 +12,7 @@ # Check https://github.com/odoo/odoo/blob/14.0/odoo/addons/base/data/ir_module_category_data.xml # for the full list "category": "Sales/CRM", - "version": "16.0.0.1.4", + "version": "16.0.0.1.5", "license": "AGPL-3", # any module necessary for this one to work correctly "depends": [ diff --git a/energy_communities_service_invoicing/__manifest__.py b/energy_communities_service_invoicing/__manifest__.py index 6cb1f667b4d750ed34bfcd90fb4ad7116bea9f48..0133e4e504e5366e6cce03ca64f3e1b25cc90c21 100644 --- a/energy_communities_service_invoicing/__manifest__.py +++ b/energy_communities_service_invoicing/__manifest__.py @@ -9,7 +9,7 @@ "author": "Som comunitats", "website": "https://coopdevs.org", "category": "Contract Management", - "version": "16.0.0.1.1", + "version": "16.0.0.1.2", # any module necessary for this one to work correctly "depends": [ "base", diff --git a/energy_communities_service_invoicing/components/contract_utils.py b/energy_communities_service_invoicing/components/contract_utils.py index 181c635081eda5cd5733d92fd510195398db7cc2..cc5e994ba7ae4d1ec613a2228c3fdf09e0b1b1cb 100644 --- a/energy_communities_service_invoicing/components/contract_utils.py +++ b/energy_communities_service_invoicing/components/contract_utils.py @@ -154,7 +154,7 @@ class ContractUtils(Component): ): executed_action_description_list = executed_action_description.split(",") return { - "company_id": self.work.record.partner_id.related_company_id, + "partner_id": self.work.record.partner_id, "pack_id": pack_id if "modify_pack" in executed_action_description_list else self.work.record.pack_id, diff --git a/energy_communities_service_invoicing/components/sale_order_utils.py b/energy_communities_service_invoicing/components/sale_order_utils.py index 460a084b1604a3e76e5f84ca8d7d6c6946f6a078..49be821ce542454f2a593ff98e2210eec2615596 100644 --- a/energy_communities_service_invoicing/components/sale_order_utils.py +++ b/energy_communities_service_invoicing/components/sale_order_utils.py @@ -1,13 +1,14 @@ +from odoo.exceptions import MissingError + from odoo.addons.component.core import Component -from odoo.addons.energy_communities.utils import contract_utils class SaleOrderUtils(Component): _inherit = "sale.order.utils" - def _create_service_invoicing_sale_order( + def create_service_invoicing_sale_order( self, - company_id, + partner_id, pack_id, pricelist_id, payment_mode_id, @@ -17,7 +18,7 @@ class SaleOrderUtils(Component): metadata, ): so_creation_dict = { - "partner_id": company_id.partner_id.id, + "partner_id": partner_id.id, "company_id": self.env.company.id, "commitment_date": start_date, "pricelist_id": pricelist_id.id, @@ -53,11 +54,11 @@ class SaleOrderUtils(Component): # Trigger name computattion in oder to include product's description_sale for order_line in sale_order.order_line: order_line._compute_name() - return sale_order + self.work.record = sale_order def create_service_invoicing_initial( self, - company_id, + partner_id, pack_id, pricelist_id, start_date, @@ -66,8 +67,8 @@ class SaleOrderUtils(Component): payment_mode_id=False, metadata=False, ): - so = self._create_service_invoicing_sale_order( - company_id, + self.create_service_invoicing_sale_order( + partner_id, pack_id, pricelist_id, payment_mode_id, @@ -76,19 +77,23 @@ class SaleOrderUtils(Component): executed_action_description, metadata, ) - so.action_confirm() - service_invoicing_id = self._get_related_contracts(so) - # TODO: We must call contract_utils with a better component and workcontext modification approach - with contract_utils(self.env, service_invoicing_id) as component: - component.setup_initial_data() - component.clean_non_service_lines() - if service_invoicing_id.is_free_pack: - component.set_contract_status_active(start_date) - return service_invoicing_id + return self.confirm() - def _get_related_contracts(self, sale_order): - return ( - self.env["contract.line"] - .search([("sale_order_line_id", "in", sale_order.order_line.ids)]) - .mapped("contract_id") - ) + def confirm(self): + if not self.work.record: + raise MissingError( + _("Sale order must be defined in order to confirm it on component") + ) + self.work.record.action_confirm() + with self.collection.work_on( + "contract.contract", record=self.work.record.service_invoicing_id + ) as work: + contract_utils = work.component("contract.utils") + contract_utils.setup_initial_data() + contract_utils.clean_non_service_lines() + # TODO: Decide if this must be by design + if contract_utils.work.record.is_free_pack: + contract_utils.set_contract_status_active( + self.work.record.commitment_date + ) + return contract_utils.work.record diff --git a/energy_communities_service_invoicing/models/sale_order.py b/energy_communities_service_invoicing/models/sale_order.py index 67447ae360d39467c8dbeb78a84cfe83e9215a16..8d369052290756c9dd0b7dc0b9558f70875c295d 100644 --- a/energy_communities_service_invoicing/models/sale_order.py +++ b/energy_communities_service_invoicing/models/sale_order.py @@ -17,6 +17,21 @@ class SaleOrder(models.Model): string="Service invoicing action description", default="none", ) + service_invoicing_id = fields.Many2one( + "contract.contract", + string="Related contract", + compute="_compute_service_invoicing_id", + store=False, + ) + + def _compute_service_invoicing_id(self): + for record in self: + record.service_invoicing_id = False + contract = self.env["contract.contract"].search( + [("sale_order_id", "=", self.id)], limit=1 + ) + if contract: + record.service_invoicing_id = contract.id def action_create_contract(self): contracts = super().action_create_contract() @@ -32,18 +47,13 @@ class SaleOrder(models.Model): def action_show_contracts(self): self.ensure_one() - action = self.env["ir.actions.act_window"]._for_xml_id( - "contract.action_customer_contract" - ) - - contracts = self.env["contract.contract"].search( - [("sale_order_id", "=", self.id)] - ) - if len(contracts) == 1: - # If there is only one contract, open it directly + if self.service_invoicing_id: + action = self.env["ir.actions.act_window"]._for_xml_id( + "contract.action_customer_contract" + ) action.update( { - "res_id": contracts.id, + "res_id": self.service_invoicing_id.id, "view_mode": "form", "views": filter(lambda view: view[1] == "form", action["views"]), } diff --git a/energy_communities_service_invoicing/wizards/service_invoicing_action_create.py b/energy_communities_service_invoicing/wizards/service_invoicing_action_create.py index d0c8030473b1bd5e63b70c0a661beb9f56002230..50c9be4906554d3ff62cde6fbe1c7adf53b4fc8b 100644 --- a/energy_communities_service_invoicing/wizards/service_invoicing_action_create.py +++ b/energy_communities_service_invoicing/wizards/service_invoicing_action_create.py @@ -130,7 +130,7 @@ class ServiceInvoicingActionCreateWizard(models.TransientModel): with sale_order_utils(self.env) as component: # TODO: pass community_company_id as metadata service_invoicing_id = component.create_service_invoicing_initial( - company_id, + company_id.partner_id, self.platform_pack_id, self.pricelist_id, self.execution_date, diff --git a/energy_selfconsumption/__manifest__.py b/energy_selfconsumption/__manifest__.py index c5b55063775a6fa0676f9126ac85f10869fa0b1c..39544c56cd9b5d2e14fa2473e4b875f39877bb59 100644 --- a/energy_selfconsumption/__manifest__.py +++ b/energy_selfconsumption/__manifest__.py @@ -9,7 +9,7 @@ "author": "Coopdevs Treball SCCL & Som Energia SCCL", "website": "https://coopdevs.org", "category": "Customizations", - "version": "16.0.0.2.0", + "version": "16.0.0.2.1", "license": "AGPL-3", "depends": [ "base", diff --git a/setup/energy_communities_crm/setup.py b/setup/energy_communities_crm/setup.py index 28c57bb640316187aaa53975c0d5c36ee4886195..27d506ebfdc85d588629b4120af486b42a142f20 100644 --- a/setup/energy_communities_crm/setup.py +++ b/setup/energy_communities_crm/setup.py @@ -1,6 +1,7 @@ import setuptools setuptools.setup( + name="odoo_addon_energy_communities_crm", setup_requires=['setuptools-odoo'], odoo_addon=True, )