In workcenter I create many2many in relation between workcenter_id and employee_id. Then in work order I created One2Many with field employee_id as many2one.
many2Many in workcenter:
class mrp_workcenter(osv.osv):
_description = "Work center link with employee"
_inherit = 'mrp.workcenter'
_columns = {
'workcenter_user': fields.many2many('hr.employee','employee_workcenter_rel', 'workcenter_id', 'employee_id', 'Employee'),
}
In workorder (mrp.production.workcenter.line):
class mrp_production_workcenter_line(osv.osv):
_inherit = 'mrp.production.workcenter.line'
_columns = {
'emp_wc_ids': fields.one2many('emp.wc.line', 'workorder_id', 'Workers', copy=True),
}
class emp_wc_line(osv.osv):
_name ="emp.wc.line"
_description ="Work Order link with employee"
_employee_domains = []
def get_employee_ids(self, cr, uid, ids, context=None):
workorder_obj = self.pool.get('mrp.production.workcenter.line')
workorder = workorder_obj.browse(cr, uid, ids, context=context)
del self._employee_domains[:]
if workorder.workcenter_id.workcenter_user:
for enter in workorder.workcenter_id.workcenter_user:
self._employee_domains.append(enter.id)
_columns = {
'employee_id' : fields.many2one('hr.employee', 'Name', domain=[('id', 'in', _employee_domains)], ondelete='restrict', select=True),
}
When I select the employee_id it doesn't show any data. It didn't manage to get any employee that I declare inside the Many2Many in Workcenter.