تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
10558 أدوات العرض

hello odoo community

in purchase_requstion.py file there is a function that use one2many(purchase_ids) to extract the value of connected field(purchase_ids->state)

def tender_cancel(self, cr, uid, ids, context=None):
    purchase_order_obj = self.pool.get('purchase.order')
    for purchase in self.browse(cr, uid, ids, context=context):
        for purchase_id in purchase.purchase_ids:
            if str(purchase_id.state) in('draft','wait'):
                purchase_order_obj.action_cancel(cr,uid,[purchase_id.id])
    self.write(cr, uid, ids, {'state': 'cancel', 'cancel_uid' : uid, 'cancel_date':time.strftime('%Y-%m-%d %H:%M:%S')})
    return True

I add function field and use the same function logic in line_ids field but it is not return anything, why?

def _compute_lin(self, cr, uid, ids, prop, unknow_none, context=None):
    res = {}
    for record in self.browse(cr, uid, ids, context=context):
        for rec in record.line_ids:
            if rec.product_id:
                res[rec.id] = 'yes'
            else:
                res[rec.id] = 'no'
    return res

'lin' : fields.function(_compute_lin ,string='Lin' , size=128 ,store=True ,type='char'),

oprnerp v6

الصورة الرمزية
إهمال
أفضل إجابة

In the res dictionary, it should not be the res[rec.id] but should be res[record.id]. Because rec.id will give you the ID of the o2m field which is wrong. You have to pass the ID of the current record which is record.id

 res[record.id] = 'yes'



الصورة الرمزية
إهمال
الكاتب

thanks, that's work

المنشورات ذات الصلة الردود أدوات العرض النشاط
2
أكتوبر 20
3152
1
مارس 15
4712
1
مايو 25
962
1
يناير 25
1703
2
سبتمبر 22
9428