Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Food & Hospitality
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brewery
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Trades
    • Bricoleur
    • Matériel informatique et support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Browse all Industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services for Partners
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

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

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

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

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
treeviewdictionaryone2many_listOdoo13one2manyfield
3 Réponses
4987 Vues
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
Ignorer
Avatar
Jaga
Meilleure réponse


(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
Ignorer
Avatar
Leon
Auteur Meilleure réponse

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
Ignorer
Avatar
Mohammed Zubair
Meilleure réponse

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
Ignorer
Leon
Auteur

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?

Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Publications associées Réponses Vues Activité
key = 'default_' + name TypeError: must be str, not int (Odoo 13)
treeview many2one one2many one2many_list Odoo13
Avatar
0
févr. 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
avr. 25
4666
​OdooV13 : Hierarchical Tree view in Odoo 13?​
treeview hierarchy Odoo13
Avatar
Avatar
1
mars 22
6958
Raise warning when there is no select record via "Add a line" in one2many tree view!? (Odoo 13) Résolu
one2many warning one2many_list Odoo13
Avatar
Avatar
Avatar
3
mars 21
6125
Is it possible to display data in a list view of a one2many field grouped by a field in Odoo 13 Résolu
treeview one2many one2many_list odoo13
Avatar
Avatar
1
sept. 20
8800
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenez partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة 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 est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

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