コンテンツへスキップ
Odoo メニュー
  • サインイン
  • 無料で15日試す
  • アプリ
    財務
    • 会計
    • 請求
    • 経費
    • スプレッドシート(BI)
    • ドキュメント管理
    • 署名
    販売
    • CRM
    • 販売
    • POS店舗
    • POSレストラン
    • サブスクリプション
    • レンタル
    ウェブサイト
    • ウェブサイトビルダー
    • eコマース
    • ブログ
    • フォーラム
    • ライブチャット
    • eラーニング
    サプライチェーン
    • 在庫
    • 製造
    • 製品ライフサイクル管理 (PLM)
    • 購買
    • 整備
    • 品質
    人事業務
    • 従業員管理
    • 採用
    • 休暇管理
    • 人事評価
    • リファラル
    • フリート
    マーケティング
    • ソーシャルマーケティング
    • メールマーケティング
    • SMSマーケティング
    • イベント
    • マーケティングオートメーション
    • アンケート調査
    サービス
    • プロジェクト管理
    • タイムシート
    • フィールドサービス
    • ヘルプデスク
    • 計画
    • アポイントメント
    生産性向上ツール
    • ディスカッション
    • 承認
    • IoT
    • VoIP
    • ナレッジ
    • WhatsApp
    サードパーティアプリ Odooスタジオ Odooクラウドプラットホーム
  • インダストリー(業種別ソリューション)
    小売
    • 書店
    • アパレルショップ
    • 家具専門店
    • 食料品店
    • 金物店
    • 玩具店
    飲食・ホスピタリティ業界
    • バー・パブ
    • レストラン
    • ファストフード
    • ゲストハウス
    • 飲料販売代理店
    • ホテル
    不動産
    • 不動産会社
    • 建築事務所
    • 建設
    • 不動産管理
    • 造園
    • 住宅所有者組合
    コンサルティング
    • 会計事務所
    • Odooパートナー
    • マーケティングエージェンシー
    • 法律事務所
    • 人材派遣
    • 監査・認証
    製造
    • テキスタイル
    • 金属
    • 家具
    • 飲食
    • 醸造所
    • コーポレートギフト
    ヘルス & フィットネス
    • スポーツクラブ
    • 眼鏡店
    • フィットネスセンター
    • ウェルネス専門家
    • 薬局
    • ヘアサロン
    業種
    • 便利屋
    • IT ハードウェア・サポート
    • 太陽エネルギーシステム
    • 靴メーカー
    • クリーニングサービス
    • 空調設備サービス
    その他
    • 非営利団体
    • 環境機関
    • ビルボードレンタル
    • 写真
    • 自転車リース
    • ソフトウェアリセラー
    すべての業種を見る
  • コミュニティ
    学ぶ
    • チュートリアル
    • ドキュメンテーション
    • 認定
    • トレーニング
    • ブログ
    • ポッドキャスト
    教育サポート
    • 教育プログラム
    • Scale Up! ビジネスゲーム
    • Odooオフィス訪問
    ソフトを入手
    • ダウンロード
    • エディションを比較
    • リリース
    コラボレーション
    • 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:

  • CRM
  • e-Commerce
  • 会計
  • 在庫
  • PoS
  • プロジェクト
  • MRP
All apps
コミュニティで交流するには登録する必要があります。
全てのポスト 人々 バッジ
タグ (全て表示)
odoo accounting v14 pos v15
このフォーラムについて
コミュニティで交流するには登録する必要があります。
全てのポスト 人々 バッジ
タグ (全て表示)
odoo accounting v14 pos v15
このフォーラムについて
ヘルプ

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

購読

この投稿に活動があった際に通知を受け取ります

この質問にフラグが付けられました
development
1 返信
2487 ビュー
アバター
شركة مهارات للتقنية وتنمية الموارد البشرية

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
アバター
破棄
شركة مهارات للتقنية وتنمية الموارد البشرية
著作者

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>

شركة مهارات للتقنية وتنمية الموارد البشرية
著作者

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>


شركة مهارات للتقنية وتنمية الموارد البشرية
著作者

Thanks
I'm entered 0553448953

アバター
D Enterprise
最善の回答

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
アバター
破棄
شركة مهارات للتقنية وتنمية الموارد البشرية
著作者

Thank you

ディスカッションを楽しんでいますか?読むだけでなく、参加しましょう!

今すぐアカウントを作成して、限定機能を利用したり、素晴らしいコミュニティと交流しましょう!

登録
関連投稿 返信 ビュー 活動
Feature Request: Native “Dialog Filters” in Search Panel
development
アバター
0
11月 25
128
Solution to the Getting Started tutorial from the official Odoo 16 documentation
development
アバター
アバター
アバター
2
11月 25
1506
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
アバター
1
11月 25
362
Guest House Module - Rental Search Bar
development
アバター
アバター
1
11月 25
232
How to make all branches for user active automatically after login his account?
development
アバター
アバター
アバター
3
11月 25
420
コミュニティ
  • チュートリアル
  • ドキュメンテーション
  • フォーラム
オープンソース
  • ダウンロード
  • Github
  • Runbot
  • 翻訳
サービス
  • Odoo.shホスティング
  • サポート
  • アップグレード
  • カスタム開発
  • 教育プログラム
  • 会計事務所一覧
  • パートナー一覧
  • パートナーになる
企業情報
  • 会社概要
  • ブランドアセット
  • お問い合わせ
  • 採用情報
  • イベント
  • ポッドキャスト
  • ブログ
  • お客様一覧
  • リーガル情報 • プライバシーポリシー
  • セキュリティ
الْعَرَبيّة 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(オドゥー)は、CRM、eコマース、会計、在庫管理、POS、プロジェクト管理など、企業のさまざまな業務を一つのシステムで管理できる、ベルギー発のオープンソースのERPソフトウェアです。

高機能で使いやすく、完全に統合されたERPとして、ユニークな価値を提供しています。

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