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

Duplicated records in DB after adding record via form view in Odoo 14

S'inscrire

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

Cette question a été signalée
viewcustommodelduplicationv14
1 Répondre
5362 Vues
Avatar
Angelina

Hello!

I have a form view with two buttons. One button – Create (type=object) – should add a record to DB. Second one – View (type=action) – should open tree view with all created records.

The problem is that Create button adds two similar records to DB and View button opens tree view and also adds one record to DB. View button doesn’t even use method from my model.

What can be a problem with duplication of records?

Odoo v14

Here is the code

Views:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
    
    <!-- ADD BUTTON TO SETTINGS -->

    <record id="res_config_settings_layouts_view_form" model="ir.ui.view">
            <field name="name">res.config.settings.layouts.view.form.inherit.base.setup</field>
            <field name="model">res.config.settings</field>
            <field name="inherit_id" ref="base_setup.res_config_settings_view_form"/>
            <field name="arch" type="xml">
                <xpath expr="//div[@id='business_documents']" position="inside">    
                    
                    <div class="row mt16 o_settings_container" name="business_documents_setting_container">
                        <div class="col-12 col-lg-6 o_setting_box" id="paper_format_setting">
                            <div class="o_setting_right_pane">
                                <span class="o_form_label">Configurable Layouts</span>
                                <div class="text-muted">
                                    Set layouts for printed documents
                                </div>
                                <div class="content-group">
                                    <div class="mt8">
                                        <button name="%(custom_layouts.action_custom_layout_configurator)d" string="Layouts Settings" type="action" class="oe_link" icon="fa-arrow-right"/>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                </xpath>
            </field>
        </record>

    <!-- FORM VIEW -->

    <record id="view_custom_layouts_form" model="ir.ui.view">
            <field name="name">document.custom.layouts</field>
            <field name="model">custom.layouts</field>
            <field name="arch" type="xml">
                <form string="Select something to som..." create="false" edit="false">
                    <group>
                        <field name="report_layout_id"/>
                        <field name="paperformat_id"/>
                    </group>
                    <div>
                        <button string="Add this" name="add_linked_docs" type="object" class="btn btn-primary"/>
                        <button string="View" name="%(custom_layouts.action_custom_layout_list)d" type="action" class="btn btn-seconadry ml-2"/>
                    </div>
                </form>
            </field>
        </record>

        <record id="action_custom_layout_configurator" model="ir.actions.act_window">
            <field name="name">Configure your document layout</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">custom.layouts</field>
            <field name="view_mode">form</field>
            <field name="target">new</field>
            <field name="view_id" ref="custom_layouts.view_custom_layouts_form"/>
        </record>
        
    <!-- TREE VIEW -->

        <record id="view_custom_layouts_tree" model="ir.ui.view">
            <field name="name">document.custom.layouts.tree</field>
            <field name="model">custom.layouts</field>
            <field name="arch" type="xml">
                <tree string="Tree" create="false" edit="false">
                    <field name="id"/>
                    <field name="report_layout_id"/>
                    <field name="paperformat_id"/>
                </tree>
            </field>
        </record>

        <record id="action_custom_layout_list" model="ir.actions.act_window">
            <field name="name">Review the list</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">custom.layouts</field>
            <field name="target">new</field>
            <field name="view_mode">tree</field>
            <field name="context">{'group_by': ['report_layout_id']}</field>
            <field name="view_id" ref="custom_layouts.view_custom_layouts_tree"/>
        </record>

    </data>
</odoo>

Model


from odoo import api, fields, models, _

class SetCustomLayouts(models.Model):
    _name = 'custom.layouts'
    _description = 'Document Layout settings'
    # _order = 'report_layout_id'

    report_layout_id = fields.Many2one('report.layout')
    paperformat_id = fields.Many2one('ir.actions.report', string="Report")

    def add_linked_docs(self):
        vals = {
            'report_layout_id' : self.report_layout_id.id,
            'paperformat_id' : self.paperformat_id.id
        }
        self.create(vals)

Form view


result


1
Avatar
Ignorer
Avatar
Angelina
Auteur Meilleure réponse

Fixed.

There should be two separate models - one Transient for creation, and one Model to store data.

0
Avatar
Ignorer
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é
Field does not exists on model error when upgrading custom modules in Odoo 16
error view custom model odoo16features
Avatar
Avatar
Avatar
2
juil. 23
7870
How can I change the list view for a custom model?
view custom list change model
Avatar
Avatar
1
mars 15
12898
Custom model - avoid deleting values when in use Résolu
custom model
Avatar
Avatar
2
mars 22
3657
Transfer data from model to arch view
view model arch
Avatar
Avatar
2
avr. 24
2035
Odoo 14: At least one model cache has been invalidated, signaling through the database Résolu
error model v14
Avatar
Avatar
1
mai 23
19271
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