From 20992897eb5a3ee882356cabdabd0bebeaff74ca Mon Sep 17 00:00:00 2001 From: konykon <kon.tsagari@coopdevs.org> Date: Fri, 20 Oct 2023 17:52:21 +0200 Subject: [PATCH] Hide button assign crm coordinator if not instance company --- energy_communities/models/crm_lead.py | 12 ++++++++++++ energy_communities/views/crm_lead_views.xml | 2 ++ 2 files changed, 14 insertions(+) diff --git a/energy_communities/models/crm_lead.py b/energy_communities/models/crm_lead.py index 18cbdec27..071544ff1 100644 --- a/energy_communities/models/crm_lead.py +++ b/energy_communities/models/crm_lead.py @@ -36,6 +36,18 @@ class CrmLead(models.Model): help="Community related to this Lead", ) + is_instance_company = fields.Boolean( + string="Is instance company", compute="_is_instance_company", default=False + ) + + def _is_instance_company(self): + company = self.env.company + instance_companies = self.env["res.company"].search( + [("hierarchy_level", "=", "instance")] + ) + if company in instance_companies: + self.is_instance_company = True + def _create_map_place_proposal(self): if not self.env.user.company_id.coordinator: raise UserError( diff --git a/energy_communities/views/crm_lead_views.xml b/energy_communities/views/crm_lead_views.xml index c08851350..6368c4ab3 100644 --- a/energy_communities/views/crm_lead_views.xml +++ b/energy_communities/views/crm_lead_views.xml @@ -80,11 +80,13 @@ <field name="arch" type="xml"> <xpath expr="//sheet" position="before"> <header> + <field name="is_instance_company" invisible="1" /> <button name="action_assign_crm_to_coordinator_company" type="object" string="Assing CRM to coordinator company" groups="energy_communities.group_platform_manager" + attrs="{'invisible': [('is_instance_company', '=', False)]}" /> </header> </xpath> -- GitLab