python - Many2one Odoo 11 中的域

标签 python python-3.x odoo odoo-11

我有三个模型

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 模型中,我有一个名为 x_zoho_tagsMany2one 字段,它显示了一个标签列表,例如:division, state, etc.x_tags_option,显示每个标签的选项,例如:

Tag (division) has options (A,B,C) and these options are having the same tag_ids stored for (division) tag

我想向 x_tags_option 添加域以过滤 x_tag_option 仅显示具有相同 tag_id 的选项。

因此,当我从 x_zoho_tags 中选择 division 时,x_tags_option 应仅显示 A、B 和 C

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

domain="[('tag_ids', '=', x_zoho_tags.tag_id)]

最佳答案

我已经弄清楚了。我就是这样做的:

在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)"/>

关于python - Many2one Odoo 11 中的域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55206659/

相关文章:

json - 如何在 Odoo Controller 中获取 JSON 数据?

python - 如何使用openpyxl使Excel工作表中的所有列折叠全部隐藏或在启动Excel时显示?

python - 如何删除 Pandas 数据框中多次出现特定列的行

python - 如何使用 nbconvert+pandoc 以 pdf 格式呈现 pd.DataFrame 表

python - 自定义 Python gTTS 语音

python - Linux中的Python和python3有不同的pip吗?

python : importing different module with same name

python - 如何使用 Python 在 Airflow 中的另一个 DAG 成功时触发 DAG?

javascript - 如何在调用 this._super 之前捕获 Promise? JavaScript

python - 如何使一个 ListView 中的不同记录直接到odoo 10中的不同表单 View