0

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

enter image description here

(calculer in french stands for compute which is empty)

what can be the issue?

Bashir
  • 2,057
  • 5
  • 19
  • 44

1 Answers1

2

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

Kenly
  • 24,317
  • 7
  • 44
  • 60
  • thanks for the info, well you did answered the question, but mainly my problem is that I am on a migration from saas to sh, and for that field I had some code in `compute`, so I tried to override it with python code, but it doesn't change (I have allways the old code in `compute`). so I tried to delete the model and recreate it, and compute was empty (so I posted this question) – Bashir Aug 31 '21 at 14:46