Skip ke Konten
Odoo Menu
  • Login
  • Uji coba gratis
  • Aplikasi
    Keuangan
    • Akuntansi
    • Faktur
    • Pengeluaran
    • Spreadsheet (BI)
    • Dokumen
    • Tanda Tangan
    Sales
    • CRM
    • Sales
    • POS Toko
    • POS Restoran
    • Langganan
    • Rental
    Website
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Rantai Pasokan
    • Inventaris
    • Manufaktur
    • PLM
    • Purchase
    • Maintenance
    • Kualitas
    Sumber Daya Manusia
    • Karyawan
    • Rekrutmen
    • Cuti
    • Appraisal
    • Referensi
    • Armada
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Acara
    • Otomatisasi Marketing
    • Survei
    Layanan
    • Project
    • Timesheet
    • Layanan Lapangan
    • Meja Bantuan
    • Planning
    • Appointment
    Produktivitas
    • Diskusi
    • Approval
    • IoT
    • VoIP
    • Pengetahuan
    • WhatsApp
    Aplikasi pihak ketiga Odoo Studio Platform Odoo Cloud
  • Industri-Industri
    Retail
    • Toko Buku
    • Toko Baju
    • Toko Furnitur
    • Toko Kelontong
    • Toko Hardware
    • Toko Mainan
    Makanan & Hospitality
    • Bar dan Pub
    • Restoran
    • Fast Food
    • Rumah Tamu
    • Distributor Minuman
    • Hotel
    Real Estate
    • Agensi Real Estate
    • Firma Arsitektur
    • Konstruksi
    • Estate Management
    • Perkebunan
    • Asosiasi Pemilik Properti
    Konsultansi
    • Firma Akuntansi
    • Mitra Odoo
    • Agensi Marketing
    • Firma huku
    • Talent Acquisition
    • Audit & Sertifikasi
    Manufaktur
    • Tekstil
    • Logam
    • Perabotan
    • Makanan
    • Brewery
    • Corporate Gift
    Kesehatan & Fitness
    • Sports Club
    • Toko Kacamata
    • Fitness Center
    • Wellness Practitioners
    • Farmasi
    • Salon Rambut
    Perdagangan
    • Handyman
    • IT Hardware & Support
    • Sistem-Sistem Energi Surya
    • Pembuat Sepatu
    • Cleaning Service
    • Layanan HVAC
    Lainnya
    • Organisasi Nirlaba
    • Agen Lingkungan
    • Rental Billboard
    • Fotografi
    • Penyewaan Sepeda
    • Reseller Software
    Browse semua Industri
  • Komunitas
    Belajar
    • Tutorial-tutorial
    • Dokumentasi
    • Sertifikasi
    • Pelatihan
    • Blog
    • Podcast
    Empower Education
    • Program Edukasi
    • Game Bisnis 'Scale Up!'
    • Kunjungi Odoo
    Dapatkan Softwarenya
    • Download
    • Bandingkan Edisi
    • Daftar Rilis
    Kolaborasi
    • Github
    • Forum
    • Acara
    • Terjemahan
    • Menjadi Partner
    • Layanan untuk Partner
    • Daftarkan perusahaan Akuntansi Anda.
    Dapatkan Layanan
    • Temukan Mitra
    • Temukan Akuntan
    • Temui penasihat
    • Layanan Implementasi
    • Referensi Pelanggan
    • Bantuan
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dapatkan demo
  • Harga
  • Bantuan

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

  • CRM
  • e-Commerce
  • Akuntansi
  • Inventaris
  • PoS
  • Project
  • MRP
All apps
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Help

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

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
fieldcreaterelatededit
2 Replies
15635 Tampilan
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
Buang
Avatar
Bruno PLANCHER
Jawaban Terbai

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
Buang
Avatar
Peter Alabaster
Penulis Jawaban Terbai

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

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

Peter Alabaster
Penulis

d

Menikmati diskusi? Jangan hanya membaca, ikuti!

Buat akun sekarang untuk menikmati fitur eksklufi dan agar terlibat dengan komunitas kami!

Daftar
Post Terkait Replies Tampilan Aktivitas
Auto Load Customer Invoice Address
invoice field related
Avatar
0
Jun 15
4111
Field acting like Textbox
field edit textbox
Avatar
0
Mar 15
4568
How do I create a related field? Diselesaikan
field related bom
Avatar
Avatar
1
Jan 24
15659
How to edit field in the page ".../my" Diselesaikan
field edit remove v17
Avatar
Avatar
2
Feb 24
2562
Field editing after create a form Diselesaikan
fields form create edit
Avatar
Avatar
1
Agu 23
2810
Komunitas
  • Tutorial-tutorial
  • Dokumentasi
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Terjemahan
Layanan
  • Odoo.sh Hosting
  • Bantuan
  • Peningkatan
  • Custom Development
  • Pendidikan
  • Temukan Akuntan
  • Temukan Mitra
  • Menjadi Partner
Tentang Kami
  • Perusahaan kami
  • Aset Merek
  • Hubungi kami
  • Tugas
  • Acara
  • Podcast
  • Blog
  • Pelanggan
  • Hukum • Privasi
  • Keamanan
الْعَرَبيّة 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 adalah rangkaian aplikasi bisnis open source yang mencakup semua kebutuhan perusahaan Anda: CRM, eCommerce, akuntansi, inventaris, point of sale, manajemen project, dan seterusnya.

Mudah digunakan dan terintegrasi penuh pada saat yang sama adalah value proposition unik Odoo.

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