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

Call a global variable on create method returns always null value. What's wrong?

Abonare

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

Această întrebare a fost marcată
createvariablesOdoo12.0
1 Răspunde
8972 Vizualizări
Imagine profil
Paulo Matos

Hello everyone,

Another newbie question related to Odoo v12.

I need to get the current fields values while creating a new record (create method).

Since I am having some problems doing it and could not find any solution, I am trying to use a global variable for this. The global variable (var_field_value) is set on the top of the module.py outside all classes.

I have tried to use "self.field_name" on create method and it is not working. For instance:

var_field_value = 0
class test (models.Model):
field_name = fields.Integer('Field Value')

On the form view for the class, I enter any integer value to the field_name field.

If I print the field value on the on_change method, I can see the value is there and I can set this value to my global variable:

@api.onchange('field_name')
def onchange_field_name(self):
        print(self.field_name)
        var_field_value = self.field_name
        print(var_field_value)

Until this point, everything runs fine.

Now, on Create method, if I print both "self.field_name" and "var_field_value", the values are 0 for both.

@api.model
def create(self, vals):
    print(var_field_value)
print(self.field_name)
...

So, I can see the variable and field values on on_change event, but I cannot see them on create method.

How can I get the current field values on create method?

Thank you in advance


0
Imagine profil
Abandonează
Sehrish

Odoo Methods (Create, Write, Unlink): http://learnopenerp.blogspot.com/2017/11/how-to-override-odoo-functions.html

Imagine profil
faOtools
Cel mai bun răspuns

Hi,

in the onchange method Odoo reads values from the form, in the create method from PostgreSQL. Since in create SQL update is not yet done, self.FIELD returns False.

To get the real field value you can do one of the following:

  1. vals.get('field_name'): all fields values to be created are within the vals dictionary

  2. firstly make super of create, and then apply to the field value you currently do 

1
Imagine profil
Abandonează
Paulo Matos
Autor

Great @Odoo Tools. I was able to solve it using the first option.

The code I have used is:

@api.model

def create(self, vals):

if vals.get('field_name') <=0:

#Desired code here

return super(mymodel, self).create(vals)

Using this approach as per your instructions, I am able to get the value of field_name on the create method.

Thank you once again

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
Related Posts Răspunsuri Vizualizări Activitate
Custom Dashboard using js
Odoo12.0
Imagine profil
Imagine profil
1
apr. 25
4660
Create new bug
create
Imagine profil
0
apr. 24
2948
How to Limit Pos Category in Odoo 12 Shop?
Odoo12.0
Imagine profil
0
mar. 24
1982
Why is the product_id initiated by default_product_id is NOT available during saving.
Odoo12.0
Imagine profil
0
oct. 22
3131
compare the lines in one2many fields
Odoo12.0
Imagine profil
0
sept. 22
2462
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