Odoo Help


domain filter for many2one fields in odoo?

on 8/8/16, 6:30 AM 326 views

Below code is account_invoice inherited class . Here i will add 'arrondissement_id', 'town_id' 

arrondissement_id = fields.Many2one('account.arrondissement','Arrondissement')

town_id = fields.Many2one('account.town','Commune')

Now i want  if i select 'town_id' with 'RABAT' (FOR EXAMPLE) then next field 'arrondissemnet_id' i have to get only 'RABAT'
drop down list  and previous selected 'arrondissement_id' values should get deleted . i have tried with domain filter option but isnt work this is my code :

class account_town(models.Model):

_name = 'account.town'

_description = "town"

name = fields.Char('Nom de la Commune', required=True)

code = fields.Char('Code de la Commune')

prefecture_id = fields.Many2one('account.prefecture','Préfecture')

# @api.onchange('name')

# def onchange_town(self):

# res = {}

# if self.name:

# res['domain'] = {'arrondissement_id': [('town_id', '=', self.town.id)]}

# return res

class account_arrondissement(models.Model):

_name = 'account.arrondissement'

_description = "arrondissement"

name = fields.Char('Nom d\'Arrondissements', required=True)

code = fields.Char('Code d\'Arrondissements')

town_id = fields.Many2one('account.town','Commune')

class AccountInvoice(models.Model):

_name = 'account.invoice'

_inherit = 'account.invoice'

is_oi_generated = fields.Boolean('OI généré ?',default=0)

prefecture_id = fields.Many2one('account.prefecture','Préfecture')

town_id = fields.Many2one('account.town','Commune')

arrondissement_id = fields.Many2one('account.arrondissement','Arrondissement')

maitre_ouvrage = fields.Char('Maitre ouvrage')

num_dossier = fields.Char('N°dossier')

type_paiement = fields.Selection([('online', 'Paiement En ligne'), ('chek2', 'chèque'), ('cash1', 'Espèce'), ('cart', 'Carte Bancaire'), ('virement', 'Virement')],string='Type de paiement')

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 platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 8/8/16, 6:30 AM
Seen: 326 times
Last updated: 8/8/16, 11:06 AM