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

Issue with pass value from mode B into one2many field using dictionary of model A? (Odoo 13)

Iscriviti

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

La domanda è stata contrassegnata
treeviewdictionaryone2many_listOdoo13one2manyfield
3 Risposte
4986 Visualizzazioni
Avatar
Leon

Hello,

I'm trying to pass values and show the records from the form view of model_b.py into one2many field notebook in the form view of model_a.py by wizard.


model_b.py  like this:

def accept(self):

        lstd = {

            'name': self.name.id,

            'thamchieu': self.id,

            'thoigian': self.thoigian,

            'bhxh': self.bhxh,

            'bhtn': self.bhtn,

            'bhxh_mucdongnld': self.bhxh_mucdongnld,

            'bhxh_mucdongcty': self.bhxh_mucdongcty,

            'bhtn_mucdongnld': self.bhtn_mucdongnld,

            'bhtn_mucdongcty': self.bhtn_mucdongcty,

            'bhyt_mucdongnld': self.bhyt_mucdongnld,

            'bhyt_mucdongcty': self.bhyt_mucdongcty

        }

        ls_dc = self.env['model.a']

        ls_dc = ls_dc.write({'lstd_baohiem':[(0,0,{lstd})]})


XML of one2many tree view in the form view of an user's model_a.py like this:

<notebook>

                            <page name="bao_hiem_lich_su" string="Lịch Sử Thay Đổi">

                                <field name="lstd_baohiem">

                                    <tree>

                                        <field name="thoigian"/>

                                        <field name="bhxh" string="M.Đ BHXH"/>

                                        <field name="bhtn" string="M.Đ BHTN"/>

                                        <field name="bhxh_mucdongnld"/>

                                        <field name="bhxh_mucdongcty"/>

                                        <field name="bhyt_mucdongnld"/>

                                        <field name="bhyt_mucdongcty"/>

                                        <field name="bhtn_mucdongnld"/>

                                        <field name="bhtn_mucdongcty"/>

                                        <field name="loai"/>

                                        <field name="thamchieu"/>

                                    </tree>

                                </field>

</page>

</notebook>


After clicking the button 'Accept'. I got the issue like that:

Odoo Server Error
Traceback (most recent call last):
  File "/home/odoo/src/odoo/odoo/http.py", line 624, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/home/odoo/src/odoo/odoo/http.py", line 310, in _handle_exception
    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
  File "/home/odoo/src/odoo/odoo/tools/pycompat.py", line 14, in reraise
    raise value
  File "/home/odoo/src/odoo/odoo/http.py", line 669, in dispatch
    result = self._call_function(**self.params)
  File "/home/odoo/src/odoo/odoo/http.py", line 350, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/home/odoo/src/odoo/odoo/service/model.py", line 94, in wrapper
    return f(dbname, *args, **kwargs)
  File "/home/odoo/src/odoo/odoo/http.py", line 339, in checked_call
    result = self.endpoint(*a, **kw)
  File "/home/odoo/src/odoo/odoo/http.py", line 915, in __call__
    return self.method(*args, **kw)
  File "/home/odoo/src/odoo/odoo/http.py", line 515, in response_wrap
    response = f(*args, **kw)
  File "/home/odoo/src/odoo/addons/web/controllers/main.py", line 1331, in call_button
    action = self._call_kw(model, method, args, kwargs)
  File "/home/odoo/src/odoo/addons/web/controllers/main.py", line 1319, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/home/odoo/src/odoo/odoo/api.py", line 387, in call_kw
    result = _call_kw_multi(method, model, args, kwargs)
  File "/home/odoo/src/odoo/odoo/api.py", line 374, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "/home/odoo/src/odoo/addons/baohiem/models/dieu_chinh.py", line 128, in chapthuan
    ls_dc = ls_dc.write({'lstd_baohiem':[(0,0,{lstd})]})
TypeError: unhashable type: 'dict'

What am I doing wrong?

Please help!

Thank you!

0
Avatar
Abbandona
Avatar
Jaga
Risposta migliore


(0, 0, { values }) link to a new record that needs to be created with the given values dictionary (1, ID, { values }) update the linked record with id = ID (write *values* on it) (2, ID) remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well) (3, ID) cut the link to the linked record with id = ID (delete the relationship between the two objects but does not delete the target object itself) (4, ID) link to existing record with id = ID (adds a relationship) (5) unlink all (like using (3,ID) for all linked records) (6, 0, [IDs]) replace the list of linked IDs (like using (5) then (4,ID) for each ID in the list of IDs)

Check the above format,Confirm the error comes in some extra brackets or wrong rules you defined.

Example :

check the link

https://www.odoo.com/forum/help-1/not-able-to-write-datas-in-res-partner-res-partner-category-rel-table-182270

0
Avatar
Abbandona
Avatar
Leon
Autore Risposta migliore

Hello Mohamed,

Yes, I connect with model_c.py by creating a one2many field ('lstd_baohiem'), cause I want to put the tree view of model_c.py in the form view of a user of model_a.py. 

But model_c.py and model_b.py have connected by the relationship with one2many (model_b.py) and many2one (model_c.py). And I have done to pass all the value from model_b.py to the tree view of model_c.py via the KEY field of model_b.py:

reference = fields.Char('Reference')

Back to the model_a.py. I do not know how to create a many2one field for model_c.py to connect with one2many of model_a.py. 

Because the KEY field is 'reference' in model_b.py. That's the KEY field for 3 models not 2.

So that why I'm trying to copy or pass all values of the model_b.py by using dictionary like that. But still no sucess.

0
Avatar
Abbandona
Avatar
Mohammed Zubair
Risposta migliore

You can prepare values same like above and add model_b 'id' in Many2one field too.

Write: model_b.create(values) method if you have already model_a record is created.

After that you can see the newly created record gets added in One2many field.

0
Avatar
Abbandona
Leon
Autore

Hi Mohammed. Cause I created one2many field: lstd_baohiem from... model C not model B. So you mean that I must have created a relation one2many from model.b.py and many2one from model.a.py!?

Mohammed Zubair

Let you have Model_a, Model_b and Model_c. Now you have relation between Model_a and Model_b as One2many and Many2one respectively. According to your above code, I can understand that you have field 'lstd_baohiem' in Model_a. That means, relation of One2many with Model_c and Model_a as Many2one, right?

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à
key = 'default_' + name TypeError: must be str, not int (Odoo 13)
treeview many2one one2many one2many_list Odoo13
Avatar
0
feb 21
4552
How to pass values and create the records for field name according to the selection in one2many tree view? (Odoo 13)
many2one one2many_list Odoo13
Avatar
Avatar
1
apr 25
4666
​OdooV13 : Hierarchical Tree view in Odoo 13?​
treeview hierarchy Odoo13
Avatar
Avatar
1
mar 22
6958
Raise warning when there is no select record via "Add a line" in one2many tree view!? (Odoo 13) Risolto
one2many warning one2many_list Odoo13
Avatar
Avatar
Avatar
3
mar 21
6125
Is it possible to display data in a list view of a one2many field grouped by a field in Odoo 13 Risolto
treeview one2many one2many_list odoo13
Avatar
Avatar
1
set 20
8800
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