Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Many2One inside One2Many domain filter from Many2Many

By
Munesh Nandwani
on 5/17/16, 10:44 AM 573 views

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. 

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 5/17/16, 10:44 AM
Seen: 573 times
Last updated: 5/17/16, 11:17 AM