From 95ef0c8ad056d825e93ff3a992a2fc3aaab874fa Mon Sep 17 00:00:00 2001
From: benjamin <benjamin@le-filament.com>
Date: Mon, 8 Jul 2024 13:06:59 +0200
Subject: [PATCH] [UPD] add compute admin user for partner staff view

---
 datas/union_regionale_data.xml |  4 ++--
 models/scop_partner_staff.py   | 10 +++++++++-
 views/scop_partner_staff.xml   |  9 +++++----
 3 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/datas/union_regionale_data.xml b/datas/union_regionale_data.xml
index bd5100c..86ec1e7 100644
--- a/datas/union_regionale_data.xml
+++ b/datas/union_regionale_data.xml
@@ -88,8 +88,8 @@
         <record id="ur_dom_tom" model="union.regionale">
             <field
                 name="long_name"
-            >UNION REGIONALE DOM TOM</field>
-            <field name="name">DOM-TOM</field>
+            >PROGRAMME OUTRE MER</field>
+            <field name="name">POM</field>
         </record>
     </data>
 </odoo>
diff --git a/models/scop_partner_staff.py b/models/scop_partner_staff.py
index 7441aa9..10850e0 100644
--- a/models/scop_partner_staff.py
+++ b/models/scop_partner_staff.py
@@ -91,9 +91,12 @@ class ScopPartnerStaff(models.Model):
     staff_women = fields.Integer("Eff. salariés femmes")
     staff_shareholder_men = fields.Integer("Sociétaires salariés hommes")
     staff_shareholder_women = fields.Integer("Sociétaires salariés femmes")
-
     comment = fields.Char("Commentaire")
 
+    is_admin_user = fields.Boolean(
+        compute="_compute_is_admin_user",
+    )
+
     # ------------------------------------------------------
     # Compute
     # ------------------------------------------------------
@@ -115,6 +118,11 @@ class ScopPartnerStaff(models.Model):
             else:
                 r.is_partner_in_tracked_naf = False
 
+    def _compute_is_admin_user(self):
+        self.is_admin_user = (
+            self.env.user.has_group("cgscop_partner.group_cg_administrative") or False
+        )
+
     # ------------------------------------------------------
     # OnChange
     # ------------------------------------------------------
diff --git a/views/scop_partner_staff.xml b/views/scop_partner_staff.xml
index 02cffd8..3c79bf5 100644
--- a/views/scop_partner_staff.xml
+++ b/views/scop_partner_staff.xml
@@ -31,21 +31,22 @@
                             <group name="staff_stats">
                                 <field name="cooperative_form_id" invisible="1" />
                                 <field name="is_partner_in_tracked_naf" invisible="1" />
+                                <field name="is_admin_user" invisible="1" />
                                 <field
                                     name="staff_count"
-                                    attrs="{'readonly':[('type_entry','in',('questionnaire', 'questionnaire_inscription', 'membership'))]}"
+                                    attrs="{'readonly':[('type_entry','in',('questionnaire', 'questionnaire_inscription', 'membership')), ('is_admin_user', '!=', True)]}"
                                 />
                                 <field
                                     name="staff_shareholder_count"
-                                    attrs="{'readonly':[('type_entry','in',('questionnaire', 'questionnaire_inscription', 'membership'))]}"
+                                    attrs="{'readonly':[('type_entry','in',('questionnaire', 'questionnaire_inscription', 'membership')), ('is_admin_user', '!=', True)]}"
                                 />
                                 <field
                                     name="staff_shareholder_total"
-                                    attrs="{'readonly':[('type_entry','in',('questionnaire', 'questionnaire_inscription', 'membership'))]}"
+                                    attrs="{'readonly':[('type_entry','in',('questionnaire', 'questionnaire_inscription', 'membership')), ('is_admin_user', '!=', True)]}"
                                 />
                                 <field
                                     name="staff_average"
-                                    attrs="{'readonly':[('type_entry','in',('questionnaire', 'questionnaire_inscription', 'membership'))], 'required':[('is_partner_in_tracked_naf', '=', True)]}"
+                                    attrs="{'readonly':[('type_entry','in',('questionnaire', 'questionnaire_inscription', 'membership')), ('is_admin_user', '!=', True)], 'required':[('is_partner_in_tracked_naf', '=', True)]}"
                                 />
                             </group>
                             <group name="staff_stats">
-- 
GitLab