Skip to Content
Menu
This question has been flagged
2 Replies
12893 Views

Hi,

I have model that contain 40000 record i should do something that can set automaticaly the value of a field in every record like this :

fields1 should get the value of the fields2 always in the same record for the whole records at once

Any help, Thaaanks

Regards


Avatar
Discard
Best Answer

Hello,

You can achieve using the making the field related of another field. and another way is make the second field to compute. using compute you can also achieve.

using related field:  

fieldname_2 = fields.Char(related="fieldname_1", string="field 2")

using compute:

@api.depends('fieldname_1')
def _compute_fieldvalue(self):
    for each in self:
      each.fieldname_2  = each.fieldname_1

fieldname_2 = fields.Char(compute="_compute_fieldvalue", string="field 2")


Avatar
Discard
Author

Thanks, how can i store the value on the db for the related or the computed field

into the field pass the attribute store=True

like

fieldname_2 = fields.Char(compute="_compute_fieldvalue", string="field 2", store=True)

By just adding store=True to the field. like this :

fieldname_2 = fields.Char(X, string="field 2", store=True)

X is either compute or related as shown in the answser.

Author

Yes this work for new records and not for existing records( when using store it keep always the old value) i need something to crush or overwrite the value inside

for old records using query you can achieve easily

like

UPDATE table SET column2 = column1;

Author

Thanks so much

Hi,
I didn't know this postgres option, thank you for the share
But how about company_dependent fields ?

You can not store company_dependent field in a database. Because when the company is change then company_depedent field value is also changed. (This field data is stored in ir.property object in odoo which name is Company Properties in odoo)

Best Answer

Please how to add condition (if fieldname_1 like 'OUT') using compute

Avatar
Discard