Skip to Content
Odoo मेन्यू
  • Sign in
  • मुफ़्त में आज़माएं
  • ऐप्लिकेशन
    फ़ाइनेंस
    • अकाउंटिंग
    • इनवॉइसिंग
    • एक्सपेंस
    • स्प्रेडशीट (बीआई)
    • डॉक्यूमेंट्स
    • साइन
    सेल्स
    • सीआरएम
    • सेल्स
    • पीओएस शॉप
    • पीओएस रेस्टोरेंट
    • सब्सक्रिप्शन
    • रेंटल
    वेबसाइट
    • वेबसाइट बिल्डर
    • ई-कॉमर्स
    • ब्लॉग
    • फ़ोरम
    • लाइव चैट
    • ई-लर्निंग
    सप्लाई चेन
    • इन्वेंट्री
    • मैन्युफ़ैक्चरिंग
    • पीएलएम
    • परचेज़
    • मेंटेनेंस
    • क्वालिटी
    मानव संसाधन
    • कर्मचारी
    • रिक्रूटमेंट
    • टाइम ऑफ़
    • अप्रेज़ल
    • रेफ़रल
    • फ़्लीट
    मार्केटिंग
    • सोशल मार्केटिंग
    • ईमेल मार्केटिंग
    • एसएमएस मार्केटिंग
    • इवेंट
    • मार्केटिंग ऑटोमेशन
    • सर्वे
    सेवाएं
    • प्रोजेक्ट
    • टाइमशीट
    • फ़ील्ड सर्विस
    • हेल्पडेस्क
    • प्लानिंग
    • अपॉइंटमेंट
    प्रॉडक्टिविटी
    • डिस्कस
    • अप्रूवल
    • आईओटी
    • वीओआईपी
    • नॉलेज
    • WhatsApp
    तीसरे पक्ष के ऐप्लिकेशन Odoo स्टूडियो Odoo क्लाउड प्लेटफ़ॉर्म
  • इंडस्ट्री
    रीटेल
    • बुक स्टोर
    • क्लोदिंग स्टोर
    • फ़र्नीचर स्टोर
    • ग्रॉसरी स्टोर
    • हार्डवेयर स्टोर
    • टॉय स्टोर
    Food & Hospitality
    • बार और पब
    • रेस्टोरेंट
    • फ़ास्ट फ़ूड
    • Guest House
    • बेवरिज डिस्ट्रीब्यूटर
    • होटल
    रियल एस्टेट
    • Real Estate Agency
    • आर्किटेक्चर फ़र्म
    • कंसट्रक्शन
    • एस्टेट मैनेजमेंट
    • गार्ड्निंग
    • प्रॉपर्टी ओनर असोसिएशन
    कंसल्टिंग
    • अकाउंटिंग फ़र्म
    • Odoo पार्टनर
    • मार्केटिंग एजेंसी
    • लॉ फ़र्म
    • टैलेंट ऐक्विज़िशन
    • ऑडिट & सर्टिफ़िकेशन
    मैन्युफ़ैक्चरिंग
    • टेक्सटाइल
    • Metal
    • फ़र्नीचर
    • फ़ूड
    • Brewery
    • कॉर्पोरेट गिफ़्ट
    हेल्थ & फिटनेस
    • स्पोर्ट्स क्लब
    • आईवियर स्टोर
    • फिटनेस सेंटर
    • वेलनेस प्रैक्टिशनर
    • फॉर्मेसी
    • हेयर सैलून
    Trades
    • Handyman
    • आईटी हॉर्डवेयर और सपोर्ट
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    अन्य
    • Nonprofit Organization
    • एन्वायरमेंटल एजेंसी
    • बिलबोर्ड रेंटल
    • फ़ोटोग्राफी
    • बाइक लीजिंग
    • सॉफ़्टवेयर रीसेलर
    Browse all Industries
  • कम्यूनिटी
    सीखें
    • ट्यूटोरियल्स
    • दस्तावेज़
    • सर्टिफ़िकेशन
    • ट्रेनिंग
    • ब्लॉग
    • पॉडकास्ट
    शिक्षा को बढ़ावा दें
    • एजुकेशन प्रोग्राम
    • स्केल अप! बिजनेस गेम
    • Odoo के ऑफ़िस में आएं
    सॉफ़्टवेयर पाएं
    • डाउनलोड
    • वर्शन की तुलना करें
    • रिलीज़
    साथ मिलकर काम करें
    • Github
    • फ़ोरम
    • इवेंट
    • अनुवाद
    • पार्टनर बनें
    • Services for Partners
    • अपना अकाउंटिंग फ़र्म रजिस्टर करें
    सेवाएं पाएं
    • पार्टनर ढूंढें
    • अकाउंटेंट खोजें
    • सलाहकार की मदद लें
    • इम्प्लिमेंटेशन सेवाएं
    • कस्टमर रेफ़रेंस
    • सहायता
    • अपग्रेड
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    डेमो देखें
  • कीमत
  • सहायता

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • सीआरएम
  • e-Commerce
  • लेखांकन
  • इन्वेंटरी
  • PoS
  • प्रोजेक्ट
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
टैग (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
टैग (View all)
odoo accounting v14 pos v15
About this forum
Help

Changing domain for a field

Subscribe

Get notified when there's activity on this post

This question has been flagged
domain_filterv18docker-compose
2 Replies
1908 Views
Avatar
Gauthier.G

Hi everyone,

I'm currently developing a module for the management of lost object. And for this module, i've created another module that list all the french region, departments, municipalities and postal codes.

I'm using a docker-compose file with the version 18 of Odoo to develop.


What i am trying to do, is that when a user selects a zip code when registering a lost item, a list of cities with the same zip code is displayed (and vice versa when the user enters a city), and i'm trying to achieve this by changing the domain.
I've also added the ability to auto-populate the field if there is only one zip code associated to a city.


When i choose a city that has only one postal code, the postal code is automatically filled (and vice versa for the city).

But when there's more than one city attached to a postal code, i got the good informations, but the list is not filtered when i try to select a city.

This is what is displayed with the UserError :

City associated with zip code 64110 : ['Gelos', 'Jurançon', 'Laroin', 'Mazères-Lezons', 'Rontignon', 'Saint-Faust', 'Uzos'].
Here is what is contained in 'communes' : [27049, 27094, 27127, 27184, 27280, 27291, 27361] 

The numbers correspond to the Id assigned by Odoo to the city. I checked and the ID 27049 does indeed correspond to the city of Gelos


Here's the code of my two models from my "Postal" module, representing municipalities and postal code :

class Commune(models.Model):

    _name = 'postal.commune'

    _description = 'Communes de France'


    name = fields.Char("Nom de la commune",required=True)

    type_commune = fields.Selection([

        ('ARM','Arrondissement municipal'),

        ('COM','Commune'),

        ('COMA','Commune associée'),

        ('COMD','Commune déléguée')

    ],string="Type de commune")

    code_insee = fields.Char("Code INSEE de la commune",required=True,size=5)

    departement_id = fields.Many2one("postal.departement",string="Département de la commune",required=True)


    # Relation hiérarchique si une commune fait partie d'une commune (par exemple : Arbigneu et Arboys en Bugey (01015) )

    parent_ids = fields.Many2one("postal.commune",string='Commune parent',ondelete='restrict')

    child_ids = fields.One2many("postal.commune","parent_ids",string="Commune enfant")


    codepostal_ids = fields.Many2many("postal.codepostal",string="Codes postaux de la commune")


class Codepostal(models.Model):

    _name = 'postal.codepostal'

    _description = 'Codes postaux de France'


    name = fields.Char("Code postal",required=True,size=5)

    commune_ids = fields.Many2many("postal.commune",string="Communes liées au code postal",required=True)

And here is the model from my module for management of lost object :

class Annonce(models.Model):

    # Champs obligatoires utilisée par Odoo

    _name = 'objetperdu.annonce'

    _description = 'Annonce d\'un objet perdu ou trouvé'


    # Champs propre à l'objet

    state = fields.Selection([('perdu','Perdu'),('trouve','Trouvé')],string="État de l'objet",default="perdu")

    date_depot = fields.Date('Date de l\'annonce',required=True)

    category_id = fields.Many2one('objetperdu.categorie',required=True,string="Catégorie de l'objet")


    # Champs relatifs à l'endroit où l'objet a été trouvé

    adresse = fields.Char('Adresse d\'où l\'objet a été trouvé/perdu',required=True)

    cp = fields.Many2one('postal.codepostal',string='Code postal',size=5,required=True)

    ville = fields.Many2one('postal.commune',string='Ville',required=True)


    # Champs relatifs à la description de l'objet

    marque = fields.Char("Marque")

    description = fields.Text("Description de l'objet")

    contient_objet = fields.Boolean("Contient des objets ?")

    description_contenu = fields.Text("Description du contenu")


    @api.onchange('cp')

    # Affiche les villes du code postal saisie, et pré-remplit le champ ville si le code postal n'appartient qu'à une seule commune

    def _onchange_cp(self):

        if self.cp:

            communes = self.cp.commune_ids

            #raise UserError(f"Communes associées au code postal {self.cp.name} : {communes.mapped('name')}. Voici ce que contient 'communes' :  {communes.ids}")

            if len(communes) == 1:

                self.ville = communes[0]

            return {'domain': {'ville': [('id', 'in', communes.ids)]}}

        else:

            return {'domain': {'ville': []}}


    @api.onchange('ville')

    # Affiche les codes postaux de la ville saisie, et pré-remplit le code postal s'il n'y en a qu'un

    def _onchange_ville(self):

        if self.ville:

            codes = self.ville.codepostal_ids

            #raise UserError(f"Codes postaux associés à la ville {self.ville.name} : {codes.mapped('name')}")

            if len(codes) == 1:

                self.cp = codes[0]

            return {'domain': {'cp': [('id', 'in', codes.ids)]}}

        else:

            return {'domain': {'cp': []}}

And here is the view for the "Annonce" model :

<odoo>

    <!-- Création de la vue de formulaire -->

    <record id="view_form_annonce" model="ir.ui.view">

        <field name="name">Formulaire d'annonce</field>

        <field name="model">objetperdu.annonce</field>

        <field name="arch" type="xml">

            <form string="annonce">

                <header>

                    <field name="state" widget="statusbar" statusbar_visible="perdu,trouve"/>

                </header>


                <sheet>

                    <notebook>

                        <!-- Onglet pour les informations générales -->

                        <page name="general" string="Général">

                            <group name="general_line1">

                                <h2>État actuel de l'objet</h2>

                                <field name="state"/>

                                <field name="date_depot"/>

                                <field name="category_id"/>

                            </group>

                        </page>


                        <!-- Onglet pour le lieu de trouvaille-->

                        <page name="lieu" string="Lieu de la perte">

                            <group>

                                <h2>Adresse de l'endroit où l'objet a été trouvé</h2>

                                <field name="adresse"/>

                                <field name="cp" onchange="1"/>

                                <field name="ville" onchange="1"/>

                            </group>

                        </page>


                        <!-- Onglet pour la description de l'objet -->

                        <page name="description" string="Description de l'objet">

                            <group>

                                <h2>Détails sur l'objet</h2>

                                <field name="marque"/>

                                <field name="description"/>

                                <field name="contient_objet"/>

                                <field name="description_contenu" invisible="not contient_objet" required="contient_objet"/>

                            </group>

                        </page>

                    </notebook>

                </sheet>

            </form>

        </field>

    </record>


    <!-- Création de la vue de liste -->

    <record id="view_list_annonce" model="ir.ui.view">

        <field name="name">Liste des annonces</field>

        <field name="model">objetperdu.annonce</field>

        <field name="arch" type="xml">

            <list>

                <field name="state"/>

                <field name="date_depot"/>

                <field name="adresse"/>

            </list>

        </field>

    </record>


    <!-- Création de la barre de recherche -->

    <record id="view_search_annonce" model="ir.ui.view">

        <field name="name">Filtre des annonces</field>

        <field name="model">objetperdu.annonce</field>

        <field name="arch" type="xml">

            <search>

                <field name="category_id"/>

                <group expand="0" string="Filtres avancés">

                    <filter name="perdu" string="Perdu" domain="[('state','=','perdu')]"/>

                    <filter name="trouve" string="Trouvé" domain="[('state','=','trouve')]"/>

                </group>

            </search>

        </field>

    </record>

</odoo>


Thank you in advance for your help.

0
Avatar
Discard
Avatar
Gauthier.G
Author Best Answer

Thank you for your answer.

I used the first option and it did works. But i would like to have all the city displayed if no zip code has been choosen.
I tried to do it by replacing "browse" by "search", but it obviously has effects on performance (36 000+ city to load at every change). How could i resole this problem ?


And also, i would like to keep the possibility to have the vice versa, typing the name of a city and changing the domain for the zip codes.

0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
Change Sign & Pay Button on Quotation E-mails
v18
Avatar
Avatar
Avatar
Avatar
3
नव॰ 25
359
Problem including JS asset in v18
v18
Avatar
Avatar
Avatar
3
नव॰ 25
8390
Is it possible to sell on credit directly at the point of sale and leave the order pending payment?
v18
Avatar
Avatar
2
सित॰ 25
756
How to segrigate a product into multiple products & at the same time i have to manufacture that product also with separate BOM? Solved
v18
Avatar
Avatar
1
जून 25
1919
Turkey live currency rates from TCMB
v18
Avatar
Avatar
Avatar
3
मार्च 25
3016
कम्यूनिटी
  • ट्यूटोरियल्स
  • दस्तावेज़
  • फ़ोरम
ओपन सोर्स
  • डाउनलोड
  • Github
  • रनबॉट
  • अनुवाद
सेवाएं
  • Odoo.sh Hosting
  • सहायता
  • अपग्रेड
  • कस्टम डेवलपमेंट्स
  • शिक्षा
  • अकाउंटेंट खोजें
  • पार्टनर ढूंढें
  • पार्टनर बनें
हमारे बारे में
  • हमारी कंपनी
  • ब्रांड ऐसेट
  • संपर्क करें
  • नौकरियां
  • इवेंट
  • पॉडकास्ट
  • ब्लॉग
  • ग्राहक
  • लीगल • गोपनीयता
  • सुरक्षा
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo, बिज़नेस से जुड़े ऐप्लिकेशन का एक कलेक्शन है जो ओपन सोर्स पर आधारित है. इसमें आपकी कंपनी की हर ज़रूरत के लिए ऐप्लिकेशन हैं. जैसे, सीआरएम, ई-कॉमर्स, अकाउंटिंग, इन्वेंट्री, पॉइंट ऑफ़ सेल, प्रोजेक्ट मैनेजमेंट वगैरह.

Odoo की सबसे बड़ी खासियत है कि यह इस्तेमाल करने में बहुत आसान है और यह पूरी तरह से इंटिग्रेट किया हुआ है.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now