Zum Inhalt springen
Odoo Menü
  • Anmelden
  • Jetzt gratis testen
  • Apps
    Finanzen
    • Buchhaltung
    • Rechnungsstellung
    • Spesenabrechnung
    • Tabellenkalkulation (BI)
    • Dokumente
    • E-Signatur
    Vertrieb
    • CRM
    • Vertrieb
    • Kassensystem – Shop
    • Kassensystem – Restaurant
    • Abonnements
    • Vermietung
    Websites
    • Website-Builder
    • E-Commerce
    • Blog
    • Forum
    • Livechat
    • E-Learning
    Lieferkette
    • Lager
    • Fertigung
    • PLM
    • Einkauf
    • Wartung
    • Qualität
    Personalwesen
    • Mitarbeiter
    • Personalbeschaffung
    • Abwesenheiten
    • Mitarbeiterbeurteilung
    • Personalempfehlungen
    • Fuhrpark
    Marketing-
    • Social Marketing
    • E-Mail-Marketing
    • SMS-Marketing
    • Veranstaltungen
    • Marketing-Automatisierung
    • Umfragen
    Dienstleistungen
    • Projekte
    • Zeiterfassung
    • Außendienst
    • Kundendienst
    • Planung
    • Termine
    Produktivität
    • Dialog
    • Genehmigungen
    • IoT
    • VoIP
    • Wissensdatenbank
    • WhatsApp
    Apps von Drittanbietern Odoo Studio Odoo Cloud-Plattform
  • Branchen
    Einzelhandel
    • Buchladen
    • Kleidergeschäft
    • Möbelhaus
    • Lebensmittelgeschäft
    • Baumarkt
    • Spielwarengeschäft
    Essen & Gastgewerbe
    • Bar und Kneipe
    • Restaurant
    • Fast Food
    • Gästehaus
    • Getränkehändler
    • Hotel
    Immobilien
    • Immobilienagentur
    • Architekturbüro
    • Baugewerbe
    • Immobilienverwaltung
    • Gartenarbeit
    • Eigentümervereinigung
    Beratung
    • Buchhaltungsfirma
    • Odoo-Partner
    • Marketingagentur
    • Anwaltskanzlei
    • Talentakquise
    • Prüfung & Zertifizierung
    Fertigung
    • Textil
    • Metall
    • Möbel
    • Speisen
    • Brauerei
    • Firmengeschenke
    Gesundheit & Fitness
    • Sportklub
    • Brillengeschäft
    • Fitnessstudio
    • Therapeut
    • Apotheke
    • Friseursalon
    Handel
    • Handyman
    • IT-Hardware & -Support
    • Solarenergiesysteme
    • Schuster
    • Reinigungsdienstleistungen
    • HLK-Dienstleistungen
    Sonstiges
    • Gemeinnützige Organisation
    • Umweltschutzagentur
    • Plakatwandvermietung
    • Fotostudio
    • Fahrrad-Leasing
    • Software-Händler
    Alle Branchen ansehen
  • Community
    Lernen
    • Tutorials
    • Dokumentation
    • Zertifizierungen
    • Schulung
    • Blog
    • Podcast
    Bildung fördern
    • Bildungsprogramm
    • Scale-Up! Planspiel
    • Odoo besuchen
    Software anfragen
    • Herunterladen
    • Editionen vergleichen
    • Releases
    Zusammenarbeiten
    • Github
    • Forum
    • Veranstaltungen
    • Übersetzungen
    • Partner werden
    • Dienstleistungen für Partner
    • Buchhaltungsfirma registrieren
    Services anfragen
    • Partner finden
    • Buchhalter finden
    • Einen Experten treffen
    • Implementierungsservices
    • Kundenreferenzen
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Eine Demo erhalten
  • Preiskalkulation
  • Hilfe

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

  • CRM
  • e-Commerce
  • Buchhaltung
  • Lager
  • PoS
  • Projekte
  • MRP
All apps
Sie müssen registriert sein, um mit der Community zu interagieren.
Alle Beiträge Personen Abzeichen
Stichwörter (Alle anzeigen)
odoo accounting v14 pos v15
Über dieses Forum
Sie müssen registriert sein, um mit der Community zu interagieren.
Alle Beiträge Personen Abzeichen
Stichwörter (Alle anzeigen)
odoo accounting v14 pos v15
Über dieses Forum
Hilfe

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

Abonnieren

Erhalten Sie eine Benachrichtigung, wenn es eine Aktivität zu diesem Beitrag gibt

Diese Frage wurde gekennzeichnet
treeviewdictionaryone2many_listOdoo13one2manyfield
3 Antworten
4990 Ansichten
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
Verwerfen
Avatar
Jaga
Beste Antwort


(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
Verwerfen
Avatar
Leon
Autor Beste Antwort

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
Verwerfen
Avatar
Mohammed Zubair
Beste Antwort

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
Verwerfen
Leon
Autor

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?

Diskutieren Sie gerne? Treten Sie bei, statt nur zu lesen!

Erstellen Sie heute ein Konto, um exklusive Funktionen zu nutzen und mit unserer tollen Community zu interagieren!

Registrieren
Verknüpfte Beiträge Antworten Ansichten Aktivität
key = 'default_' + name TypeError: must be str, not int (Odoo 13)
treeview many2one one2many one2many_list Odoo13
Avatar
0
Feb. 21
4553
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
März 22
6960
Raise warning when there is no select record via "Add a line" in one2many tree view!? (Odoo 13) Gelöst
one2many warning one2many_list Odoo13
Avatar
Avatar
Avatar
3
März 21
6129
Is it possible to display data in a list view of a one2many field grouped by a field in Odoo 13 Gelöst
treeview one2many one2many_list odoo13
Avatar
Avatar
1
Sept. 20
8802
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Herunterladen
  • Github
  • Runbot
  • Übersetzungen
Dienstleistungen
  • Odoo.sh-Hosting
  • Support
  • Upgrade
  • Individuelle Entwicklungen
  • Bildung
  • Buchhalter finden
  • Partner finden
  • Partner werden
Über uns
  • Unsere Firma
  • Markenwerte
  • Kontakt
  • Karriere
  • Veranstaltungen
  • Podcast
  • Blog
  • Kunden
  • Rechtliches • Datenschutz
  • Sicherheit
الْعَرَبيّة 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 ist eine Suite von Open-Source-Betriebsanwendungen, die alle Bedürfnisse Ihres Unternehmens abdecken: CRM, E-Commerce, Buchhaltung, Lager, Kassensystem, Projektmanagement etc.

Das einzigartige Wertversprechen von Odoo ist, dass es gleichzeitig sehr einfach zu bedienen und voll integriert ist.

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