Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
3 Ответы
2224 Представления

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

Аватар
Отменить
Related Posts Ответы Просмотры Активность
2
авг. 24
2386
0
авг. 23
2119
1
июл. 23
2030
1
июн. 21
2931
6
июн. 17
23155