This question has been flagged
3 Replies
3047 Views

hi all,

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" ... )?

please guide, how I can do it?

my Py file:

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()


Avatar
Discard
Best Answer

Hi,
You can’t set the related with concatenate, but you can write a compute method for address.

@api.depends('store_id')
def _compute_address(self):
for rec in self:
res = [rec.store_id.street, rec.store_id.street2,
rec.store_id.city,
rec.store_id.zip]
rec.address = ', '.join(filter(bool, res))

Regards

Avatar
Discard
Best Answer

Hey Smith,

Try passing context like below in the XML file. It should work as per your requirements.

<field name="store_id" widget="res_partner_many2one" context="{'res_partner_search_mode': 'customer', 'show_address': 1}" options='{"always_reload": True}'/>

Thank you!

Regards,




Email:      odoo@aktivsoftware.com  

Skype: kalpeshmaheshwari

   

Avatar
Discard
Author Best Answer

this solution is very easy...

@api.onchange('store_id')

def change_address(self):

    self.address = self.store_id.street+self.store_id.street2+self.store_id.zip+self.store_id.city

posted for those who are like me... beginners :)

Avatar
Discard