Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

allow only numeric value fields.char

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
4 Răspunsuri
15969 Vizualizări
Imagine profil
philip

Hi All,

Is there anyone can figureout what we need to be done. Code is working when I entered char value the "raise (_('Invalid phone'),_('Please enter a valid phone'))" popup on my screen then if I hit the ok button and click save button and it will save, I want only numeric value to save. is there additional code can be added?

Thanks again for your reply

xml---

<field name="mobile" string="Phone" placeholder="434343454" on_change="onchange_mobile(mobile)"/>

python---

    def onchange_mobile(self, cr, uid, ids, mobile, context=None):
        if not mobile:
            return {}
        if not mobile.isdigit():
            raise osv.except_osv(_('Invalid phone'),_('Please enter a valid phone'))
        return {}

 

any help 

0
Imagine profil
Abandonează
Imagine profil
Med Said BARA
Cel mai bun răspuns

Where the field is defined in your python code (_columns ....) ?

'mobile': fields.integer('Mobile', required =........, ..................., size= .....)

A ready solution: http://bazaar.launchpad.net/~aristobulo/web-addons/web_fields_masks/files/head:/web_fields_masks/

1
Imagine profil
Abandonează
philip
Autor

Thanks Sir, in my python I have the following: _columns = { 'mobile': fields.char('Mobile Phone', size=11), } I did already change from fields.char to fields.integer but I got the following error: if not mobile.isdigit(): AttributeError: 'int' object has no attribute 'isdigit' 2014-08-24 19:21:13,526 11482 ERROR ABS openerp.netsvc: 'int' object has no attribute 'isdigit' Traceback (most recent call last): File "/home/jp/ws/openerp/server/openerp/netsvc.py", line 296, in dispatch_rpc result = ExportService.getService(service_name).dispatch(method, params) File "/home/jp/ws/openerp/server/openerp/service/web_services.py", line 626, in dispatch res = fn(db, uid, *params) File "/home/jp/ws/openerp/server/openerp/osv/osv.py", line 190, in execute_kw return self.execute(db, uid, obj, method, *args, **kw or {}) File "/home/jp/ws/openerp/server/openerp/osv/osv.py", line 132, in wrapper return f(self, dbname, *args, **kwargs) File "/home/jp/ws/openerp/server/openerp/osv/osv.py", line 199, in execute res = self.execute_cr(cr, uid, obj, method, *args, **kw) File "/home/jp/ws/openerp/server/openerp/osv/osv.py", line 187, in execute_cr return getattr(object, method)(cr, uid, *args, **kw) File "/home/jp/ws/openerp/my_addons/abs_hr_additional_info/abs_hr_additional_info.py", line 11, in onchange_mobile if not mobile.isdigit(): AttributeError: 'int' object has no attribute 'isdigit'

philip
Autor

Sir Thank you so much and really appreciate your help. Here's what I did replace my to many thanks again

Imagine profil
Muhammad Rizwan
Cel mai bun răspuns

Us can Try this one:

@api.constrains('phone_number')
def _verify_phone_number(self):
for rec in self:
if rec.phone_number and not rec.phone_number.isdigit():
raise ValidationError(_("The Phone Number must be a sequence of digits."))


0
Imagine profil
Abandonează
Imagine profil
Bole
Cel mai bun răspuns

If you want to use onchange method to get warning on invalid chars in field,
then try this:
def onchange_mobile(self, cr, uid, ids, mobile, context=None):
        res = {}
        if not mobile:
             return res

        if not mobile.isdigit():
            # raise osv.except_osv(_('Invalid phone'),_('Please enter a valid phone'))
            res['warning'] = "Phone number %s is invalid, please use only digits!" % mobile
            res['value']['mobile'] = False   # just erase the value entered
        return res

Or, you can override thw write method of your working class and raise error if field 'mobile' is not numeric... like

def write(self, cr, uid, ids, vals, context=None):
    if 'mobile' in vals.keys() and not vals['mobile'].isdigit():
         raise osv.except_osv(_('Invalid phone'),_('Please enter a valid phone'))
    return super(your_class, self).write(cr, uid, ids, vals, context=context)

 

