Skip to Content
Odoo Menu
  • Zaloguj się
  • Wypróbuj za darmo
  • Aplikacje
    Finanse
    • Księgowość
    • Fakturowanie
    • Wydatki
    • Arkusz kalkulacyjny (BI)
    • Dokumenty
    • Podpisy
    Sprzedaż
    • CRM
    • Sprzedaż
    • PoS Sklep
    • PoS Restauracja
    • Subskrypcje
    • Wypożyczalnia
    Strony Internetowe
    • Kreator Stron Internetowych
    • eCommerce
    • Blog
    • Forum
    • Czat na Żywo
    • eLearning
    Łańcuch dostaw
    • Magazyn
    • Produkcja
    • PLM
    • Zakupy
    • Konserwacja
    • Jakość
    Zasoby Ludzkie
    • Pracownicy
    • Rekrutacja
    • Urlopy
    • Ocena pracy
    • Polecenia Pracownicze
    • Flota
    Marketing
    • Marketing Społecznościowy
    • E-mail Marketing
    • SMS Marketing
    • Wydarzenia
    • Automatyzacja Marketingu
    • Ankiety
    Usługi
    • Projekt
    • Ewidencja czasu pracy
    • Usługi Terenowe
    • Helpdesk
    • Planowanie
    • Spotkania
    Produktywność
    • Dyskusje
    • Zatwierdzenia
    • IoT
    • VoIP
    • Baza wiedzy
    • WhatsApp
    Aplikacje trzecich stron Studio Odoo Odoo Cloud Platform
  • Branże
    Sprzedaż detaliczna
    • Księgarnia
    • Sklep odzieżowy
    • Sklep meblowy
    • Sklep spożywczy
    • Sklep z narzędziami
    • Sklep z zabawkami
    Żywienie i hotelarstwo
    • Bar i Pub
    • Restauracja
    • Fast Food
    • Pensjonat
    • Dystrybutor napojów
    • Hotel
    Agencja nieruchomości
    • Agencja nieruchomości
    • Biuro architektoniczne
    • Budowa
    • Zarządzanie nieruchomościami
    • Ogrodnictwo
    • Stowarzyszenie właścicieli nieruchomości
    Doradztwo
    • Biuro księgowe
    • Partner Odoo
    • Agencja marketingowa
    • Kancelaria prawna
    • Agencja rekrutacyjna
    • Audyt i certyfikacja
    Produkcja
    • Tekstylia
    • Metal
    • Meble
    • Jedzenie
    • Browar
    • Prezenty firmowe
    Zdrowie & Fitness
    • Klub sportowy
    • Salon optyczny
    • Centrum fitness
    • Praktycy Wellness
    • Apteka
    • Salon fryzjerski
    Transakcje
    • Złota rączka
    • Wsparcie Sprzętu IT
    • Systemy energii słonecznej
    • Szewc
    • Firma sprzątająca
    • Usługi HVAC
    Inne
    • Organizacja non-profit
    • Agencja Środowiskowa
    • Wynajem billboardów
    • Fotografia
    • Leasing rowerów
    • Sprzedawca oprogramowania
    Przeglądaj wszystkie branże
  • Community
    Ucz się
    • Samouczki
    • Dokumentacja
    • Certyfikacje
    • Szkolenie
    • Blog
    • Podcast
    Pomóż w nauce innym
    • Program Edukacyjny
    • Scale Up! Gra biznesowa
    • Odwiedź Odoo
    Skorzystaj z oprogramowania
    • Pobierz
    • Porównaj edycje
    • Wydania
    Współpracuj
    • Github
    • Forum
    • Wydarzenia
    • Tłumaczenia
    • Zostań partnerem
    • Usługi dla partnerów
    • Zarejestruj swoją firmę rachunkową
    Skorzystaj z usług
    • Znajdź partnera
    • Znajdź księgowego
    • Spotkaj się z doradcą
    • Usługi wdrożenia
    • Opinie klientów
    • Wsparcie
    • Aktualizacje
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Zaplanuj demo
  • Cennik
  • Pomoc

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

  • CRM
  • e-Commerce
  • Księgowość
  • Zapasy
  • PoS
  • Projekt
  • MRP
All apps
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Pomoc

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

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
development
1 Odpowiedz
2501 Widoki
Awatar
شركة مهارات للتقنية وتنمية الموارد البشرية

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
Awatar
Odrzuć
شركة مهارات للتقنية وتنمية الموارد البشرية
Autor

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>

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

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>


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

Thanks
I'm entered 0553448953

Awatar
D Enterprise
Najlepsza odpowiedź

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
Awatar
Odrzuć
شركة مهارات للتقنية وتنمية الموارد البشرية
Autor

Thank you

Podoba Ci się ta dyskusja? Dołącz do niej!

Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!

Zarejestruj się
Powiązane posty Odpowiedzi Widoki Czynność
Feature Request: Native “Dialog Filters” in Search Panel
development
Awatar
0
lis 25
140
Solution to the Getting Started tutorial from the official Odoo 16 documentation
development
Awatar
Awatar
Awatar
2
lis 25
1512
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
Awatar
1
lis 25
364
Guest House Module - Rental Search Bar
development
Awatar
Awatar
1
lis 25
235
How to make all branches for user active automatically after login his account?
development
Awatar
Awatar
Awatar
3
lis 25
429
Społeczność
  • Samouczki
  • Dokumentacja
  • Forum
Open Source
  • Pobierz
  • Github
  • Runbot
  • Tłumaczenia
Usługi
  • Hosting Odoo.sh
  • Wsparcie
  • Aktualizacja
  • Indywidualne rozwiązania
  • Edukacja
  • Znajdź księgowego
  • Znajdź partnera
  • Zostań partnerem
O nas
  • Nasza firma
  • Zasoby marki
  • Skontaktuj się z nami
  • Oferty pracy
  • Wydarzenia
  • Podcast
  • Blog
  • Klienci
  • Informacje prawne • Prywatność
  • Bezpieczeństwo Odoo
الْعَرَبيّة 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 to pakiet aplikacji biznesowych typu open source, które zaspokoją wszystkie potrzeby Twojej firmy: CRM, eCommerce, księgowość, inwentaryzacja, punkt sprzedaży, zarządzanie projektami itp.

Unikalną wartością Odoo jest to, że jest jednocześnie bardzo łatwe w użyciu i w pełni zintegrowane.

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