Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
3 Replies
2150 Tampilan

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
Buang
Jawaban Terbai

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
Buang
Jawaban Terbai

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
Buang
Jawaban Terbai

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
Buang
Post Terkait Replies Tampilan Aktivitas
2
Agu 24
2289
0
Agu 23
2018
1
Jul 23
1927
1
Jun 21
2834
6
Jun 17
23072