Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

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

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

trying to auto correct a wrong users value

Subscriure's

Get notified when there's activity on this post

This question has been flagged
onchange
1 Respondre
2901 Vistes
Avatar
Gondran Louis

Hi, in this program, I'm trying to automatically correct a value if the user uses the wrong syntax, for example, if they enter '12h12,' I'd like to auto-correct it to '12:12.' Even though the corrected_value is modified correctly, it's not returned in my ERP, which retains the incorrect value. So, I assume the error comes from the following two lines: value = corrected_value self.write({field_name: value})

How can I fix this?"



# -*- coding: utf-8 -*-

import json

from openerp.exceptions import except_orm, ValidationError, Warning

from openerp import models, fields, api, _


import requests

import re


class x_days(models.Model):

  _name = 'x.days'

  name = fields.Char(string='Breaks', copy=False)

  breaks_monday = fields.Char(string='Monday breaks')

  breaks_tuesday = fields.Char(string='Tuesday breaks')

  breaks_wednesday = fields.Char(string='Wednesday breaks')

  breaks_thursday = fields.Char(string='Thursday breaks')

  breaks_friday = fields.Char(string='Friday breaks')


  def config(self):

    get_rcdst = self.search([])

    mon = get_rcdst.read(['breaks_monday'])

    tue = get_rcdst.read(['breaks_tuesday'])

    wed = get_rcdst.read(['breaks_wednesday'])

    thu = get_rcdst.read(['breaks_thursday'])

    fri = get_rcdst.read(['breaks_friday'])

    d = {'fri': [], 'mon': [], 'tue': [], 'thu': [], 'wed': []}

    l = [mon, tue, wed, thu, fri]

    for i in mon:

      d['mon'].append(i['breaks_monday'])

    for i in tue:

      d['tue'].append(i['breaks_tuesday'])

    for i in wed:

      d['wed'].append(i['breaks_wednesday'])

    for i in thu:

      d['thu'].append(i['breaks_thursday'])

    for i in fri:

      d['fri'].append(i['breaks_friday'])


    d = json.dumps(d)

    headers = {'Content-Type': 'application/json'}

    response = requests.post('http://172.19.0.35:5000/new_slot', data=d, headers=headers)


    if response.status_code == 200:

      print('Requête POST réussie')

      print('Réponse du serveur:', response.text)

    else:

      print('Échec de la requête POST')

      print('Code d état HTTP:', response.status_code)

    return 0


  @api.multi

  def write(self, vals):

    rc = super(x_days, self).write(vals)

    self.config()

    return rc


  @api.model

  def create(self, vals):

    rc = super(x_days, self).create(vals)

    self.config()

    return rc


  @api.onchange('breaks_monday', 'breaks_tuesday', 'breaks_wednesday', 'breaks_thursday', 'breaks_friday')

  def _onchange_my_field(self):

      for field_name in ['breaks_monday', 'breaks_tuesday', 'breaks_wednesday', 'breaks_thursday', 'breaks_friday']:

          value = getattr(self, field_name)

          if value:

              pattern = r'^\d{2}:\d{2}$'  # Syntaxe correcte "hh:mm"

              if not re.match(pattern, value):

                  corrected_value = self._try_to_correct_value(value)

                  if corrected_value:

                      value = corrected_value

                      self.write({field_name: value})

                  else:

                      raise ValidationError("Syntaxe incorrecte. Utilisez hh:mm.")

                      return 0



  def _try_to_correct_value(self, value):

    corrected_value = None

    if ',' in value:

        corrected_value = value.replace(',', ':')

    elif 'h' in value:

        corrected_value = value.replace('h', ':')

    return corrected_value


0
Avatar
Descartar
Avatar
Savya Sachin
Best Answer

Hi,

Just try updating the following line of code 

​ value = corrected_value 

​self.write({field_name: value})

like this,

​self[field_name] = corrected_value

Thanks


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

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

Registrar-se
Related Posts Respostes Vistes Activitat
"Wrong value for %s: %r" % (self, value) Solved
onchange
Avatar
Avatar
2
d’oct. 23
3136
How to add domain in onchange function for a One2many field Solved
onchange
Avatar
Avatar
Avatar
2
d’ag. 23
5366
How to create dynamic domain on many2one fields with onchange function? Solved
onchange
Avatar
Avatar
Avatar
Avatar
Avatar
4
d’ag. 23
21829
Odoo onchange method is not saving values in readonly fields Solved
onchange
Avatar
Avatar
Avatar
Avatar
3
d’oct. 22
12228
How to add records to one2many field using onchange event Solved
onchange
Avatar
Avatar
Avatar
Avatar
3
de març 22
38251
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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