تخطي للذهاب إلى المحتوى
أودو القائمة
  • تسجيل الدخول
  • جرب مجاناً
  • التطبيقات
    المالية
    • المحاسبة
    • فوترة
    • النفقات
    • جدول البيانات (BI)
    • المستندات
    • توقيع إلكتروني
    المبيعات
    • إدارة علاقات العملاء
    • المبيعات
    • نقطة البيع للمتاجر
    • نقطة البيع للمطاعم
    • الاشتراكات
    • تأجير
    المواقع الإلكترونية
    • أداة بناء المواقع الإلكترونية
    • متاجر إلكترونية
    • مدونة
    • المنتدى
    • دردشة مباشرة
    • التعليم الإلكتروني
    سلسلة التوريد
    • المستودعات
    • التصنيع
    • إدارة دورة حياة المنتج
    • المشتريات
    • الصيانة
    • الجودة
    الموارد البشرية
    • موظفون
    • التوظيف
    • إجازة عمل
    • التقييمات
    • الإحالات
    • تطبيق الأسطول
    التسويق
    • التسويق الإجتماعي
    • التسويق عبر البريد الإلكتروني
    • التسويق عبر الرسائل النصية
    • فعاليات
    • أتمتة التسويق
    • الاستطلاعات
    الخدمات
    • المشاريع
    • الجداول الزمنية
    • الخدمة الميدانية
    • مكتب المساعدة
    • التخطيط
    • مواعيد
    اﻹنتاجية
    • مناقشة
    • الموافقات
    • إنترنت الأشياء "IoT"
    • بروتوكول ربط المحادثات الصوتية عبر الإنترنت
    • المعرفة
    • WhatsApp
    التطبيقات الخارجية ستوديو أودو منصة أودو السحابية
  • قطاعات الأعمال
    البيع بالتجزئة
    • متجر كتب
    • متجر ملابس
    • متجر أثاث
    • متجر بقالة
    • متجر معدات
    • متجر ألعاب
    الطعام والضيافة
    • بار وحانة
    • المطعم
    • مطعم للوجبات السريعة
    • نزل للضيوف
    • موزّع مشروبات
    • فندق
    العقارات
    • وكالة عقارات
    • شركة هندسة معمارية
    • البناء
    • إدارة العقارات
    • العناية بالحدائق
    • اتحاد مُلاّك العقارات
    استشارة
    • مؤسسة محاسبية
    • شريك أودو
    • وكالة تسويقية
    • منشأة قانونية
    • استقطاب المواهب
    • التدقيق والتوثيق
    التصنيع
    • الأقمشة
    • معدني
    • الأثاث
    • الطعام
    • مصنع خمور
    • هدايا الشركات
    الصحة واللياقة البدنية
    • نادي رياضي
    • متجر نظارات
    • مركز لياقة بدنية
    • الممارسون الصحيون
    • صيدلية
    • صالون تصفيف الشعر
    التجارة
    • عامل صيانة
    • الأجهزة والمعدات التقنية ودعمها
    • أنظمة الطاقة الشمسية
    • صانع أحذية
    • خدمات التنظيف
    • خدمات التكييف (HVAC)
    غير ذلك
    • منظمة غير ربحية
    • وكالة بيئية
    • تأجير لوحات إعلانية
    • تصوير
    • تأجير دراجات
    • بائع وسيط للبرمجيات
    تصفح كافة قطاعات الأعمال
  • مجتمع أودو
    تعلم
    • دروس
    • التوثيق
    • شهادات
    • التدريب
    • مدونة
    • بودكاست
    قم بتعزيز التعليم
    • برنامج تعليم
    • Scale UP! لعبة الأعمال
    • قم بزيارة أودو
    احصل على البرنامج
    • تحميل
    • قارنْ الإصدارات
    • إطلاق
    تعاون
    • جيت هاب "Github"
    • المنتدى
    • فعاليات
    • الترجمات
    • كنْ شريكاً
    • خدمات الشركاء
    • سجل مكتب المحاسبة الخاص بك
    احصل على الخدمات
    • اعثر على شريك
    • اعثر على محاسب
    • قابل أحد مرشدي الأعمال
    • خدمات التنفيذ
    • مراجع العملاء
    • الدعم
    • الترقيات
    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
يجب أن تكون مسجلاً حتى تتفاعل مع المجتمع.
كافة المنشورات الأفراد الشارات
علامات التصنيف (عرض الكل)
odoo accounting v14 pos v15
حول هذا المنتدى
يجب أن تكون مسجلاً حتى تتفاعل مع المجتمع.
كافة المنشورات الأفراد الشارات
علامات التصنيف (عرض الكل)
odoo accounting v14 pos v15
حول هذا المنتدى
المساعدة

Changing domain for a field

اشتراك

تسلم الإشعارات عندما يكون هناك نشاط في هذا المنشور

لقد تم الإبلاغ عن هذا السؤال
domain_filterv18docker-compose
2 الردود
1905 أدوات العرض
الصورة الرمزية
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
الصورة الرمزية
إهمال
الصورة الرمزية
Gauthier.G
الكاتب أفضل إجابة

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
الصورة الرمزية
إهمال
هل أعجبك النقاش؟ لا تكن مستمعاً فقط. شاركنا!

أنشئ حساباً اليوم لتستمتع بالخصائص الحصرية، وتفاعل مع مجتمعنا الرائع!

تسجيل
المنشورات ذات الصلة الردود أدوات العرض النشاط
Change Sign & Pay Button on Quotation E-mails
v18
الصورة الرمزية
الصورة الرمزية
الصورة الرمزية
الصورة الرمزية
3
نوفمبر 25
359
Problem including JS asset in v18
v18
الصورة الرمزية
الصورة الرمزية
الصورة الرمزية
3
نوفمبر 25
8389
Is it possible to sell on credit directly at the point of sale and leave the order pending payment?
v18
الصورة الرمزية
الصورة الرمزية
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? تم الحل
v18
الصورة الرمزية
الصورة الرمزية
1
يونيو 25
1919
Turkey live currency rates from TCMB
v18
الصورة الرمزية
الصورة الرمزية
الصورة الرمزية
3
مارس 25
3016
المجتمع
  • دروس
  • التوثيق
  • المنتدى
مصدر مفتوح
  • تحميل
  • جيت هاب "Github"
  • المشغل الآلي رنبوت
  • الترجمات
خدماتنا
  • استضافة أودو إس إتش
  • الدعم
  • الترقية
  • التطويرات المخصصة
  • التعليم
  • اعثر على محاسب
  • اعثر على شريك
  • كنْ شريكاً
معلومات عنا
  • شركتنا
  • أصول العلامة التجارية
  • اتصلْ بنا
  • الوظائف
  • فعاليات
  • بودكاست
  • مدونة
  • عملاء
  • قانوني • الخصوصية
  • الحماية
الْعَرَبيّة 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

أودو هو عبارة عن مجموعة من تطبيقات الأعمال مفتوحة المصدر التي تغطي جميع احتياجات شركتك، مثل: إدارة علاقات العملاء والتجارة الإلكترونية والمحاسبة والمخزون ونقاط البيع وإدارة المشاريع وما إلى ذلك.

ما يجعل من أودو مميزاً هو هدفه بأن يكون سهل الاستخدام للغاية ومتكاملاً تمامًا في الوقت ذاته.

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