Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Artificial Intelligence
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Property Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

trying to auto correct a wrong users value

Naroči se

Get notified when there's activity on this post

This question has been flagged
onchange
1 Odgovori
4088 Prikazi
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
Opusti
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
Opusti
Enjoying the discussion? Don't just read, join in!

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

Prijavi
Related Posts Odgovori Prikazi Aktivnost
"Wrong value for %s: %r" % (self, value) Solved
onchange
Avatar
Avatar
2
okt. 23
4351
How to add domain in onchange function for a One2many field Solved
onchange
Avatar
Avatar
Avatar
2
avg. 23
6604
How to create dynamic domain on many2one fields with onchange function? Solved
onchange
Avatar
Avatar
Avatar
Avatar
Avatar
4
avg. 23
23387
Odoo onchange method is not saving values in readonly fields Solved
onchange
Avatar
Avatar
Avatar
Avatar
3
okt. 22
13858
How to add records to one2many field using onchange event Solved
onchange
Avatar
Avatar
Avatar
Avatar
3
mar. 22
39565
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة 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 Svenska ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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