Bỏ qua để đến Nội dung
Odoo Menu
  • Đăng nhập
  • Dùng thử miễn phí
  • Ứng dụng
    Tài chính
    • Kế toán
    • Hóa đơn
    • Chi phí
    • Bảng tính (BI)
    • Tài liệu
    • Ký tên
    Bán hàng
    • CRM
    • Bán hàng
    • POS Cửa hàng
    • POS Nhà hàng
    • Đăng ký
    • Cho thuê
    Trang web
    • Trình tạo trang web
    • Thương mại điện tử
    • Blog
    • Diễn đàn
    • Trò chuyện trực tiếp
    • Học trực tuyến
    Chuỗi cung ứng
    • Tồn kho
    • Sản xuất
    • PLM
    • Mua hàng
    • Bảo dưỡng
    • Chất lượng
    Nhân sự
    • Nhân viên
    • Tuyển dụng
    • Ngày nghỉ
    • Đánh giá
    • Giới thiệu
    • Đội xe
    Marketing
    • Marketing trên MXH
    • Marketing qua email
    • Marketing qua SMS
    • Sự kiện
    • Tự động hóa Marketing
    • Khảo sát
    Dịch vụ
    • Dự án
    • Bảng chấm công
    • Dịch vụ hiện trường
    • Hỗ trợ
    • Kế hoạch
    • Lịch hẹn
    Năng suất
    • Thảo luận
    • Phê duyệt
    • IoT
    • VoIP
    • Kiến thức
    • WhatsApp
    Ứng dụng của bên thứ ba Studio Odoo Nền tảng Đám mây Odoo
  • Ngành
    Bán lẻ
    • Nhà sách
    • Cửa hàng quần áo
    • Cửa hàng nội thất
    • Cửa hàng tạp hóa
    • Cửa hàng đồ kim khí
    • Cửa hàng đồ chơi
    Ẩm thực & Dịch vụ lưu trú
    • Bar và quán rượu
    • Nhà hàng
    • Đồ ăn nhanh
    • Guest house
    • Nhà phân phối đồ uống
    • Khách sạn
    Bất động sản
    • Công ty môi giới bất động sản
    • Công ty kiến trúc
    • Xây dựng
    • Quản lý bất động sản
    • Làm vườn
    • Hiệp hội chủ sở hữu bất động sản
    Tư vấn
    • Công ty kế toán
    • Đối tác Odoo
    • Công ty marketing
    • Công ty luật
    • Tuyển dụng
    • Thanh tra & chứng nhận
    Sản xuất
    • Dệt may
    • Kim loại
    • Nội thất
    • Ẩm thực
    • Nhà máy bia
    • Quà tặng doanh nghiệp
    Sức khoẻ & fitness
    • CLB thể thao
    • Cửa hàng kính mắt
    • Trung tâm fitness
    • Chuyên gia chăm sóc sức khỏe
    • Hiệu thuốc
    • Tiệm làm tóc
    Thương mại
    • Dịch vụ sửa chữa
    • Phần cứng CNTT & Hỗ trợ
    • Hệ thống năng lượng mặt trời
    • Công ty sản xuất giày
    • Dịch vụ vệ sinh
    • Dịch vụ HVAC
    Khác
    • Tổ chức phi lợi nhuận
    • Cơ quan môi trường
    • Cho thuê biển quảng cáo
    • Nhiếp ảnh
    • Cho thuê xe đạp
    • Đại lý phần mềm
    Xem tất cả ngành
  • Cộng đồng
    Học tập
    • Khóa học
    • Tài liệu
    • Chứng chỉ
    • Đào tạo
    • Blog
    • Podcast
    Thúc đẩy đào tạo
    • Chương trình đào tạo
    • Trò chơi kinh doanh Scale Up!
    • Tham quan Odoo
    Nhận phần mềm
    • Tải xuống
    • So sánh các phiên bản
    • Phiên bản
    Hợp tác
    • Github
    • Diễn đàn
    • Sự kiện
    • Dịch thuật
    • Trở thành đối tác
    • Dịch vụ dành cho Đối tác
    • Đăng ký công ty kế toán của bạn
    Nhận dịch vụ
    • Tìm đối tác
    • Tìm kế toán
    • Gặp chuyên gia hỗ trợ
    • Dịch vụ Triển khai
    • Khách hàng tham khảo
    • Hỗ trợ
    • Nâng cấp
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Nhận một buổi demo
  • Bảng giá
  • Trợ giúp

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

  • CRM
  • e-Commerce
  • Kế toán
  • Tồn kho
  • PoS
  • Dự án
  • MRP
All apps
Bạn cần phải đăng ký để tương tác với cộng đồng.
Tất cả bài viết Người Huy hiệu
Thẻ (Xem tất cả)
odoo accounting v14 pos v15
Về diễn đàn này
Bạn cần phải đăng ký để tương tác với cộng đồng.
Tất cả bài viết Người Huy hiệu
Thẻ (Xem tất cả)
odoo accounting v14 pos v15
Về diễn đàn này
Hỗ trợ

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

Đăng ký nhận tin

Nhận thông báo khi có hoạt động trên bài viết này

Câu hỏi này đã bị gắn cờ
3 Trả lời
20315 Lượt xem
Ảnh đại diện
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
Ảnh đại diện
Huỷ bỏ
Pau Ubach

Can you post your create function?

Juan Formoso Vasco
Tác giả

@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
Tác giả

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.

Ảnh đại diện
Juan Formoso Vasco
Tác giả Câu trả lời hay nhất

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
Ảnh đại diện
Huỷ bỏ
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.

Ảnh đại diện
Ajay
Câu trả lời hay nhất

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
Ảnh đại diện
Huỷ bỏ
Juan Formoso Vasco
Tác giả

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
Tác giả

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

Ảnh đại diện
Ludo - 21South
Câu trả lời hay nhất

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
Ảnh đại diện
Huỷ bỏ
Juan Formoso Vasco
Tác giả

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
Tác giả

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
Tác giả

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

Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!

Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!

Đăng ký
Cộng đồng
  • Khóa học
  • Tài liệu
  • Diễn đàn
Open source
  • Tải xuống
  • Github
  • Runbot
  • Dịch thuật
Dịch vụ
  • Lưu trữ Odoo.sh
  • Hỗ trợ
  • Nâng cấp
  • Phát triển tùy chỉnh
  • Đào tạo
  • Tìm kế toán
  • Tìm đối tác
  • Trở thành đối tác
Giới thiệu công ty
  • Công ty của chúng tôi
  • Tài sản thương hiệu
  • Liên hệ
  • Việc làm
  • Sự kiện
  • Podcast
  • Blog
  • Khách hàng
  • Pháp lý • Riêng tư
  • Bảo mật
الْعَرَبيّة 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 là bộ ứng dụng kinh doanh có open source đáp ứng tất cả các nhu cầu của công ty bạn: CRM, thương mại điện tử, kế toán, tồn kho, POS, quản lý dự án, v.v.

Định hướng giá trị riêng biệt của Odoo là tích hợp hoàn toàn và dễ dàng sử dụng.

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