From 3e387c0b0165774617db0cc7e15671aac723c344 Mon Sep 17 00:00:00 2001
From: jordan <jordan@le-filament.com>
Date: Tue, 19 Jan 2021 16:51:22 +0100
Subject: [PATCH] [add] add multi_compnay_menu

---
 __manifest__.py               |  3 ++-
 models/res_config_settings.py | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/__manifest__.py b/__manifest__.py
index f384c80..383dc02 100755
--- a/__manifest__.py
+++ b/__manifest__.py
@@ -9,9 +9,10 @@
     "installable": True,
     "depends": [
         "account",
+        "account_banking_sepa_direct_debit",
         "cgscop_liste_ministere",
         "cgscop_partner",
-        "account_banking_sepa_direct_debit",
+        "multi_company_menu",
     ],
     "data": [
         "security/ir.model.access.csv",
diff --git a/models/res_config_settings.py b/models/res_config_settings.py
index 3cf5a4a..78f240d 100644
--- a/models/res_config_settings.py
+++ b/models/res_config_settings.py
@@ -17,3 +17,36 @@ class CotisationsConfigSettings(models.TransientModel):
         readonly=False,
         string='Journal des cotisations',
         domain="[('type', '=', 'sale')]")
+
+    def add_company_to_menu(self, menu, bool_condition):
+        """
+        Add current company to the list of companies allowed to see menu
+        :param menu: target menu
+        :param bool_condition: condition to check to allow company or not
+        :return: add company to menu
+        """
+        current_company_id = self.env.user.company_id
+        if bool_condition:
+            if current_company_id not in menu.company_ids:
+                menu.write({
+                    "company_ids": [(4, current_company_id.id)]
+                })
+        else:
+            if current_company_id in menu.company_ids:
+                menu.write({
+                    "company_ids": [(3, current_company_id.id)]
+                })
+
+    def execute(self):
+        """
+        Rewrite execute() function to add current company to the list
+        of available company in ir_ui_menu
+        """
+        res = super(CotisationsConfigSettings, self).execute()
+
+        menu_cotiz = self.env.ref(
+            'cgscop_cotisation.menu_scop_cotisation')
+        bool_condition = self.is_contribution
+
+        self.add_company_to_menu(menu_cotiz, bool_condition)
+        return res
-- 
GitLab