Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Dynamic domain depending on user selection

By
Julius Petraška
on 8/7/15, 3:18 AM 875 views

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?

0
Julius Petraška
On 8/10/15, 2:24 AM

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')]}"/>

1

Solanki Shamji

--Solanki Shamji--
1293
| 5 2 6
Baroda, India
--Solanki Shamji--

Hello!

Solanki Shamji
On 8/7/15, 4:09 AM

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.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 8/7/15, 3:18 AM
Seen: 875 times
Last updated: 8/10/15, 2:24 AM