Skip to content

Commit

Permalink
feat: overload more functions
Browse files Browse the repository at this point in the history
  • Loading branch information
victorvermot committed Nov 1, 2023
1 parent 305e73d commit c36c7f0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
9 changes: 9 additions & 0 deletions hr_holidays_validator_list/models/hr_employee.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,18 @@ class HrEmployeeBase(models.AbstractModel):
)

def create(self, values):
if ('leave_manager_ids' in values.keys()):
values['leave_manager_id'] = values['leave_manager_ids'][0][-1][-1]
res = super().create(values)
return res

def write(self, values):
if ('leave_manager_ids' in values.keys()):
values['leave_manager_id'] = values['leave_manager_ids'][0][-1][-1]
res = super().write(values)
approver_group = self.env.ref('hr_holidays.group_hr_holidays_responsible', raise_if_not_found=False)
breakpoint()
for manager_id in values['leave_manager_ids'][0][-1]:
if approver_group:
approver_group.sudo().write({'users': [(4, manager_id)]})
return res
16 changes: 13 additions & 3 deletions hr_holidays_validator_list/models/hr_leave_allocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,18 @@ class HolidaysAllocation(models.Model):
""" Allocation Requests Access specifications: similar to leave requests """
_inherit = "hr.leave.allocation"

def _get_responsible_for_approval(self):
print("Need to override it")
def activity_update(self):
for manager in self.employee_id.leave_manager_ids:
old_manager = self.employee_id.leave_manager_id
self.employee_id.leave_manager_id = manager
super().activity_update()
self.employee_id.leave_manager_id = old_manager

def _check_approval_update(self, state):
print("Need to override it")
for manager in self.employee_id.leave_manager_ids:
if manager == self.env.user:
old_manager = self.employee_id.leave_manager_id
self.employee_id.leave_manager_id = manager
super()._check_approval_update(state)
self.employee_id.leave_manager_id = old_manager
break
2 changes: 1 addition & 1 deletion hr_holidays_validator_list/views/hr_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//group[@name='managers']" position="inside">
<field name="leave_manager_ids" />
<field name="leave_manager_ids" widget="many2many_tags"/>
</xpath>
</field>
</record>
Expand Down

0 comments on commit c36c7f0

Please sign in to comment.