Skip to Content
Odoo Menu
  • Prisijungti
  • Išbandykite nemokamai
  • Programėlės
    Finansai
    • Apskaita
    • Pateikimas apmokėjimui
    • Sąnaudos
    • Skaičiuoklė (BI)
    • Dokumentai
    • Pasirašymas
    Pardavimai
    • CRM
    • Pardavimai
    • Kasų sistema - Parduotuvė
    • Kasų sistema - Restoranas
    • Prenumeratos
    • Nuoma
    Svetainės
    • Svetainių kūrėjimo įrankis
    • El. Prekyba
    • Internetinis Tinklaraštis
    • Forumas
    • Tiesioginis pokalbis
    • eMokymasis
    Tiekimo grandinė
    • Atsarga
    • Gamyba
    • PLM
    • Įsigijimai
    • Priežiūra
    • Kokybė
    Žmogaus ištekliai
    • Darbuotojai
    • Įdarbinimas
    • Atostogos
    • Įvertinimai
    • Rekomendacijos
    • Transporto priemonės
    Rinkodara
    • Socialinė rinkodara
    • Rinkodara el. paštu
    • SMS rinkodara
    • Renginiai
    • Rinkodaros automatizavimas
    • Apklausos
    Paslaugos
    • Projektas
    • Darbo laiko žiniaraščiai
    • Priežiūros tarnyba
    • Pagalbos tarnyba
    • Planavimas
    • Rezervacijos
    Produktyvumas
    • Diskucija
    • Patvirtinimai
    • IoT
    • VoIP
    • Žinių biblioteka
    • WhatsApp
    Trečiųjų šalių programos Odoo Studija Odoo debesijos platforma
  • Pramonės šakos
    Mažmeninė prekyba
    • Knygynas
    • Drabužių parduotuvė
    • Baldų parduotuvė
    • Maisto prekių parduotuvė
    • Techninės įrangos parduotuvė
    • Žaislų parduotuvė
    Food & Hospitality
    • Barai ir pub'ai
    • Restoranas
    • Greitasis maistas
    • Guest House
    • Gėrimų platintojas
    • Hotel
    Nekilnojamasis turtas
    • Real Estate Agency
    • Architektūros įmonė
    • Konstrukcija
    • Estate Managament
    • Sodininkauti
    • Turto savininkų asociacija
    Konsultavimas
    • Accounting Firm
    • Odoo Partneris
    • Marketing Agency
    • Teisinė firma
    • Talentų paieška
    • Auditai & sertifikavimas
    Gamyba
    • Textile
    • Metal
    • Furnitures
    • Maistas
    • Brewery
    • Įmonių dovanos
    Sveikata & Fitnesas
    • Sporto klubas
    • Akinių parduotuvė
    • Fitneso Centras
    • Sveikatos praktikai
    • Vaistinė
    • Kirpėjas
    Trades
    • Handyman
    • IT įranga ir palaikymas
    • Saulės energijos sistemos
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Kiti
    • Nonprofit Organization
    • Aplinkos agentūra
    • Reklaminių stendų nuoma
    • Fotografavimas
    • Dviračių nuoma
    • Programinės įrangos perpardavėjas
    Browse all Industries
  • Bendrija
    Mokykitės
    • Mokomosios medžiagos
    • Dokumentacija
    • Sertifikatai
    • Mokymai
    • Internetinis Tinklaraštis
    • Tinklalaidės
    Skatinkite švietinimą
    • Švietimo programa
    • Scale Up! Verslo žaidimas
    • Aplankykite Odoo
    Gaukite programinę įrangą
    • Atsisiųsti
    • Palyginkite versijas
    • Leidimai
    Bendradarbiauti
    • Github
    • Forumas
    • Renginiai
    • Vertimai
    • Tapkite partneriu
    • Services for Partners
    • Registruokite jūsų apskaitos įmonę
    Gaukite paslaugas
    • Susiraskite partnerį
    • Susirask buhalterį
    • Susitikti su konsultantu
    • Diegimo paslaugos
    • Klientų rekomendavimas
    • Palaikymas
    • Atnaujinimai
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Gaukite demo
  • Kainodara
  • Pagalba

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

  • CRM
  • e-Commerce
  • Apskaita
  • Atsarga
  • PoS
  • Projektas
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
Pagalba

The value of the onchange function shows up in the form but does not save in the database.

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
on_changeodoo8.0
4 Replies
14257 Rodiniai
Portretas
Anand Prasanth

