Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Food & Hospitality
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brewery
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Trades
    • Bricoleur
    • Matériel informatique et support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Browse all Industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services for Partners
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

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

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

I want to modify the partner form in odoo 18 enterprise; How to edit code?

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
development
1 Répondre
2489 Vues
Avatar
شركة مهارات للتقنية وتنمية الموارد البشرية

I would like help with the following: - I want to modify the partner form by adding three fields: nationality, gender, and ID. This way, I can search for a customer within the partner form from any application using the search bar by entering their mobile number, ID number, or name (which is the default in Odoo) and simply pressing Enter.  - I want to set the conditions for the mobile number to be 0553449910, because when adding the number, the country code is added, and when searching, I was unable to do so. As for the ID, if the nationality is Saudi, the ID number must begin with 1, otherwise it must begin with 2.

I don't select but press enter


To be the same search by name

from odoo import models, fields, api, _

from odoo.exceptions import ValidationError

import re


class ResPartner(models.Model):

_inherit = 'res.partner'


identity_number = fields.Char(string="Identity Number", index=True, size=10) # Added size limit

gender = fields.Selection([('male', 'Male'), ('female', 'Female')], string="Gender")

nationality_id = fields.Many2one('res.country', string='nationality')


_sql_constraints = [

('unique_identity_number', 'unique(identity_number)', 'ID number already used.'),

('unique_phone_number', 'unique(phone)', 'Phone number already used.') # Renamed constraint for clarity

]


@api.constrains('identity_number', 'nationality_id')

def _check_identity_number_format(self):

for rec in self:

number = (rec.identity_number or '').strip()

if number:

if not number.isdigit():

raise ValidationError(_("ID number must contain number."))

if len(number) != 10:

raise ValidationError(_("The ID number must consist of only 10 digits."))



if rec.nationality_id:

if rec.nationality_id.code == 'SA' and not number.startswith('1'):

raise ValidationError(_("The ID number for Saudis must start with the number 1."))

elif rec.nationality_id.code != 'SA' and not number.startswith('2'):

raise ValidationError(_("The ID number for non-Saudis must start with the number 2."))


@api.constrains('phone')

def _check_phone_format(self):

for rec in self:

phone = (rec.phone or '').strip()

if phone:

clean_phone = re.sub(r'\D', '', phone)

if not clean_phone.isdigit():

raise ValidationError(_("Phone number contain numbers only."))

if len(clean_phone) != 10:

raise ValidationError(_("Phone number must be 10 digits."))


@api.model

def _name_search(self, name='', args=None, operator='ilike', limit=100, name_get_uid=None):

args = args or []

domain = []


if name:

# Clean the name input to only contain digits for numerical searches

clean_name = re.sub(r'\D', '', name)

# Base search domain for name, phone, and identity_number

search_domain = ['|', '|',

('name', operator, name),

('phone', operator, name),

('identity_number', operator, name)]

# If the cleaned name is numeric, add specific phone/identity number search conditions

if clean_name:

# If it looks like a full 10-digit number (potential phone or identity)

if len(clean_name) == 10:

search_domain.extend(['|',

('phone', '=', clean_name),

('identity_number', '=', clean_name)])

# Handle partial matches for phone and identity number as well if needed

elif len(clean_name) <= 10: # For partial numerical searches

search_domain.extend(['|',

('phone', operator, clean_name),

('identity_number', operator, clean_name)])


domain = search_domain + args

else:

domain = args


return self.search(domain, limit=limit).name_get()



#XML 

<odoo>

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

<field name="name">res.partner.form.training.center</field>

<field name="model">res.partner</field>

<field name="inherit_id" ref="base.view_partner_form"/>

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


<xpath expr="//field[@name='website']" position="before">

<field name="identity_number" placeholder="Ex: 1012345678" required="1"/>

<field name="gender"/>

<field name="nationality_id"/>

</xpath>


<xpath expr="//field[@name='mobile']" position="replace">

</xpath>


<xpath expr="//field[@name='phone']" position="attributes">

<attribute name="placeholder">05XXXXXXXX</attribute>

<attribute name="required">1</attribute>

</xpath>


</field>

</record>

</odoo>

0
Avatar
Ignorer
شركة مهارات للتقنية وتنمية الموارد البشرية
Auteur

How do I prevent the user from entering more than 10 numbers only?

<xpath expr="//field[@name='phone']" position="attributes">
<attribute name="placeholder">05XXXXXXXX</attribute>
<attribute name="required">1</attribute>
<attribute name="maxlength">10</attribute>

شركة مهارات للتقنية وتنمية الموارد البشرية
Auteur

