Passa al contenuto
Odoo Menu
  • Accedi
  • Provalo gratis
  • App
    Finanze
    • Contabilità
    • Fatturazione
    • Note spese
    • Fogli di calcolo (BI)
    • Documenti
    • Firma
    Vendite
    • CRM
    • Vendite
    • Punto vendita Negozio
    • Punto vendita Ristorante
    • Abbonamenti
    • Noleggi
    Siti web
    • Configuratore sito web
    • E-commerce
    • Blog
    • Forum
    • Live chat
    • E-learning
    Supply chain
    • Magazzino
    • Produzione
    • PLM
    • Acquisti
    • Manutenzione
    • Qualità
    Risorse umane
    • Dipendenti
    • Assunzioni
    • Ferie
    • Valutazioni
    • Referral dipendenti
    • Parco veicoli
    Marketing
    • Social marketing
    • E-mail marketing
    • SMS marketing
    • Eventi
    • Marketing automation
    • Sondaggi
    Servizi
    • Progetti
    • Fogli ore
    • Assistenza sul campo
    • Helpdesk
    • Pianificazione
    • Appuntamenti
    Produttività
    • Comunicazioni
    • Approvazioni
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    App di terze parti Odoo Studio Piattaforma cloud Odoo
  • Settori
    Retail
    • Libreria
    • Negozio di abbigliamento
    • Negozio di arredamento
    • Alimentari
    • Ferramenta
    • Negozio di giocattoli
    Cibo e ospitalità
    • Bar e pub
    • Ristorante
    • Fast food
    • Pensione
    • Grossista di bevande
    • Hotel
    Agenzia immobiliare
    • Agenzia immobiliare
    • Studio di architettura
    • Edilizia
    • Gestione immobiliare
    • Impresa di giardinaggio
    • Associazione di proprietari immobiliari
    Consulenza
    • Società di contabilità
    • Partner Odoo
    • Agenzia di marketing
    • Studio legale
    • Selezione del personale
    • Audit e certificazione
    Produzione
    • Tessile
    • Metallo
    • Arredamenti
    • Alimentare
    • Birrificio
    • Ditta di regalistica aziendale
    Benessere e sport
    • Club sportivo
    • Negozio di ottica
    • Centro fitness
    • Centro benessere
    • Farmacia
    • Parrucchiere
    Commercio
    • Tuttofare
    • Hardware e assistenza IT
    • Ditta di installazione di pannelli solari
    • Calzolaio
    • Servizi di pulizia
    • Servizi di climatizzazione
    Altro
    • Organizzazione non profit
    • Ente per la tutela ambientale
    • Agenzia di cartellonistica pubblicitaria
    • Studio fotografico
    • Punto noleggio di biciclette
    • Rivenditore di software
    Carica tutti i settori
  • Community
    Apprendimento
    • Tutorial
    • Documentazione
    • Certificazioni 
    • Formazione
    • Blog
    • Podcast
    Potenzia la tua formazione
    • Programma educativo
    • Scale Up! Business Game
    • Visita Odoo
    Ottieni il software
    • Scarica
    • Versioni a confronto
    • Note di versione
    Collabora
    • Github
    • Forum
    • Eventi
    • Traduzioni
    • Diventa nostro partner
    • Servizi per partner
    • Registra la tua società di contabilità
    Ottieni servizi
    • Trova un partner
    • Trova un contabile
    • Incontra un esperto
    • Servizi di implementazione
    • Testimonianze dei clienti
    • Supporto
    • Aggiornamenti
    GitHub Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Richiedi una demo
  • Prezzi
  • Aiuto

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

  • CRM
  • e-Commerce
  • Contabilità
  • Magazzino
  • PoS
  • Progetti
  • MRP
All apps
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
Assistenza

Value returned in onchange function not reflecting in UI

Iscriviti

Ricevi una notifica quando c'è un'attività per questo post

La domanda è stata contrassegnata
ormonchangeodoo-10
2 Risposte
7467 Visualizzazioni
Avatar
sukesh

