I have write a class that inherit of purchase.order,so i want to get the value of the "amount_untaxed" which is a computed field. I have try this code :
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)
But the Print function return 0.0. Please someone helps me.
The computed field are computed in the create call, if you want to get the value:
@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