How do I prevent the user from entering more than 10 numbers only?

<xpath expr="//field[@name='phone']" position="attributes">

    <attribute name="placeholder">05XXXXXXXX</attribute>

    <attribute name="required">1</attribute>

    <attribute name="options">{'maxlength': '10'}</attribute>

</xpath>


شركة مهارات للتقنية وتنمية الموارد البشرية
Auteur

Thanks
I'm entered 0553448953

Avatar
D Enterprise
Meilleure réponse

Hii,

Here is updated code please check 

from odoo import models, fields, api, _ from odoo.exceptions import ValidationError import re class ResPartner(models.Model): _inherit = 'res.partner' identity_number = fields.Char(string="Identity Number", index=True, size=10) gender = fields.Selection([('male', 'Male'), ('female', 'Female')], string="Gender") nationality_id = fields.Many2one('res.country', string='Nationality') _sql_constraints = [ ('unique_identity_number', 'unique(identity_number)', 'ID number already used.'), ('unique_phone_number', 'unique(phone)', 'Phone number already used.') ] @api.constrains('identity_number', 'nationality_id') def _check_identity_number_format(self): for rec in self: number = (rec.identity_number or '').strip() if number: if not number.isdigit(): raise ValidationError(_("ID number must contain only digits.")) if len(number) != 10: raise ValidationError(_("The ID number must be exactly 10 digits.")) if rec.nationality_id: if rec.nationality_id.code == 'SA' and not number.startswith('1'): raise ValidationError(_("The ID number for Saudis must start with 1.")) elif rec.nationality_id.code != 'SA' and not number.startswith('2'): raise ValidationError(_("The ID number for non-Saudis must start with 2.")) @api.constrains('phone') def _check_phone_format(self): for rec in self: phone = (rec.phone or '').strip() if phone: clean_phone = re.sub(r'\D', '', phone) if not clean_phone.isdigit(): raise ValidationError(_("Phone number must contain digits only.")) if len(clean_phone) != 10: raise ValidationError(_("Phone number must be exactly 10 digits (e.g., 05XXXXXXXX).")) @api.model def _name_search(self, name='', args=None, operator='ilike', limit=100, name_get_uid=None): args = args or [] domain = [] if name: clean_name = re.sub(r'\D', '', name) search_domain = ['|', '|', ('name', operator, name), ('identity_number', operator, clean_name), ('phone', operator, name), ] # Convert +966xxxxxxxxx to 05xxxxxxxx if clean_name: local_number = clean_name if clean_name.startswith('966') and len(clean_name) == 12: local_number = '0' + clean_name[3:] # 966553449910 → 0553449910 if len(local_number) == 10: search_domain += ['|', ('phone', 'ilike', local_number), ('mobile', 'ilike', local_number) ] domain = search_domain + args else: domain = args return self.search(domain, limit=limit).name_get()

XML View File 

<odoo> <record id="view_partner_form_inherit_identity" model="ir.ui.view"> <field name="name">res.partner.form.identity.fields</field> <field name="model">res.partner</field> <field name="inherit_id" ref="base.view_partner_form"/> <field name="arch" type="xml"> <!-- Insert fields before website field --> <xpath expr="//field[@name='website']" position="before"> <field name="identity_number" placeholder="Ex: 1012345678" required="1"/> <field name="gender"/> <field name="nationality_id"/> </xpath> <!-- Replace mobile field to show it again --> <xpath expr="//field[@name='mobile']" position="replace"> <field name="mobile" placeholder="05XXXXXXXX"/> </xpath> <!-- Add attributes to phone --> <xpath expr="//field[@name='phone']" position="attributes"> <attribute name="placeholder">05XXXXXXXX</attribute> <attribute name="required">1</attribute> </xpath> </field> </record> </odoo>

i hope it is usefull

1
Avatar
Ignorer
شركة مهارات للتقنية وتنمية الموارد البشرية
Auteur

Thank you

Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Publications associées Réponses Vues Activité
Feature Request: Native “Dialog Filters” in Search Panel
development
Avatar
0
nov. 25
129
Solution to the Getting Started tutorial from the official Odoo 16 documentation
development
Avatar
Avatar
Avatar
2
nov. 25
1507
How do I change the name of the module, or rather the name assigned to the module, after I created it in Odoo Studio?
development
Avatar
1
nov. 25
362
Guest House Module - Rental Search Bar
development
Avatar
Avatar
1
nov. 25
232
How to make all branches for user active automatically after login his account?
development
Avatar
Avatar
Avatar
3
nov. 25
426
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenez partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة 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 est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

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