the issue is simple, I just need to create a computed field. here is what I have:
class MyModel(models.Model):
_name = 'my.model'
a = fields.Float()
b = fields.Float()
value = fields.Float(compute='_compute_value')
@api.depends('a','b')
def _compute_value(self):
for record in self:
record.value = a/b
but when I want to check it from the web browser on the db, I see that it's not added to compute
(calculer in french stands for compute which is empty)
what can be the issue?
To create my.model
fields, Odoo will execute the following query:
INSERT INTO ir_model_fields (model_id,model,name,field_description,help,ttype,state,relation,index,store,copied,on_delete,related,readonly,required,selectable,size,translate,relation_field,relation_table,column1,column2,track_visibility)
VALUES
(390, 'my.model', 'a', 'A', NULL, 'float', 'base', NULL, false, true, true, NULL, NULL, false, false, true, NULL, false, NULL, NULL, NULL, NULL, NULL),
(390, 'my.model', 'b', 'B', NULL, 'float', 'base', NULL, false, true, true, NULL, NULL, false, false, true, NULL, false, NULL, NULL, NULL, NULL, NULL),
(390, 'my.model', 'value', 'Value', NULL, 'float', 'base', NULL, false, false, false, NULL, NULL, true, false, false, NULL, false, NULL, NULL, NULL, NULL, NULL),
(390, 'my.model', 'id', 'ID', NULL, 'integer', 'base', NULL, false, true, true, NULL, NULL, true, false, true, NULL, false, NULL, NULL, NULL, NULL, NULL),
(390, 'my.model', 'display_name', 'Display Name', NULL, 'char', 'base', NULL, false, false, false, NULL, NULL, true, false, false, NULL, false, NULL, NULL, NULL, NULL, NULL),
(390, 'my.model', 'create_uid', 'Created by', NULL, 'many2one', 'base', 'res.users', false, true, true, 'set null', NULL, true, false, true, NULL, false, NULL, NULL, NULL, NULL, NULL),
(390, 'my.model', 'create_date', 'Created on', NULL, 'datetime', 'base', NULL, false, true, true, NULL, NULL, true, false, true, NULL, false, NULL, NULL, NULL, NULL, NULL),
(390, 'my.model', 'write_uid', 'Last Updated by', NULL, 'many2one', 'base', 'res.users', false, true, true, 'set null', NULL, true, false, true, NULL, false, NULL, NULL, NULL, NULL, NULL),
(390, 'my.model', 'write_date', 'Last Updated on', NULL, 'datetime', 'base', NULL, false, true, true, NULL, NULL, true, false, true, NULL, false, NULL, NULL, NULL, NULL, NULL),
(390, 'my.model', '__last_update', 'Last Modified on', NULL, 'datetime', 'base', NULL, false, false, false, NULL, NULL, true, false, false, NULL, false, NULL, NULL, NULL, NULL, NULL) RETURNING id
You can see that compute
is not present in the column names. Its value is not stored in database