i have a model that inherits res.partner model
class supplierDetails(models.Model):
_inherit = 'res.partner'
farmer_code = fields.Char(string="Farmer's Code")
Now i want the values from farmer_code in another model, so as per this answer, i reached this far.
class productTest(models.Model):
_name = 'quality.physical'
_inherit = 'res.partner'
frm_code_ids = fields.Many2one('res.partner',string="Farmer Code")
frm_cod = fields.Char(related='frm_code_ids.farmer_code',store=True,readonly=True)
Now i am getting KeyError: 'farmer_code' . What do i do to fix this? Thanks in advance.
Your code should work, repeat the process step by step make sure the res.partner
have this field you may forget to put the class in the __init__.py
file.
# related field without store is like a compute field it's computed on fly
related_field_name = fields.FieldType(related='your_m2o.target_field_name')
If you put store=True
it will be added to the database and recomputed whenever you change the value of many2one
.
You can go more than one level ex: your_m2m.another_m2o_field.target_field_name
.
Field type should be the same as the target field.
Just make sure the target model have that field.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.