Hey guys,
I want to ask you how your module sends it's data to odoo?
Background:
I wrote a module that keeps employee_ids (ressources) and user_id (assigned to) on the task level in sync.
Works fine on kanban. When you assign a task to users the emplyee_ids are set, too, and vice versa.
However, selecting ressources on the gantt does not trigger the writing of the user_ids.
I implemented this as an extension off the write-function.
Here is my code:
# sync user_id and employee_id
if 'employee_ids' in vals or 'user_ids' in vals or 'resource_id' in vals:
for task in self:
# Start with current values
current_user_ids = set(task.user_ids.ids)
current_employee_ids = set(task.employee_ids.ids)
user_write = 'user_ids' in vals
emp_write = 'employee_ids' in vals
ressource_write = 'ressource_id' in vals
# Both fields need syncing only if one is changed
if user_write:
new_user_ids = self._resolve_m2m_command(current_user_ids, vals['user_ids'])
if not new_user_ids:
new_employee_ids = set()
else:
new_employee_ids = set(self.env['res.users'].browse(new_user_ids).mapped('employee_ids').ids)
elif emp_write or ressource_write:
new_employee_ids = self._resolve_m2m_command(current_employee_ids, vals['employee_ids'])
if not new_employee_ids:
new_user_ids = set()
else:
new_user_ids = set(self.env['hr.employee'].browse(new_employee_ids).mapped('user_id').ids)
else:
continue # nothing to sync
vals['user_ids'] = [(6, 0, list(new_user_ids))]
vals['employee_ids'] = [(6, 0, list(new_employee_ids))]
Do you have a suggestion why this might not be triggered by the gantt?
Cheers
caalb