Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3 Odpowiedzi
2168 Widoki

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

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
sie 24
2332
0
sie 23
2063
1
lip 23
1976
1
cze 21
2872
6
cze 17
23104