Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Priemyselné odvetvia
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Reštaurácia
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Reality
    • Real Estate Agency
    • Architecture Firm
    • Konštrukcia
    • Estate Managament
    • Gardening
    • Property Owner Association
    Poradenstvo
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Jedlo
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Iní
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

Changing domain for a field

Odoberať

Get notified when there's activity on this post

This question has been flagged
domain_filterv18docker-compose
2 Replies
1904 Zobrazenia
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
Zrušiť
Avatar
Gauthier.G
Autor 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
Zrušiť
Enjoying the discussion? Don't just read, join in!

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

Registrácia
Related Posts Replies Zobrazenia Aktivita
Change Sign & Pay Button on Quotation E-mails
v18
Avatar
Avatar
Avatar
Avatar
3
nov 25
359
Problem including JS asset in v18
v18
Avatar
Avatar
Avatar
3
nov 25
8389
Is it possible to sell on credit directly at the point of sale and leave the order pending payment?
v18
Avatar
Avatar
2
sep 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
jún 25
1919
Turkey live currency rates from TCMB
v18
Avatar
Avatar
Avatar
3
mar 25
3016
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 je sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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