Function field is not working in OpenERP

柔情痞子 提交于 2019-12-12 04:36:15

问题


In purchase.order.line I added new field pln price and changed unit price field to function:

'price_unit': fields.function(_amount_pln, string='Unit Price', required=True, digits_compute= dp.get_precision('Product Price')),
'plnprice': fields.float('PLN Price', digits_compute= dp.get_precision('PLN Price')),

Here is function:

def _amount_pln(self, cr, uid, ids, prop, arg, context=None):
    res = {}
    for line in self.browse(cr, uid, ids, context=context):
        res[line.id] = line.plnprice * 0.25
    return res

exchange value now is hardcoded, 0.25 as you see in _amount_pln function

Then I added new field in purchase.order class:

'exchange_value': fields.float('Exchange',readonly=False)

But how get this field value to my _amount_pln function I don't know. can you please help me how to resolve this problem?


回答1:


Sometimes function fields need the parameter: store=True

Try adding this parameter to your function field and see if it works.




回答2:


Try following,

def _amount_pln(self, cr, uid, ids, prop, arg, context=None):
    res = {}
    for line in self.browse(cr, uid, ids, context=context):
        res[line.id] = line.plnprice * line.order_id.exchange_value
    return res

order_id is many2one field in purchase order line in relation with purchase order, so you can easily access values of purchase order in purchase order line.




回答3:


Relation between "purchase.order" and "purchase.order.line" is "order_id". "purchase.order.line" contains "order_id". You can get values of "purchase.order" using this "order_id".

for purchase_line in self.browse(cr, uid, ids, context=context):
    res[line.id] = purchase_line.plnprice * purchase_line.order_id.exchange_value


来源:https://stackoverflow.com/questions/26973329/function-field-is-not-working-in-openerp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!