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

[SOLVED] Related field in a form - works on edit, but not create

Abonnieren

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

Diese Frage wurde gekennzeichnet
fieldcreaterelatededit
2 Antworten
15637 Ansichten
Avatar
Peter Alabaster

Hi, I have created a related field on the product.template form in hope to duplicate the field and have it placed somewhere else.

In the _columns{} section of a class, I have added :

'default_code_duplicate' : fields.related('product_variant_ids', 'default_code', type='char', string='SKU:'),

And in the view I have added:           

           <field name="arch" type="xml">
                <div name="options" position="inside">
                    <div>
                        <label for="default_code_duplicate"/>
                        <field name="default_code_duplicate"/>
                    </div>
                </div>
            </field>

The field shows up fine and i thought it was working correctly until I created a new record and inputted data to this field. The data dissapears on 'Save'. When I click edit, then enter again in the same field, and click save - the data stays.

Could this be something to do with the fact it is a temporary record when you click create, and not written to the database yet?

Is this the correct way to go about this? I don't actually need to duplicate the field, but simply move it - but i didn't know how to do that - so I went about doing it this way.

Thanks

 

0
Avatar
Verwerfen
Avatar
Bruno PLANCHER
Beste Antwort

Hello Peter Alabaster,

No, using a related field is not the correct way to "move" a field on a view.

First, related field are not meant to be written when creating a new record (as you saw it on your tests, the create() method remove the related fields from the written fields).

Then, you can move a field by directly overriding the view (you have to create a new view on xml file, and add the field inherit_id to reference the product view).

Moving a field can be dangerous, as other modules can override the same view. One of the correct way to do this could be (IMHO), to set the priority field of your view as higher as possible (so that your view will be the last one to override the original view).

To sum'up, you could create a new view to remove the original field and relocate it where you want to move it, for example: 

        <record id="view_product_peter_alabaster_inherit" model="ir.ui.view">
            <field name="name">product.product.peter.alabaster.inherit</field>
            <field name="model">product.product</field>
            <field name="priority">99</field>
            <field name="inherit_id" ref="product.product_view_you_want_inherit"/>
            <field name="arch" type="xml">
                <-- remove the orinial location of default_code and its label -->
                <field name="default_code" position="replace"/>
                <label for="default_code" position="replace"/>
                <!-- relocate the field under the options field -->
                <field name="options" position="inside">
                    <div>
                        <label for="default_code"/>
                        <field name="default_code"/>
                    </div>
                </field>
        </record>

 

Hope it helps you,

Regards

1
Avatar
Verwerfen
Avatar
Peter Alabaster
Autor Beste Antwort

Sorry I can't reply to your comment. Thankyou for the answer! It is very helpful. I think i must have tried this before though.

The product template form is all messed up - default_code is in a different form inherit to the position i want it to go.
 

The Inherit id where i want the field to go is:
<field name="inherit_id" ref="product.product_template_form_view"/>

 

Whereas the field I want to move is in:
product.template.product.form
product.template
product.product_template_only_form_view

 

Error details:
Element '<field name="default_code">' cannot be located in parent view

 

I tried this and got no errors, but the internal reference is showing twice, and the second field (the new one) is blank

        <record id="view_product_supplier_inherit" model="ir.ui.view">
            <field name="name">product.template.supplier.form.inherit</field>
            <field name="model">product.template</field>

            <field name="priority">99</field>
            <field name="inherit_id" ref="product.product_template_only_form_view"/>
            <field name="arch" type="xml">
                <field name="default_code" position="replace"/>
                <label for="default_code" position="replace"/>
            </field>

            <field name="priority">99</field>
            <field name="inherit_id" ref="product.product_template_form_view"/>
            <field name="arch" type="xml">
                <div name="options" position="inside">
                    <div>
                        <label for="default_code"/>
                        <field name="default_code"/>
                    </div>
                </div>
            </field>
        </record>

 

 

:: EDIT ::

In response to your comment - yes I have tried that, and get 'not located in parent view' error. I have tried this:

        <record id="view_product_template_form" model="ir.ui.view">
            <field name="name">product.template.inherit</field>
            <field name="model">product.template</field>
            <field name="priority">99</field>
            <field name="inherit_id" ref="product.product_template_form_view"/>
            <field name="arch" type="xml">
                <xpath expr="//page[@string='Information']" position="inside">                   
                    <label for="default_code" position="replace"/>
                    <field name="default_code" position="replace"/>
                </xpath>
                <div name="options" position="inside">
                    <div>
                        <label for="default_code"/>
                        <field name="default_code"/>
                    </div>
                </div>
            </field>
        </record>

And the original still shows up, the duplicated field shows too though, which is a start, but unfortunately, neither stay updated when entering values (enter value, save, leave form, return to form, value not there).

Also - with the latest xml i posted (above) neither fields show a tooltip when developer mode is activated and the mouse is hovered over them.

0
Avatar
Verwerfen
Bruno PLANCHER

have you tried to inherit from product.product_template_form_view instead of product.product_template_only_form_view ?

Peter Alabaster
Autor

d

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
Auto Load Customer Invoice Address
invoice field related
Avatar
0
Juni 15
4116
Field acting like Textbox
field edit textbox
Avatar
0
März 15
4568
How do I create a related field? Gelöst
field related bom
Avatar
Avatar
1
Jan. 24
15662
How to edit field in the page ".../my" Gelöst
field edit remove v17
Avatar
Avatar
2
Feb. 24
2565
Field editing after create a form Gelöst
fields form create edit
Avatar
Avatar
1
Aug. 23
2813
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Herunterladen
  • Github
  • Runbot
  • Übersetzungen
Dienstleistungen
  • Odoo.sh-Hosting
  • Support
  • Upgrade
  • Individuelle Entwicklungen
  • Ausbildung
  • 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