Skip to Content
Odoo Menu
  • Zaloguj się
  • Wypróbuj za darmo
  • Aplikacje
    Finanse
    • Księgowość
    • Fakturowanie
    • Wydatki
    • Arkusz kalkulacyjny (BI)
    • Dokumenty
    • Podpisy
    Sprzedaż
    • CRM
    • Sprzedaż
    • PoS Sklep
    • PoS Restauracja
    • Subskrypcje
    • Wypożyczalnia
    Strony Internetowe
    • Kreator Stron Internetowych
    • eCommerce
    • Blog
    • Forum
    • Czat na Żywo
    • eLearning
    Łańcuch dostaw
    • Magazyn
    • Produkcja
    • PLM
    • Zakupy
    • Konserwacja
    • Jakość
    Zasoby Ludzkie
    • Pracownicy
    • Rekrutacja
    • Urlopy
    • Ocena pracy
    • Polecenia Pracownicze
    • Flota
    Marketing
    • Marketing Społecznościowy
    • E-mail Marketing
    • SMS Marketing
    • Wydarzenia
    • Automatyzacja Marketingu
    • Ankiety
    Usługi
    • Projekt
    • Ewidencja czasu pracy
    • Usługi Terenowe
    • Helpdesk
    • Planowanie
    • Spotkania
    Produktywność
    • Dyskusje
    • Zatwierdzenia
    • IoT
    • VoIP
    • Baza wiedzy
    • WhatsApp
    Aplikacje trzecich stron Studio Odoo Odoo Cloud Platform
  • Branże
    Sprzedaż detaliczna
    • Księgarnia
    • Sklep odzieżowy
    • Sklep meblowy
    • Sklep spożywczy
    • Sklep z narzędziami
    • Sklep z zabawkami
    Żywienie i hotelarstwo
    • Bar i Pub
    • Restauracja
    • Fast Food
    • Pensjonat
    • Dystrybutor napojów
    • Hotel
    Agencja nieruchomości
    • Agencja nieruchomości
    • Biuro architektoniczne
    • Budowa
    • Zarządzanie nieruchomościami
    • Ogrodnictwo
    • Stowarzyszenie właścicieli nieruchomości
    Doradztwo
    • Biuro księgowe
    • Partner Odoo
    • Agencja marketingowa
    • Kancelaria prawna
    • Agencja rekrutacyjna
    • Audyt i certyfikacja
    Produkcja
    • Tekstylia
    • Metal
    • Meble
    • Jedzenie
    • Browar
    • Prezenty firmowe
    Zdrowie & Fitness
    • Klub sportowy
    • Salon optyczny
    • Centrum fitness
    • Praktycy Wellness
    • Apteka
    • Salon fryzjerski
    Transakcje
    • Złota rączka
    • Wsparcie Sprzętu IT
    • Systemy energii słonecznej
    • Szewc
    • Firma sprzątająca
    • Usługi HVAC
    Inne
    • Organizacja non-profit
    • Agencja Środowiskowa
    • Wynajem billboardów
    • Fotografia
    • Leasing rowerów
    • Sprzedawca oprogramowania
    Przeglądaj wszystkie branże
  • Community
    Ucz się
    • Samouczki
    • Dokumentacja
    • Certyfikacje
    • Szkolenie
    • Blog
    • Podcast
    Pomóż w nauce innym
    • Program Edukacyjny
    • Scale Up! Gra biznesowa
    • Odwiedź Odoo
    Skorzystaj z oprogramowania
    • Pobierz
    • Porównaj edycje
    • Wydania
    Współpracuj
    • Github
    • Forum
    • Wydarzenia
    • Tłumaczenia
    • Zostań partnerem
    • Usługi dla partnerów
    • Zarejestruj swoją firmę rachunkową
    Skorzystaj z usług
    • Znajdź partnera
    • Znajdź księgowego
    • Spotkaj się z doradcą
    • Usługi wdrożenia
    • Opinie klientów
    • Wsparcie
    • Aktualizacje
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Zaplanuj demo
  • Cennik
  • Pomoc

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

  • CRM
  • e-Commerce
  • Księgowość
  • Zapasy
  • PoS
  • Projekt
  • MRP
All apps
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Pomoc

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

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
3 Odpowiedzi
20266 Widoki
Awatar
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
Awatar
Odrzuć
Pau Ubach

Can you post your create function?

Juan Formoso Vasco
Autor

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

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.

Awatar
Juan Formoso Vasco
Autor Najlepsza odpowiedź

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
Awatar
Odrzuć
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.

Awatar
Ajay
Najlepsza odpowiedź

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
Awatar
Odrzuć
Juan Formoso Vasco
Autor

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
Autor

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

Awatar
Ludo - 21South
Najlepsza odpowiedź

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
Awatar
Odrzuć
Juan Formoso Vasco
Autor

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
Autor

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
Autor

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

Podoba Ci się ta dyskusja? Dołącz do niej!

Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!

Zarejestruj się
Społeczność
  • Samouczki
  • Dokumentacja
  • Forum
Open Source
  • Pobierz
  • Github
  • Runbot
  • Tłumaczenia
Usługi
  • Hosting Odoo.sh
  • Wsparcie
  • Aktualizacja
  • Indywidualne rozwiązania
  • Edukacja
  • Znajdź księgowego
  • Znajdź partnera
  • Zostań partnerem
O nas
  • Nasza firma
  • Zasoby marki
  • Skontaktuj się z nami
  • Oferty pracy
  • Wydarzenia
  • Podcast
  • Blog
  • Klienci
  • Informacje prawne • Prywatność
  • Bezpieczeństwo Odoo
الْعَرَبيّة 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 to pakiet aplikacji biznesowych typu open source, które zaspokoją wszystkie potrzeby Twojej firmy: CRM, eCommerce, księgowość, inwentaryzacja, punkt sprzedaży, zarządzanie projektami itp.

Unikalną wartością Odoo jest to, że jest jednocześnie bardzo łatwe w użyciu i w pełni zintegrowane.

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