This question has been flagged

What I need:

I want to make one field for user to select a category of partners. After he made that I want to let him to select a partner from a selected category. How could I achieve that?


What I did:

I have the fallowing fields:

  • partner_categories = fields.Many2one('res.partner.category', string="Partners Categories")

  • partner_category_name = fields.Char(related='partner_categories.name', string="Choosen category name")

  • partner_adress = fields.Many2one('res.partner', string="Partner from selected category")

In the xml i have these lines:

  • <field name="partner_categories"/>

  • <field name="partner_category_name"/>

  • <field name="partner_adress" domain="[('res.partner.category','=', 'partner_category_name')]" attrs="{'invisible': [('partner_category_name', '=', 'False')]}"/>

But that doesn't work. I'm getting error:

  • ValueError: Invalid field 'res.partner.category' in leaf "&lt;osv.ExtendedLeaf: ('res.partner.category', 'ilike', 'partner_category_name') on res_partner (ctx: )>"

Afcourse it is normal because I can't inherit res.partner module so that I could access all its fields, so res.partner.category is unknown field for my module. But how could I achieve what I need?

Avatar
Discard
Author Best Answer

I found a solution. It was to use

  • 'category_id'

in a place of

  • 'res.partner.category'

So now my field line looks like

  • <field name="partner_adress" domain="[('category_id','=', 'partner_category_name')]" attrs="{'invisible': [('partner_category_name', '=', 'False')]}"/>

Avatar
Discard
Best Answer

I think your domain syntax is wrong.

It should be [('partner_categories.name', '=' ,partner_category_name)]

Each tuple in the domain needs to have 3 elements, in the form: ('field_name', 'operator', value), where:

field_name must be a valid name of field of the object model, possibly following many-to-one relationships using dot-notation, e.g 'name' or 'partner_id.name' are valid values.

operator must be a string with a valid comparison operator from this list: =, !=, >, >=, <, <=, like, ilike, in, not in, child_of, parent_left, parent_right The semantics of most of these operators are obvious. The child_of operator will look for records who are children or grand-children of a given record, according to the semantics of this model (i.e following the relationship field named by self._parent_name, by default parent_id.

value must be a valid value to compare with the values of field_name, depending on its type.

May be this will helpful you.

Avatar
Discard
Best Answer

Hi, 

You can follow following link for this:

https://youtu.be/GPhgxxwprA4

Hope it helps,

Thanks

Avatar
Discard