Hello everyone, kindda lost for my odoo adventure and i need a help. I have a class named "planned.bom", some of it's columns are product_id (many2one on product), project_id (many2one on project). This is where i stuck, in my purchase requisition, when i add purchase requisition lines, i want to show only those products which are under planned.bom and base on project.
Here is the image i want to tell:
Any help is much appreciated.
-------------------------------------------------------------------------
In purchase.requisition i add fields.function;
'product_ids_to_chose_from' : fields.function(_get_assigned_bom, type='many2many', method=True,store=False, multi='compute_assigned_bomproduct', string='Assigned BOM product')
and the functions looks lik this:
def _get_assigned_bom(self,cr,uid,ids,context=None):
vals = {}
pr_id = None
for rec in self.browse(cr, uid, ids, context=context):
pr_id = self.pool.get('project.project').search(cr,uid,[('id','=',rec.project_id.id)])
for project in self.pool.get('project.project').browse(cr,uid,pr_id,context=context):
p_bom_ids = self.pool.get('planned.bom').search(cr,uid,[('project_id','=',project.id)])
for bom in self.pool.get('planned.bom').browse(cr,uid,p_bom_ids,context=context):
pr_id = bom.product_id.id
vals[rec.id] = {'product_ids_to_chose_from':pr_id}
return vals
on purchase.requisition.line i add this one:
'product_ids_to_chose_from': fields.related('requisition_id', 'product_ids_to_chose_from', type='many2many', string='Assigned BOM product'),
and on my form here how create the domain:
<page string="Products" attrs="{'invisible':[('state','=','new')]}">
<field name="line_ids" context="{'requisition_id': active_id}" attrs="{'readonly':[('state','not in','add_product')]}">
<tree string="Products" editable="bottom">
<field name="product_id" required="True"
on_change="onchange_product_id_limit(product_id,product_uom_id,product_qty,context)"
domain="[('is_bom','=',True),('ids','in',product_ids_to_chose_from[0][2])]" />
upon clicking on a product i recieve this client error:
Uncaught Error: NameError: name 'product_ids_to_chose_from' is not defined
i don't know what it cause.
****************** EDIT
def _get_assigned_bom(self, cr, uid, ids, name, arg, context=None):
vals = {}
pr_id = []
for rec in self.browse(cr, uid, ids, context=context):
id = rec.id
vals[id] = []
if rec.project_id:
p_bom_ids = self.pool.get('planned.bom').search(cr,uid,[('project_id','=',rec.project_id.id)])
for bom in self.pool.get('planned.bom').browse(cr,uid,p_bom_ids,context=context):
pr_id = bom.product_id
vals[id] = [(6, 0, [x.id for x in pr_id])]
return vals