Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

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

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
viewcustommodelduplicationv14
1 Răspunde
5394 Vizualizări
Imagine profil
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
Imagine profil
Abandonează
Imagine profil
Angelina
Autor Cel mai bun răspuns

Fixed.

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

0
Imagine profil
Abandonează
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
Field does not exists on model error when upgrading custom modules in Odoo 16
error view custom model odoo16features
Imagine profil
Imagine profil
Imagine profil
2
iul. 23
7943
How can I change the list view for a custom model?
view custom list change model
Imagine profil
Imagine profil
1
mar. 15
12943
Custom model - avoid deleting values when in use Rezolvat
custom model
Imagine profil
Imagine profil
2
mar. 22
3705
Transfer data from model to arch view
view model arch
Imagine profil
Imagine profil
2
apr. 24
2056
Odoo 14: At least one model cache has been invalidated, signaling through the database Rezolvat
error model v14
Imagine profil
Imagine profil
1
mai 23
19320
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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