Passa al contenuto
Odoo Menu
  • Accedi
  • Provalo gratis
  • App
    Finanze
    • Contabilità
    • Fatturazione
    • Note spese
    • Fogli di calcolo (BI)
    • Documenti
    • Firma
    Vendite
    • CRM
    • Vendite
    • Punto vendita Negozio
    • Punto vendita Ristorante
    • Abbonamenti
    • Noleggi
    Siti web
    • Configuratore sito web
    • E-commerce
    • Blog
    • Forum
    • Live chat
    • E-learning
    Supply chain
    • Magazzino
    • Produzione
    • PLM
    • Acquisti
    • Manutenzione
    • Qualità
    Risorse umane
    • Dipendenti
    • Assunzioni
    • Ferie
    • Valutazioni
    • Referral dipendenti
    • Parco veicoli
    Marketing
    • Social marketing
    • E-mail marketing
    • SMS marketing
    • Eventi
    • Marketing automation
    • Sondaggi
    Servizi
    • Progetti
    • Fogli ore
    • Assistenza sul campo
    • Helpdesk
    • Pianificazione
    • Appuntamenti
    Produttività
    • Comunicazioni
    • Approvazioni
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    App di terze parti Odoo Studio Piattaforma cloud Odoo
  • Settori
    Retail
    • Libreria
    • Negozio di abbigliamento
    • Negozio di arredamento
    • Alimentari
    • Ferramenta
    • Negozio di giocattoli
    Cibo e ospitalità
    • Bar e pub
    • Ristorante
    • Fast food
    • Pensione
    • Grossista di bevande
    • Hotel
    Agenzia immobiliare
    • Agenzia immobiliare
    • Studio di architettura
    • Edilizia
    • Gestione immobiliare
    • Impresa di giardinaggio
    • Associazione di proprietari immobiliari
    Consulenza
    • Società di contabilità
    • Partner Odoo
    • Agenzia di marketing
    • Studio legale
    • Selezione del personale
    • Audit e certificazione
    Produzione
    • Tessile
    • Metallo
    • Arredamenti
    • Alimentare
    • Birrificio
    • Ditta di regalistica aziendale
    Benessere e sport
    • Club sportivo
    • Negozio di ottica
    • Centro fitness
    • Centro benessere
    • Farmacia
    • Parrucchiere
    Commercio
    • Tuttofare
    • Hardware e assistenza IT
    • Ditta di installazione di pannelli solari
    • Calzolaio
    • Servizi di pulizia
    • Servizi di climatizzazione
    Altro
    • Organizzazione non profit
    • Ente per la tutela ambientale
    • Agenzia di cartellonistica pubblicitaria
    • Studio fotografico
    • Punto noleggio di biciclette
    • Rivenditore di software
    Carica tutti i settori
  • Community
    Apprendimento
    • Tutorial
    • Documentazione
    • Certificazioni 
    • Formazione
    • Blog
    • Podcast
    Potenzia la tua formazione
    • Programma educativo
    • Scale Up! Business Game
    • Visita Odoo
    Ottieni il software
    • Scarica
    • Versioni a confronto
    • Note di versione
    Collabora
    • Github
    • Forum
    • Eventi
    • Traduzioni
    • Diventa nostro partner
    • Servizi per partner
    • Registra la tua società di contabilità
    Ottieni servizi
    • Trova un partner
    • Trova un contabile
    • Incontra un esperto
    • Servizi di implementazione
    • Testimonianze dei clienti
    • Supporto
    • Aggiornamenti
    GitHub Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Richiedi una demo
  • Prezzi
  • Aiuto

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

  • CRM
  • e-Commerce
  • Contabilità
  • Magazzino
  • PoS
  • Progetti
  • MRP
All apps
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
Assistenza

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

Iscriviti

Ricevi una notifica quando c'è un'attività per questo post

La domanda è stata contrassegnata
fieldcreaterelatededit
2 Risposte
15646 Visualizzazioni
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
Abbandona
Avatar
Bruno PLANCHER
Risposta migliore

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
Abbandona
Avatar
Peter Alabaster
Autore Risposta migliore

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
Abbandona
Bruno PLANCHER

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

Peter Alabaster
Autore

d

Ti stai godendo la conversazione? Non leggere soltanto, partecipa anche tu!

Crea un account oggi per scoprire funzionalità esclusive ed entrare a far parte della nostra fantastica community!

Registrati
Post correlati Risposte Visualizzazioni Attività
Auto Load Customer Invoice Address
invoice field related
Avatar
0
giu 15
4126
Field acting like Textbox
field edit textbox
Avatar
0
mar 15
4579
How do I create a related field? Risolto
field related bom
Avatar
Avatar
1
gen 24
15672
How to edit field in the page ".../my" Risolto
field edit remove v17
Avatar
Avatar
2
feb 24
2568
Field editing after create a form Risolto
fields form create edit
Avatar
Avatar
1
ago 23
2830
Community
  • Tutorial
  • Documentazione
  • Forum
Open source
  • Scarica
  • Github
  • Runbot
  • Traduzioni
Servizi
  • Hosting Odoo.sh
  • Supporto
  • Aggiornamenti
  • Sviluppi personalizzati
  • Formazione
  • Trova un contabile
  • Trova un partner
  • Diventa nostro partner
Chi siamo
  • La nostra azienda
  • Branding
  • Contattaci
  • Lavora con noi
  • Eventi
  • Podcast
  • Blog
  • Clienti
  • Note legali • Privacy
  • Sicurezza
الْعَرَبيّة 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 è un gestionale di applicazioni aziendali open source pensato per coprire tutte le esigenze della tua azienda: CRM, Vendite, E-commerce, Magazzino, Produzione, Fatturazione elettronica, Project Management e molto altro.

Il punto di forza di Odoo è quello di offrire un ecosistema unico di app facili da usare, intuitive e completamente integrate tra loro.

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