Ir al contenido
Odoo Menú
  • Iniciar sesión
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • PdV para tiendas
    • PdV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en vivo
    • eLearning
    Cadena de suministro
    • Inventario
    • Manufactura
    • PLM
    • Compras
    • Mantenimiento
    • Calidad
    Recursos humanos
    • Empleados
    • Reclutamiento
    • Vacaciones
    • Evaluaciones
    • Referencias
    • Flotilla
    Marketing
    • Redes sociales
    • Marketing por correo
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyectos
    • Registro de horas
    • Servicio externo
    • Soporte al cliente
    • Planeación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Artículos
    • WhatsApp
    Aplicaciones externas Studio de Odoo Plataforma de Odoo en la nube
  • Industrias
    Venta minorista
    • Librería
    • Tienda de ropa
    • Mueblería
    • Tienda de abarrotes
    • Ferretería
    • Juguetería
    Alimentos y hospitalidad
    • Bar y pub
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidora de bebidas
    • Hotel
    Bienes inmuebles
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión de bienes inmuebles
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Firma contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Manufactura
    • Textil
    • Metal
    • Muebles
    • Comida
    • Cervecería
    • Regalos corporativos
    Salud y ejercicio
    • Club deportivo
    • Óptica
    • Gimnasio
    • Especialistas en bienestar
    • Farmacia
    • Peluquería
    Trades
    • Personal de mantenimiento
    • Hardware y soporte de TI
    • Sistemas de energía solar
    • Zapateros y fabricantes de calzado
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin fines de lucro
    • Agencia para la protección del medio ambiente
    • Alquiler de anuncios publicitarios
    • Fotografía
    • Alquiler de bicicletas
    • Distribuidor de software
    Descubre todas las industrias
  • Odoo Community
    Aprende
    • Tutoriales
    • Documentación
    • Certificaciones
    • Capacitación
    • Blog
    • Podcast
    Fortalece la educación
    • Programa educativo
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtén el software
    • Descargar
    • Compara ediciones
    • Versiones
    Colabora
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Conviértete en partner
    • Servicios para partners
    • Registra tu firma contable
    Obtén servicios
    • Encuentra un partner
    • Encuentra un contador
    • Contacta a un consultor
    • Servicios de implementación
    • Referencias de clientes
    • Soporte
    • Actualizaciones
    GitHub YouTube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicita una demostración
  • Precios
  • Ayuda

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

  • CRM
  • e-Commerce
  • Contabilidad
  • Inventario
  • PoS
  • Proyectos
  • MRP
All apps
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

Show warning message when enter wrong mobile no. format in Odoo 10

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
apipython2.7warningvalidationodoo10
5 Respuestas
12599 Vistas
Avatar
Pawan Kumar Sharma

Hello all,

I have a integer field 'is_mobile'. Where user entering mobile. I want that when user enter wrong mobile no. format then it show warning message "invalid no. format" and also form not save without right format. For this i applied code, but it is not work as per requirement. 

Code is below:

is_mobile = fields.Integer("Mobile")


@api.multi

    @api.constrains('is_mobile')

    def _check_phone_number(self):

        for rec in self:

            if rec.is_mobile and len(rec.is_mobile) != "^[0-9]{10}$" :

                raise ValidationError(_("Wrong value enter"))

            else:

                return False

        return {}


Thanks in advance

0
Avatar
Descartar
Pawan Kumar Sharma
Autor


Avatar
Parth Patel (pat)
Mejor respuesta

Hello Pawan,
Specific about your python condition :  

if rec.is_mobile and len(rec.is_mobile) != "^[0-9]{10}$" :
I Could not understand why you need to compare regex string with length, as it going to directly compare the string only not regex output.
So, rather you can directly do something like this :
if rec.is_mobile and len(str(rec.is_mobile)) != 10 :
1
Avatar
Descartar
Pawan Kumar Sharma
Autor

Hii @Parth, Your code upto 10 digits work well, But after 10 digits it shows error "The following fields are invalid: " also warning message change into error when using character and other type words. I want that warning show else than 10 digits in any condition.

Thanks for help.

Parth Patel (pat)

Hi Pawan, The Error warning 'The following fields are invalid: ' is due to you are using is_mobile as an Integer field and it can store max 10 digits, more than that it will show error. To, avoid this you can take Char field insted.

Just sake of information :

If you are about to develope something in odoo you can even use the default phone validation module provided by odoo. Where you have to just define phone widget in xml view.

<field name="phone" widget="phone"/>

And make sure module 'phone_validation' will install. This module will validate the phone number according to the country selected.

Pawan Kumar Sharma
Autor

Thanks parth, Now error message problem solved, but there is still one problem is that it take 10 values they might be integer, character, comma and etc. But i want only 10 integer values else validation. So, how i solve this problem for only integer 10 numbers?

Parth Patel (pat)

Hello Pawan, For that you can make use of your regex like this,

import re

pattern = re.compile("^[0-9]{10}$")

if pattern.match(string):

return true

else:

return false

Pawan Kumar Sharma
Autor

Thanks parth work with following code:

@api.multi

@api.constrains('whats_app')

def _onchange_phone_number(self):

pattern = re.compile("^[0-9]{10}$")

for rec in self:

if pattern.match(rec.whats_app) and len(str(rec.whats_app)) == 10:

return True

else:

raise ValidationError(_("Invalid Mobile No."))

¿Le interesa esta conversación? ¡Participe en ella!

Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

Registrarse
Publicaciones relacionadas Respuestas Vistas Actividad
"IndexError: list index out of range" on Button wizard action for sending SMS on mobile in Odoo10
api mobile python2.7 odoo10
Avatar
0
sept 17
4087
TypeError: unsupported operand type(s) for +: 'bool' and 'str' in Odoov10
function error api python2.7 odoo10
Avatar
Avatar
3
oct 17
22946
How to add values of particular column from One2many field in Odoo10
api python2.7 openerp odoo10 odoo10.0
Avatar
1
oct 17
11281
How to return action window or wizard from def copy()or def write method in odoo 10.
python2.7 odoo10
Avatar
Avatar
2
jul 25
1666
Show edit button on odoo 10 qweb html report.
python2.7 odoo10
Avatar
0
dic 24
1876
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento en Odoo.sh
  • Soporte
  • Actualizaciones del software
  • Desarrollos personalizados
  • Educación
  • Encuentra un contador
  • Encuentra un partner
  • Conviértete en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contáctanos
  • Empleos
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Legal • Privacidad
  • Seguridad
الْعَرَبيّة 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 es un conjunto de aplicaciones de código abierto que cubren todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

La propuesta única de valor de Odoo es ser muy fácil de usar y estar totalmente integrado.

Sitio web hecho con

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