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

Using values of many2one fields

By
Wobson
on 8/11/14, 4:44 AM 567 views

I'm working on 3 many2one fields in the 'res.partner' table: 'country_id', 'state_id' and 'city_id' and I want to use 'state_id.country_id' and 'city_id.state_id' in order to filter the value (all the states of a country, and all the cities of a state and none other) my question is : Is it possible to take the value of 'city_id.state_id' or 'state_id.country_id' and use it to filter the corresponding field ?

2

Prakash

--Prakash--
3173
| 5 4 7
Bikaner, India
--Prakash--

OpenERP Devloper at SunARC Technology

Prakash
On 8/11/14, 5:30 AM

To add domain in the state_id field example,

      'country_id': fields.many2one('res.country', 'Country'),
       'state_id': fields.many2one("res.country.state", 'State', domain="[('country_id','=',country_id)]"),

0
Wobson
On 8/11/14, 7:27 AM

Thank you very much prakash I had no idea I could do that with many2one fields, now it works perfectly.

0

Ludo - Neobis

--Ludo - Neobis--
2387
| 2 2 5
Hoogvliet, Netherlands
--Ludo - Neobis--

Developer

Ludo - Neobis
On 8/11/14, 5:24 AM

You could create a related field to get to the country_id via state. You should then be able to set a domain on another field, based on the value of the related field.

Something like this (disclaimer: this is by head, can't check for errors):

country_id = fields.related('state_id', 'country_id', string="Related country")

"domain=[('country_id', '=', country_id)]"

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/11/14, 4:44 AM
Seen: 567 times
Last updated: 3/16/15, 8:10 AM