diff --git a/models/hr_timesheet.py b/models/hr_timesheet.py index 86b7cd2dab9f41cf727b2daeebdff688e3906e5e..4d4030543b637261a4a46a8d7748295d5d370f55 100644 --- a/models/hr_timesheet.py +++ b/models/hr_timesheet.py @@ -253,3 +253,23 @@ class ScopHrTimesheet(models.Model): "default_name": self[0].name if len(self) == 1 else "", }, } + + # ------------------------------------------------------ + # Modification du context pour cacher les colonnes + # ------------------------------------------------------ + @api.model + def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): + custom_context = self.env.context.copy() + + current_ur_id = self.env.context['current_ur_id'] + nbfs = self.env["ur.financial.system"].search([("ur_id", "=", current_ur_id)]) + if len(nbfs) == 0: + custom_context['hide_financial_system'] = True + nbrc = self.env["ur.regional.convention"].search([("ur_id", "=", current_ur_id)]) + if len(nbrc) == 0: + custom_context['hide_regional_convention'] = True + + res = super(ScopHrTimesheet, self.with_context(custom_context)).fields_view_get( + view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu) + + return res diff --git a/views/hr_timesheet.xml b/views/hr_timesheet.xml index c10abab945277cc3af576dcb871516c8924858f2..f7c3d80bb7fa20d37f365c258487e0c9d7527fd9 100644 --- a/views/hr_timesheet.xml +++ b/views/hr_timesheet.xml @@ -272,12 +272,14 @@ <field name="ur_financial_system_id" options="{'no_open': True, 'no_create': True}" - attrs="{'required': [('ur_financial_system_nb', '>', 0)], 'invisible': [('ur_financial_system_nb', '<', 1)], 'readonly': [('state', 'in', ('submit', 'valid'))]}" + invisible="context.get('hide_financial_system')" + attrs="{'required': [('ur_financial_system_nb', '>', 0)], 'readonly': [('state', 'in', ('submit', 'valid'))]}" /> <field name="ur_regional_convention_id" options="{'no_open': True, 'no_create': True}" - attrs="{'required':[('ur_regional_convention_nb', '>', 0)], 'invisible':[('ur_regional_convention_nb', '<', 1)], 'readonly': [('state', 'in', ('submit', 'valid'))]}" + invisible="context.get('hide_regional_convention')" + attrs="{'required':[('ur_regional_convention_nb', '>', 0)], 'readonly': [('state', 'in', ('submit', 'valid'))]}" /> <field name="justificatifs"