Search code examples
pythonmoduleormfieldodoo

related field should populate with multiple fields - Odoo


OpenERP: in a model i had a single column for Address, now i want to make it related field which should copy values of street, street2, state_id, zip and city columns in single Address field from res.partner (already had a field of Many2one type which selecting normally from contacts (res.partner)). when user select from Many2one this will copy another all address fields into my single field which is Address. can i do it with (related="store_id.street"+"store_id.street2" ... )? or how it can be achieved?

> class Stores(models.Model):

    _name = 'tests.stores'

    _rec_name = 'name'

    _description = "Tests Stores"



    store_id = fields.Many2one('res.partner', string="Select Store", domain="[['category_id.name','ilike','store%']]")

    name = fields.Char(related='store_id.name', store=True, invisible="1")

    address = fields.Text(string="Address")

    is_exist = fields.Boolean(string="Still Exist?", default=True)

    owner_name = fields.Char(string="Owner Name")

    owner_image = fields.Binary()

Solution

  • You should use onchange fuction.

    @api.onchange('store_id')
    def change_address(self):
      self.address = self.store_id.street+self.store_id.street2