odoo获取继承模型的计算字段

问题描述 投票:1回答:2

我写了一个继承了[[purchase.order的类,所以我想获取“ amount_untaxed”的值,它是一个计算字段。我尝试过此代码:

class PurchaseOrderInherit(models.Model): _inherit='purchase.order' test_value=fields.Float(string='test value') @api.model def create(self,vals): vals['test_value']=self.amount_untaxed print(vals['test_value']) return super(PurchaseOrderInherit,self).create(vals)
但是打印功能返回0.0。请有人帮助我。
inheritance field odoo
2个回答
0
投票
如果要获取值,则在create调用中计算计算字段:

@api.model def create(self,vals): # create returns the newly created record rec = super(PurchaseOrderInherit,self).create(vals) print(rec.amount_untaxed) # if you want to set the value just do this rec.test_value = rec.amount_untaxed # this will trigger write call to update the field in database return rec


0
投票
计算字段是即时计算的。除非您调用self.amount_untaxed,否则super的值将不可用。

@api.model def create(self,vals): res = super(PurchaseOrderInherit,self).create(vals) print(vals['test_value']) return res

如果test_value字段是计算字段,则不必覆盖createwrite方法中的值,而只需覆盖与计算相同的方法amount_untaxed值。
© www.soinside.com 2019 - 2024. All rights reserved.