Skip to Content
मेन्यू
This question has been flagged
3 Replies
2153 Views

I have a model in Odoo where I want to create a calculated field called x_studio_test, and I want to set its value to 234 for all records (just in order to keep it simple and see if that work). Following the Odoo documentation, I tried the following code in the model:

for record in self:
        record['size'] = len(record.name)

converted into:

for record in self:
        record['x_studio_test'] = 234

But that does not work, the field appear as "0,00"

It is a float number and in "Dependences" -> x_studio_test



Why is not working? thank you

Avatar
Discard
Best Answer

Hi,
You don't need to keep the same field in the dependency list, just remove the x_studio_test field from dependency list and see if it makes any diff.

See:  How To Add Compute Field From User Interface In Odoo



Thanks

Avatar
Discard
Best Answer

Hi 
Yoo can try this it will fill the field by default and you can change it after as you want :

@api.model

def default_get(self, fields):

res = super(YourModule, self).default_get(fields)

if 'x_studio_test' in fields and not res.get('x_studio_test'):

     res['x_studio_test'] = 234


 return res

Avatar
Discard
Best Answer

Hi,

You can try this code,
Once you return the value in dictionary format you can fetch the record like record['filed_name']
or you try with the normal method and only need to use record.field_nameie:

for record in self:
        record.x_studio_test = 234

If the record does not return the value like dictionary you can follow the above code.

Another solution is you do not use the studio, and if you make it as a default value, tryfied_name  = fields.Float(string='Field name' , default=234)


Hope it helps

Avatar
Discard
Related Posts Replies Views Activity
2
अग॰ 24
2290
0
अग॰ 23
2020
1
जुल॰ 23
1927
1
जून 21
2835
6
जून 17
23074