hope it helps

0
Imagine profil
Abandonează
philip
Autor

Thanks Sir Bole for your reply, I will try this

philip
Autor

Hi Sir Bole, Tried to test the above code I Got the Following errors: Client Traceback (most recent call last): File "/home/philip/ws/openerp/web/addons/web/http.py", line 204, in dispatch response["result"] = method(self, **self.params) File "/home/philip/ws/openerp/web/addons/web/controllers/main.py", line 1125, in call_kw return self._call_kw(req, model, method, args, kwargs) File "/home/philip/ws/openerp/web/addons/web/controllers/main.py", line 1117, in _call_kw return getattr(req.session.model(model), method)(*args, **kwargs) File "/home/philip/ws/openerp/web/addons/web/session.py", line 42, in proxy result = self.proxy.execute_kw(self.session._db, self.session._uid, self.session._password, self.model, method, args, kw) File "/home/philip/ws/openerp/web/addons/web/session.py", line 30, in proxy_method result = self.session.send(self.service_name, method, *args) File "/home/philip/ws/openerp/web/addons/web/session.py", line 103, in send raise xmlrpclib.Fault(openerp.tools.ustr(e), formatted_info) Server Traceback (most recent call last): File "/home/philip/ws/openerp/web/addons/web/session.py", line 89, in send return openerp.netsvc.dispatch_rpc(service_name, method, args) File "/home/philip/ws/openerp/server/openerp/netsvc.py", line 296, in dispatch_rpc result = ExportService.getService(service_name).dispatch(method, params) File "/home/philip/ws/openerp/server/openerp/service/web_services.py", line 626, in dispatch res = fn(db, uid, *params) File "/home/philip/ws/openerp/server/openerp/osv/osv.py", line 190, in execute_kw return self.execute(db, uid, obj, method, *args, **kw or {}) File "/home/philip/ws/openerp/server/openerp/osv/osv.py", line 132, in wrapper return f(self, dbname, *args, **kwargs) File "/home/philip/ws/openerp/server/openerp/osv/osv.py", line 199, in execute res = self.execute_cr(cr, uid, obj, method, *args, **kw) File "/home/philip/ws/openerp/server/openerp/osv/osv.py", line 187, in execute_cr return getattr(object, method)(cr, uid, *args, **kw) File "/home/philip/ws/openerp/my_addons/for_development/philcode_test.py", line 16, in onchange_mobile res['value']['mobile'] = False # just erase the value entered KeyError: 'value' Here the XML and python file XML file----- PYTHON FIle----- import time from osv import osv, fields from openerp import tools class philcode_test(osv.Model): _name = "philcode.test" def onchange_mobile(self, cr, uid, ids, mobile, context=None): res = {} if not mobile: return res if not mobile.isdigit(): # raise osv.except_osv(_('Invalid phone'),_('Please enter a valid phone')) res['warning'] = "Phone number %s is invalid, please use only digits!" % mobile res['value']['mobile'] = False # just erase the value entered return res _columns = { 'a': fields.char('A', size=12), 'b': fields.char('B', size=12), 'mobile': fields.char('Mobile Phone', size=11), }

Imagine profil
René Schuster
Cel mai bun răspuns

The on_change() method can only return values, domains or warnings. If you don't want a record with a non numeric phone number to be safed, then either follow Boles hint and override the write() method, or use the built in functionality of constraints!

def _check_mobile(self, cr, uid, ids, context=None):
     for obj in self.browse(cr, uid, ids, context=context):
          if not obj.mobile.isdigit():
              return False
     return True

_constraints = [(_check_mobile, _('Error: Wrong Phone Number Format!'), [mobile'])]

Add this code to your .py file and leave the field as char.

The constraints will be checked whenever a record is saved (creation/modification).

 

Regards.

0
Imagine profil
Abandonează
philip
Autor

Thank you Sir René Schuster will try booth solution

Enjoying the discussion? Don't just read, join in!

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

Înscrie-te
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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