This question has been flagged
2 Replies
2373 Views

hello odoo community

I want fill field True if I have one product of category = 18 else fill field False 

and my question is :

if I have several purchase requisition line ,how  can I search in all lines and see if I have product of categ 18 or not ?

openerp v6.1

Avatar
Discard
Best Answer

You can use search method in in purchase requisition line.

po_req_line_obj = self.pool.get('purchase.requisition')
po_req_line_ids = depreciation_lin_obj.search(cr, uid, [])

for pr_line in po_req_line_obj.browse(po_req_line_ids):

if pr_line.product_id.categ_id==18:

#write your logic

else:

#write your logic

Avatar
Discard
Author Best Answer

I solve my problem like this:

def _compute_m(self, cr, uid, ids, prop, unknow_none, context=None):
    res = {}
    Lid=[]
    for record in self.browse(cr, uid, ids, context=context):
        for rec in record.line_ids:
            Lid.append(rec.categ.id)
        if 18 in Lid:
            res[record.id] = True
        else:
            res[record.id] = False
    return res

'x_m' : fields.function(_compute_m,string='m',store=True ,type='boolean'),

Avatar
Discard