相关的字段应该由多个字段填充- Odoo



OpenERP:在一个模型中,我有一个单列的地址,现在我想使它相关字段,它应该复制街,street2, state_id, zip和城市列在单个地址字段从res.partner(已经有一个字段的Many2one类型选择通常从联系人(res.partner)))。当用户选择从Many2one这将复制另一个所有地址字段到我的单个字段,这是地址。我可以用(related="store_id.street"+"store_id.street2"…)? 或者如何实现?

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

应该使用onchange函数

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

最新更新