I have a simple onchange function in which I am writing to a few fields. But the value returned as "vals" isn't getting to the frontend. The values returned in the network tab for Here is the function:

	@api.multi
	@api.onchange('email')
	def onchange_email(self):
		vals = {}
		contactid = ""
		siteid = ""
		respartner = self.env['res.partner'].search([('id','=',self._origin.id)])
		for partner in respartner:
			for site in partner.company_site_lines:
				if site.company_corporate:
					site.email = self.email.upper()
					site.write({"email":self.email.upper()})
			for contact in partner.contact_ids:
				if contact.flag_first_contact:
					contactid = contact.id
					contact.email = self.email.upper()
					contact.site_email = self.email.upper()
					contact.write({'email':self.email.upper(),'site_email':self.email.upper()})
					self.write({'contact_ids':[(1,contact.id,{'email':self.email.upper(),'site_email':self.email.upper()})]})
			partner.email = self.email.upper()
			partner.write({'email':self.email.upper()})
			vals['email'] = partner.email
			vals['active_tabs'] = partner.active_tabs
			ressite = self.env['company.site'].search([('company_site_id','=',partner.id)])
			vals['contact_ids'] = self._origin.contact_ids
                        #Printing vals['contact_ids'] gives the proper one2many field with the correct id: partner.contact(475,)                         #But the output in chrome is: # {"jsonrpc": "2.0", # "id": 427040437, # "result": { # "value": { # "contact_ids": [ # [5] # ], # .
#                .
#                .
#                .     return {'value':vals} # Is there something wrong with the way I am returning Values?

0
Avatar
Abbandona
sukesh
Autore

@Prakash, (Didn't have enough karma to comment.) Yes, that can be done, but that is not what I was looking for. I was looking to return the vals.

Avatar
sukesh
Autore Risposta migliore

The reason this wasn't happening was that I was trying to save inside an onchange. The onchange function, even if you write into the object, doesn't actually completely write into the database. The issue is related to a concept called dirty fields. When you have a dirty field (i.e any field that is affected by the onchange function) before saving, Odoo doesn't support updating x2Many fields. This is why the fields weren't being passed on to the UI. 
A workaround I had for this is by making a javascript file, including the formview object and modifying the way saving works in Odoo. 
This essentially saves and performs a .reload() function which loads all the values. This modified save and .reload() function is placed inside the success function of the (Javascript) Formview onchange method. This solves my purpose, but may not solve everyone's. This issue is still in the wishlist in the official odoo repository. So it may be supported in future versions. But as of now, in odoo 8,9,10 and 11. The updating of x2Many fields in odoo through an onchange function is not supported. The comments (in odoo10) are in the odoo/models.py file on line 5511-5519. Hope this helps someone. 

0
Avatar
Abbandona
Avatar
Prakash Prajapati (ppr)
Risposta migliore

Hello Aditya , onchange method/ function are return the domain then reflection in UI.

Like: 

    @api.onchange('product_id')

    def _onchange_product_id(self):

        domain = {}

            domain['uom_id'] = "Domain....."

        return {'domain': domain}

0
Avatar
Abbandona
Ti stai godendo la conversazione? Non leggere soltanto, partecipa anche tu!

Crea un account oggi per scoprire funzionalità esclusive ed entrare a far parte della nostra fantastica community!

Registrati
Post correlati Risposte Visualizzazioni Attività
Add month to date field Risolto
date orm onchange
Avatar
Avatar
2
giu 22
18513
Update one2many record within the same view
orm onchange V13
Avatar
Avatar
1
gen 22
4053
onchange method doesn't work for new records Risolto
orm onchange odoo12
Avatar
Avatar
2
gen 19
7462
Odoo ORM Create Method Doesn't Save created Records in Treeview?
orm onchange odoo-10-Enteprise
Avatar
0
ago 17
5499
How to trigger function on object write? Risolto
addon v7 orm onchange
Avatar
Avatar
Avatar
Avatar
4
giu 20
27996
Community
  • Tutorial
  • Documentazione
  • Forum
Open source
  • Scarica
  • Github
  • Runbot
  • Traduzioni
Servizi
  • Hosting Odoo.sh
  • Supporto
  • Aggiornamenti
  • Sviluppi personalizzati
  • Formazione
  • Trova un contabile
  • Trova un partner
  • Diventa nostro partner
Chi siamo
  • La nostra azienda
  • Branding
  • Contattaci
  • Lavora con noi
  • Eventi
  • Podcast
  • Blog
  • Clienti
  • Note legali • Privacy
  • Sicurezza
الْعَرَبيّة 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 è un gestionale di applicazioni aziendali open source pensato per coprire tutte le esigenze della tua azienda: CRM, Vendite, E-commerce, Magazzino, Produzione, Fatturazione elettronica, Project Management e molto altro.

Il punto di forza di Odoo è quello di offrire un ecosistema unico di app facili da usare, intuitive e completamente integrate tra loro.

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