跳至内容
菜单
此问题已终结
3 回复
2186 查看

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

形象
丢弃
最佳答案

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

形象
丢弃
最佳答案

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

形象
丢弃
最佳答案

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

形象
丢弃
相关帖文 回复 查看 活动
2
8月 24
2342
0
8月 23
2076
1
7月 23
1989
1
6月 21
2897
6
6月 17
23112