我写了一个继承了[[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。请有人帮助我。
@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
self.amount_untaxed
,否则super
的值将不可用。 @api.model
def create(self,vals):
res = super(PurchaseOrderInherit,self).create(vals)
print(vals['test_value'])
return res
如果test_value
字段是计算字段,则不必覆盖create
和write
方法中的值,而只需覆盖与计算相同的方法amount_untaxed
值。