From 6e33dea3c9837c9f4958da42b744a41bcb245800 Mon Sep 17 00:00:00 2001
From: "CGSCOP\\hsilvant" <hsilvant@scop.coop>
Date: Wed, 30 Oct 2024 09:25:57 +0100
Subject: [PATCH] =?UTF-8?q?Ajout=20d'une=20notion=20d'heures=20suppl=C3=A9?=
 =?UTF-8?q?mentaires=20(UR=20Ouest)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 models/hr_timesheet.py | 17 +++++++++++++++++
 models/res_company.py  |  5 +++++
 views/hr_timesheet.xml | 18 ++++++++++++++++++
 views/res_company.xml  |  1 +
 4 files changed, 41 insertions(+)

diff --git a/models/hr_timesheet.py b/models/hr_timesheet.py
index 54ed917..f9db0c7 100644
--- a/models/hr_timesheet.py
+++ b/models/hr_timesheet.py
@@ -72,6 +72,14 @@ class ScopHrTimesheet(models.Model):
         string="Lieu",
     )
     justificatifs = fields.Char(string="Justificatifs", required=False)
+    is_overtime = fields.Boolean(
+        string="Heures supplémentaires",
+        default=False,
+    )
+    is_overtime_allowed = fields.Boolean(
+        string="Heures supplémentaires autorisées",
+        compute="_compute_overtime_allowed",
+    )
 
     calendar_l1 = fields.Char(
         string="Ligne 1 calendrier",
@@ -85,6 +93,11 @@ class ScopHrTimesheet(models.Model):
     # ------------------------------------------------------
     # Compute Functions
     # ------------------------------------------------------
+    @api.depends("ur_id")
+    def _compute_overtime_allowed(self):
+        for rec in self:
+            rec.is_overtime_allowed = self.env.company.overtime_working
+
     @api.depends("ur_id")
     def _compute_ur_system_nb(self):
         for timesheet in self:
@@ -269,6 +282,10 @@ class ScopHrTimesheet(models.Model):
         if len(nbrc) == 0:
             custom_context['hide_regional_convention'] = True
 
+        overtime_allowed = self.env.company.overtime_working
+        if not overtime_allowed:
+            custom_context['hide_overtime'] = True
+
         res = super(ScopHrTimesheet, self.with_context(custom_context)).fields_view_get(
             view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)
 
diff --git a/models/res_company.py b/models/res_company.py
index 5bcb365..a32e41c 100644
--- a/models/res_company.py
+++ b/models/res_company.py
@@ -18,3 +18,8 @@ class ResCompanyTmesheet(models.Model):
         help="Si cette option est cochée, un employé peut imputer sans limite"
         " de temps sur une journée",
     )
+    overtime_working = fields.Boolean(
+        string="Heures supplémentaires",
+        default=False,
+        help="Si cette option est cochée, un employé peut déclarer des heures supplémentaire"
+    )
diff --git a/views/hr_timesheet.xml b/views/hr_timesheet.xml
index f7c3d80..1ddcc37 100644
--- a/views/hr_timesheet.xml
+++ b/views/hr_timesheet.xml
@@ -105,6 +105,12 @@
                         />
                         <field name="name" />
                         <field name="unit_amount" widget="float_time" />
+                        <field name="is_overtime_allowed" invisible="1" />
+                        <field
+                            name="is_overtime"
+                            widget="boolean_toggle"
+                            attrs="{'invisible': [('is_overtime_allowed', '=', False)]}"
+                        />
                     </group>
                     <group string="Divers">
                         <field name="is_present" widget="boolean_toggle" />
@@ -179,6 +185,13 @@
                         />
                         <field name="name" />
                         <field name="unit_amount" widget="float_time" />
+                        <field name="is_overtime_allowed" invisible="1" />
+                        <field
+                            name="is_overtime"
+                            widget="boolean_toggle"
+                            attrs="{'invisible': [('is_overtime_allowed', '=', False)]}"
+                        />
+
                     </group>
                     <group string="Divers">
                         <field name="is_present" widget="boolean_toggle" />
@@ -267,6 +280,11 @@
                     >{'readonly': [('state', 'in', ('submit', 'valid'))]}</attribute>
                 </field>
                 <field name="unit_amount" position="after">
+                    <field
+                        name="is_overtime"
+                        widget="boolean_toggle"
+                        invisible="context.get('hide_overtime')"
+                    />
                     <field name="ur_regional_convention_nb" invisible="1" />
                     <field name="ur_financial_system_nb" invisible="1" />
                     <field
diff --git a/views/res_company.xml b/views/res_company.xml
index ae025e9..1a42e74 100644
--- a/views/res_company.xml
+++ b/views/res_company.xml
@@ -17,6 +17,7 @@
                                     name="day_duration"
                                     attrs="{'invisible': [('day_working', '=', True)]}"
                                 />
+                                <field name="overtime_working" widget="boolean_toggle" />
                             </group>
                         </group>
                     </page>
-- 
GitLab