I have an age calculation function (onchange) and it calculates and shows up in the form when I enter the data. But the data is not saved in the data base. Please help with the code.


    @api.onchange('dob')

     def onchange_age_calculate(self):

      if not self.dob:

       self.age = 0

     else:

      today_date = datetime.datetime.now().year

      date_split = self.dob.split('-',1)

      birth_year = date_split[0]

      self.age = today_date -int(birth_year)


    _columns = {

                'name': fields.char(string="Name"), 

                'dob' : fields.date('Date of Birth'),

                'age' : fields.float( string='Age')


I have imported date time and the required library files hope so

1
Portretas
Atmesti
Sehrish

Reference: https://learnopenerp.blogspot.com/2021/10/onchange-method-readonly-field-not-store-database-odoo.html

Portretas
Axel Mendoza
Best Answer

That could be happening if you declare readonly the field age in the view. The readonly fields are not saved into the database even when they change their value through an onchange. To solve just remove the readonly attr or recalculate it in the create/write method of your model or define it as an computed field. There are solutions to send the readonly fields to the create/write methods but it's not out of the box

3
Portretas
Atmesti
Portretas
ayman mohammed adam
Best Answer

hello try this


   @api.onchange('dob')

   @api.depends('dob')

     def onchange_age_calculate(self):

      if not self.dob:

       self.age = 0

     else:

      today_date = datetime.datetime.now().year

      date_split = self.dob.split('-',1)

      birth_year = date_split[0]

      self.age = today_date -int(birth_year)

 

      name=  fields.Char(string="Name"), 

      dob' = fields.Date('Date of Birth'),

      age= fields.Float( string='Age')



then replace your class like this

class your_class_name(models.Model):


Thanks and I hoped i help you.

0
Portretas
Atmesti
Portretas
Pawan
Best Answer

Anand,

As axel said you cant store readonly values in DB, i got some workout around it to do that..

To store readonly values also in future, u can have a little modification at your js part:

at wed/static/src/js/views/view_form.js        under FormView class, at method '_process_save()'

approx at line# 873, under "else if (f.name !== 'id' && (!self.datarecord.id || f._dirty_flag))"

replace the code with below one....

else if (f.name !== 'id' && (!self.datarecord.id || f._dirty_flag)){

//commenting below lines to allow sotring readonly values also

// if (!f.get("readonly")) {

               // values[f.name] = f.get_value(true);

    // } else {

            // readonly_values[f.name] = f.get_value(true);

    // }

    values[f.name] = f.get_value();

     if (f.get("readonly"))

            readonly_values[f.name]= f.get_value();

}

Hope this will help you

0
Portretas
Atmesti
Portretas
Kirubanidhi Rajarathinam
Best Answer

# Specify below header file in your code:

from datetime import datetime

from dateutil import relativedelta as rdelta

from datetime import date

#create a two field in your py file

staff_dob = fields.Date(string="Date of Birth")

staff_age = fields.Integer(string="Age")

# We can use onchange method in my staff_dob field .

@api.onchange('staff_dob')

def age_cal_fun(self):

if self.staff_dob:

today = date.today()

bdate = datetime.strptime(self.staff_dob, '%Y-%m-%d')

rd = rdelta.relativedelta(today, bdate)

self.staff_age = rd.years

#Above this code is help for you

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

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

Registracija
Related Posts Replies Rodiniai Veikla
On_change: help! Solved
on_change uppercase odoo8.0
Portretas
Portretas
Portretas
2
rugp. 15
4550
how to implement joint piece in odoo 8 in one view
odoo8.0
Portretas
0
bal. 24
2647
what is the reason behind extra move? in stock
odoo8.0
Portretas
Portretas
Portretas
Portretas
4
lapkr. 23
6830
How to solve fields.function issue in odoo 8
odoo8.0
Portretas
0
spal. 23
2653
how to restrict create and delete access in one2many field tree view
odoo8.0
Portretas
0
gruod. 22
3370
Bendrija
  • Mokomosios medžiagos
  • Dokumentacija
  • Forumas
Atvirasis kodas
  • Atsisiųsti
  • Github
  • Runbot
  • Vertimai
Paslaugos
  • Odoo.sh talpinimas
  • Palaikymas
  • Atnaujinti
  • Pritaikytas programavimo kūrimas
  • Švietimas
  • Susirask buhalterį
  • Susiraskite partnerį
  • Tapkite partneriu
Apie mus
  • Mūsų įmonė
  • Prekės ženklo turtas
  • Susisiekite su mumis
  • Darbo pasiūlymai
  • Renginiai
  • Tinklalaidės
  • Internetinis Tinklaraštis
  • Klientai
  • Teisinis • Privatumas
  • Saugumas
الْعَرَبيّة 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 yra atvirojo kodo verslo programų rinkinys, kuris apima visas įmonės poreikius: CRM, El. Prekybą, Apskaitą, Atsargų, Kasų sistemą, Projektų valdymą ir kt.

Unikali Odoo vertės pasiūla – būti tuo pačiu metu labai lengvai naudojama ir visiškai integruota sistema.

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