Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

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

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

[SOLVED] How to generate my own create button in a form?

Naroči se

Get notified when there's activity on this post

This question has been flagged
3 Odgovori
20258 Prikazi
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
Opusti
Pau Ubach

Can you post your create function?

Juan Formoso Vasco
Avtor

@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
Avtor

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
Avtor Best Answer

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
Opusti
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
Best Answer

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
Opusti
Juan Formoso Vasco
Avtor

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
Avtor

@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
Best Answer

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
Opusti
Juan Formoso Vasco
Avtor

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
Avtor

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
Avtor

@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.

Enjoying the discussion? Don't just read, join in!

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

Prijavi
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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