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

calling other model method in a computed field shows 0/no value until save

Iscriviti

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

La domanda è stata contrassegnata
python2.7Odoo10.0
3 Risposte
10290 Visualizzazioni
Avatar
Samo Arko

I have a one2many relation where the many end model has a selection field and a method that computes a value from the selection and some other values and then returns the computed value and uses it for calculation with the values of dependent fields. (tried onchange, same result)

The problem is when I get values this way for my computed fields in my tree view with option editable="bottom" it computes the correct value when I press save, but when edit the record fields of any dependent field the value just becomes 0, until I save it again and only then the correct value is displayed.

I want it to show the the computed value when changing the dependent fields just like if I only use field values and not methods.

Is this possible? If yes an example would be nice, if not... at least I don't waste my time with it and have to try different approach.

And getting the value from fields and calculate it in the same model is a NO GO, the method uses some stuff that cannot be hard coded but it has to be dependant on user input.

0
Avatar
Abbandona
Avatar
Samo Arko
Autore Risposta migliore

Did a work around. Now it works but I have to have 2 nearly identical functions that do the exactly same thing in two models.

The main problem was that I haven't found a way to pass the object state to other module. So every time the dependent fields triggered the the compute method that called the method in the other model that method fetched the data form the database record so that's why the the computed field didn't change or had a 0 value and it showed the correct value only after saving.

Now I call the record with the selection and stored expression from the 1st model, change the variables that are in the expression with the appropriate values and then I call the 2nd models method for calculating. Before the method for calculation changed the variables with values.

0
Avatar
Abbandona
Avatar
Hilar Andikkadavath
Risposta migliore

You can use the @api.depends , it will do the onchange function too. whenever a change in the field specified in depends function, it will trigger the defined function and returns the result.

@api.multi
@api.depends('name', 'state')
def name_get(self):
result = []
for move in self:
if move.state == 'draft':
name = '* ' + str(move.id)
else:
name = move.name
result.append((move.id, name))
return result


Here is an example, here if ther is any change in the fields name, state will trigger the function. Here you can also use the fields names as 

@api.depends('debit', 'credit', 'move_id.matched_percentage', 'move_id.journal_id')

Here move_id can be a many2x or one2x field



3
Avatar
Abbandona
Samo Arko
Autore

Nope... this is not the answer. As I stated in the 1st paragraph "calculation with the values of dependent fields" that means that I used @api.depends. The "dependant" fields are the ones that are in the brackets "@api.depends( in here )". The method is in the other model. I know how to do such simple methods that you put into the example and as I stated the data is in different models that has to be collected by the method in the One2Many (on the many end side of relation) model. Thank you for trying to help but I see that you didn't read the whole question or didn't understand it. So please deselect your answer as the correct one!

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à
How to connect two odoo 10 servers.
python2.7 Odoo10.0
Avatar
Avatar
Avatar
2
dic 23
3487
How to call JavaScript function from Python model.py oodo 10.0
javascript python2.7 Odoo10.0
Avatar
Avatar
1
lug 18
9418
Error occurred during the installation of loan management(V6.1) module in V7.0
python2.7
Avatar
Avatar
Avatar
Avatar
3
ott 23
6813
Readonly field disappears when saved in odoo 10.
Odoo10.0
Avatar
Avatar
1
mar 23
3238
How to write a python function called automatically?
python2.7
Avatar
Avatar
Avatar
2
gen 23
6255
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