域名在Many2one Odoo 11

问题描述 投票:1回答:1

我有三个型号

class ZohoTags(models.Model):
    _name = 'zoho.tags'

    name = fields.Char(string="Tags")
    tag_id = fields.Char(string="Tag Id")


class TagsLine(models.Model):
    _name = 'zoho.tags.line'

    x_zoho_tags = fields.Many2one('zoho.tags', string='Tags')
    x_tags_option = fields.Many2one('zoho.tag.option', string='Tags Option', domain="[('tag_ids', '=', x_zoho_tags.tag_id)]")
    rules_id = fields.Many2one('hr.salary.rule')


class TagOptions(models.Model):
     _name = 'zoho.tag.option'

     name = fields.Char(string="tag option name")
     option_tag_id = fields.Char(string="tag option id")
     tag_ids = fields.Char(string="tag_id")

zoho.tags模型中,我有一个名为tag_id的字段,在zoho.tag.option中,我有tag_ids,两者都具有相同的值。

zoho.tags.line模型中,我有一个名为Many2onex_zoho_tags字段,它显示了一个标签列表,如:division, state, etc.x_tags_option,显示每个标签的选项,例如:

标签(除法)有选项(A,B,C),这些选项具有为(除法)标签存储的相同tag_ids

我想为x_tags_option添加一个域,以便过滤x_tag_option以仅显示具有相同tag_id的选项。

因此,当我从division选择x_zoho_tags时,x_tags_option应该只显示A, B and C

我试过在下面添加这一行,但它不起作用

domain="[('tag_ids', '=', x_zoho_tags.tag_id)]
python python-3.x odoo odoo-11 zohobooks
1个回答
0
投票

我弄清楚了。这就是我做到的方式:

在python中:

  @api.onchange('x_zoho_tags')
  def onchange_tags(self):
      res = {}
      if self.x_zoho_tags:
         res['domain'] = {'x_tags_option': [('tag_ids', '=', self.x_zoho_tags.tag_id)]}
      return res

在XML中:

 <field name="x_zoho_tags"/>
 <field name="x_tags_option" onchange="onchange_tags(x_zoho_tags)"/>
© www.soinside.com 2019 - 2024. All rights reserved.