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
    • Discuss
    • 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] How to generate my own create button in a form?

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
3 Replies
20270 Tampilan
Avatar
Juan Formoso Vasco

I have created a button of type action. This button calls an action, and this action calls a form. This form was totally created by me, and has a button Create, which calls the function create, directly inherited from orm.Model (I did not touch it).

When I click on Create, the record is perfectly stored on the database, but then I get this error:

File "/opt/openerp7/openerp_70_ocb_devel/ocb-server/openerp/osv/orm.py", line 4342, in create
    if vals.pop(f, None) is not None:
TypeError: pop() takes at most 1 argument (2 given)

I was looking for the content of vals, and when I click on the button, the method create seems to be called twice. The first time, vals brings the values of the record in a dictionary (all right), the second time brings the ID of the new record generated in a list, and provokes the error.

I would like to know why is this happening and how to solve this. I left here my code:

The button which calls the action:

<button name="%(res_partner_extended.action_create_res_partner_link_category)d" string="Link to category" type="action"/>

The action:

<record id="action_create_res_partner_link_category" model="ir.actions.act_window">
    <field name="name">Link to a new category</field>
    <field name="type">ir.actions.act_window</field>
    <field name="res_model">res.partner.link.category</field>
    <field name="view_type">form</field>
    <field name="view_mode">form</field>
    <field name="view_id" ref="res_partner_link_category_create_form_view"/>
    <field name="target">new</field>
</record>

And the form, with the button which is getting the error:

<record id="res_partner_link_category_create_form_view" model="ir.ui.view">
    <field name="name">res.partner.link.category.create.form</field>
    <field name="model">res.partner.link.category</field>
    <field name="type">form</field>
    <field name="arch" type="xml">
        <form string="Linked category" version="7.0">
            <group>
                <group col="2">
                    <field name="partner_id" readonly="1" options="{'no_open': True,}"/>
                    <field name="link_category_id" required="1" options="{'no_open': True}"/>
                    <field name="type" required="1"/>
                </group>
                <group col="2">
                    <field name="date" required="1"/>
                    <field name="observations"/>
                </group>
            </group>
            <footer>
                <button name="create" string="Create" type="object" class="oe_highlight"/>
                or
                <button string="Discard" class="oe_link" special="cancel" />
            </footer>
        </form>
    </field>
</record>

0
Avatar
Buang
Pau Ubach

Can you post your create function?

Juan Formoso Vasco
Penulis

@Pau Ubach I did not made any create function. I am calling the create function which every class inherited from orm.Model has.

Pau Ubach

Maybe I'm suggesting something stupid, in case the method should be called twice, but I'd try to make CREATE function, check the content in vals, if OK, call create, otherwise, don't call it.

Juan Formoso Vasco
Penulis

Thank you @Pau Ubach. That's not stupid, in fact, I tried it before, creating my own create function and from there calling the ORM create method. But the result was exactly the same. I do not know what I am doing wrong. I am thinking to ignore ORM method and make a SQL query directly, but that would not be a right way to manage my target.

Pau Ubach

Neither using a SQL nor overriding the CREATE function to act this way aren't good solutions, as this could affect the normal system behavior. I'm sorry to can't be more helpful. You should wait until it comes someone with better background in openERP than me.

Avatar
Juan Formoso Vasco
Penulis Jawaban Terbai

Finally, I got the solution after seeing the behaviour of the button.

When I clicked the button, first, the record was stored in the database (not because of the method I wrote in name, but because other reason I do not know). After that, the method I wrote in the name of the button was executed, receiving a list with the new ID of the new generated record instead of the classic dictionary vals (with its fields and their values), so that sparked an error.

So finally I decided to change the method of the name, as I had done before, and I wrote create_rplc instead of create. The important point is inside this function, where I removed the line self.create(cr, uid, vals). This way the content of the function now is only return {'type': 'ir.actions.act_window_close'}.

The conclusion: it is not necessary to tell the button to create the record, it is something that it does automatically, but it is mandatory to specify a method with the property name, and inside this method do not create any record.

I do not why the reason. If someone knows, it would be great if he enlightened us. Thank you!

0
Avatar
Buang
Pau Ubach

I have seen this before: when you click a button in a form, for example when changing state, the record is automatically saved. I'd say it's the normal behavior in OpenERP when a button is clicked.

Avatar
Ajay
Jawaban Terbai

Hello Juan,

From previous conversation i came to know that you have "res.partner.link.category" you customized object & on the values from that object you need to create 'res.partner' record. Make me correct if i m wrong.

Now if you have the same scenario which i declare above i have one question your 'res.partner.link.category' object is osv.osv or osv.memory ?

In you case you need to change the method name like 'create_category' & in that method you can call create method of res.partner object with passing the values you want.

1
Avatar
Buang
Juan Formoso Vasco
Penulis

If I understood well, my case is the other way round. I want to create a record of res.partner.link.category from the res.partner form. The button which begins the action is in res.partner form, and it calls the popup (a form of res.partner.link.category). Inside this popup is where the create button is... res.partner.link.category inherits from orm.Model (not from orm.TransientModel).

Ajay

If 'res.partner.link.category' is not osv.memory you can change target of action to current like new . It will automatically gives you button to create record. May be this will help you.

Juan Formoso Vasco
Penulis

@Ajay you are right, I turned new into current and I was able to create records without errors (but I needed the popup). Finally, I got the solution. I am going to post it.

Avatar
Ludo - 21South
Jawaban Terbai

I am not quite sure what you are trying to achieve here, but it sounds like a complicated work chain and not something OpenERP is suitable for. As Pau Ubach already pointed out, it is rarely a good idea to surpass the ORM and use queries instead. You will get into all sort of trouble later (especially with objects that have a workflow).

Could you please describe what the end goal is? I assume it has something to do with partner categories when creating partners, but other than that I fail to see what the requirements are.

0
Avatar
Buang
Juan Formoso Vasco
Penulis

My target is to generate a create button in the res.partner form, which will create a record from other different model, res.partner.link.category. They are not related at all. But I have to include that button inside res.partner form.

Ludo - 21South

Ok, makes more sense now. So, if you made a regular button "type=action name=create_partner_link_method" and in create_partner_link_method on the res_partner object you would call the linked objects create ( i.e. : 'self.pool.get(' res.partner.link.category').create(cr,uid,my_link_vals) )function, that would give you an error? Note that you should not call the method that the button itself calls "create" because that is already in the override.

Pau Ubach

What's the relationship between these 2 objects?

Pau Ubach

Aren't you including a field to the second object in the form?

Juan Formoso Vasco
Penulis

The problem is that I cannot declare the function "create_partner_link_method" in the "res.partner" object, because the form in which the create button is, belongs to res.partner.link.category model (otherwise, I could not show the fields of that model in the form, because they weren't recognized). But if I change the name of the method (create_partner_link_method), as you say, and in the definition of this method (in res.partner.link.category model) I write self.create(cr, uid, my_link_vals), the result is the same.

Juan Formoso Vasco
Penulis

@Pau Ubach Yes, I do. In fact, models are related, I do not have to allow creating records as a normal one2many/many2many form, I have to generate a button to create records (out of posssibles trees), so it is like they weren't related.

Menikmati diskusi? Jangan hanya membaca, ikuti!

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

Daftar
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