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

How can I show a warning message?

Abonare

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

Această întrebare a fost marcată
12 Răspunsuri
63675 Vizualizări
Imagine profil
Juan Formoso Vasco

I added a function to a model, to set the default value of a field:

_defaults = {
    'template_id': _my_function,
}

In that function, I check some conditions and return the value. In one of those conditions, I have to show a warning message before returning the value. How to do this without stopping the normal execution of the program?

For example, the option warning does this:

'warning': {
    'title': _('Warning'),
    'message': _('My warning message.')
}

But it must be used in a return, and in this case, because of the function is called from defaults, it can't return a dictionary with a warning, but the value of the template_id.

The orm/osv exceptions make the following window a blank popup, I only want to notify some aspect to the user and then leave them working as if nothing had happened. In summary, how to show a simple info message?

Does anyone know it, please? 

0
Imagine profil
Abandonează
Ludo - 21South

By default this would not be possible. I have thought about the same thing before, so I will watch this issue closely for a fix of some sort.

Ludo - 21South

By the way: A very dirty hack would be fire up a wizard which can have a cancel button as well as a regular "ok" button to continue with the flow.

Juan Formoso Vasco
Autor

Thank you Ludo! If I tried to do the hack you tell me, how can I fire up a wizard inside a function which is called from _defaults? I mean, the only way I know to fire up a wizard in python is through the return, so if I do that, it will generate an error because I'm not returning a right default value for the field, but a form.

Ivan

Juan, the problem is that when _defaults is called, it does not have to be from the UI. It can be from a cron job, etc. So, in a way, there is no guarantee you have a UI when _defaults is called. Is there any way that you can default the value of the field from another way that is guaranteed have UI? One example is the on_change which already has the warning mechanism.

Juan Formoso Vasco
Autor

The field I am trying to load its default value is a selection field. Do you mean this? Adding a new variable to the context in the function called from _defaults, and modifying its onchange method to show there the warning depending on the new variable added to the context?

Ivan

Juan, what I mean is that _defaults can be called even if it is not triggered from a UI component. _defaults will be called if the copy_data() or create() method is called. So, if you have a cron job or workflow that creates that model, it will call _defaults. In those situation the warning cannot be prompted. So, I think you need to find another way to defaulting the value of the field this if you insist on prompting the warning. I'm not sure what will work until you can describe how you're going to use template_id field and what conditions are you checking.

Ludo - 21South

John Doe is absolutely right here. The defaults can be called from everywhere in the code. If you want something specifically for the GUI, consider using on_change methods on your fields to give the desired effects.

Juan Formoso Vasco
Autor

Ok. Thank you both of you!

Imagine profil
Lucio
Cel mai bun răspuns

I would recommend doing an onchange function on the field template_id and check the value returned there. 
The function for the onchange will be called for the default value and there you will be able to return the desired warning message.

I do not know if you are working on V7 or V8, for simplicity i will state the solution for v8 you can just do something like:

@api.onchange('template_id')
@api.multi
def onchange_template_id(self):
    res = {}
    if <do your checks here>:
        res = {'warning': {
            'title': _('Warning'),
            'message': _('My warning message.')
        }
    if res:
        return res

Hope this helps!

 

9
Imagine profil
Abandonează
Juan Formoso Vasco
Autor

Hi! I'm working on v7. I'm going to try this right now, and I'll comment you the result. Thank you!

Juan Formoso Vasco
Autor

That's great Lucio! However, if I update the context in _my_function (called from _defaults) to add a variable to check in onchange, it doesn't appear here, and I can't check if I have to show the warning or not. I need to pass that variable from _defaults to the onchange.

Nimesh Jadav

That's not working in the mine, V13

Dimas Aditya Kristianto

this is working on V16

Imagine profil
Cristhian Carreno
Cel mai bun răspuns
Test ODOO 12

@api.onchange('field')
def my_function(self):

	#### CODE

	#### ASSIGN VALUE

        return {
            'value': {'other_id': arr_est},
            'warning': {'title': "Warning", 'message': "What is this?"},
        }

    #### OR APPLY DOMAIN

 		return {
		    'domain': {'other_id': [('partner_id', '=', partner_id)]},
		    'warning': {'title': "Warning", 'message': "What is this?"},
		}
0
Imagine profil
Abandonează
M M Shahriar Amin

how can I make the text color red ??

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
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