1

I have three models

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

In the zoho.tags model, I have a field called tag_id and in the zoho.tag.option, I have tag_ids and both are having the same values.

In the zoho.tags.line model, I have a Many2one field called x_zoho_tags, which shows a list of tags like: division, state, etc. and x_tags_option, which shows options for each tag, such as:

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

I want to add a domain to x_tags_option in order to filter x_tag_option to show only options that are having the same tag_id.

So when I select division from x_zoho_tags, then x_tags_option should show only A, B and C.

I have tried to add this line below, but it does not work

domain="[('tag_ids', '=', x_zoho_tags.tag_id)]
travisw
  • 2,052
  • 1
  • 14
  • 27
Alqebaiti
  • 101
  • 1
  • 11

1 Answers1

0

I have figure it out. This is how I have done it:

In 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

In XML:

 <field name="x_zoho_tags"/>
 <field name="x_tags_option" onchange="onchange_tags(x_zoho_tags)"/>
Alqebaiti
  • 101
  • 1
  • 11