Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

"add an item" to clicking a buttom

By
naitsir
on 6/11/13, 1:48 PM 3,891 views

Hi all, in a view (like sale order, but could be any view) there is two ways to add lines (products in sale order) - we can create a view form for the line and when the user click on "add an item" link show the form (like a sale order) or - we can add a line in row, directly in the tree (like customer or supplier invoice)

but I need a way to add a line when the user click on a buttom (or in on_chage attribute of a field)

in OpenERP 6.0 I can add an item with the "create" function in the server side, but in OpenERP 7.0 this not work because the line is added in the client view an the "create" function is called when the user save the form

I hope you can help me. thanks in advance.

I check a lot of the code and I found an example of this on account.voucher form. for a Saler order

naitsir
on 6/13/13, 8:55 PM
5

Sandeep

--Sandeep--
6083
| 6 5 8
Delhi, India
--Sandeep--
Python OpenERP Developer http://in.linkedin.com/pub/sandeep-rana/3b/a16/786/
Sandeep
On 6/13/13, 3:24 AM

Hi

As above answer , if you want to add value iby clicking a button , i would say that any of form view when button is clicked the current record is saved at the same time you , there is no means to before save

you add same as in above answer mentions

if you want add before save then just use on change property

Thanks
Sandeep

3

Keyur

--Keyur--
1165
| 4 4 8
Ahmedabad, India
--Keyur--

Odoo Expert

Keyur
On 6/12/13, 3:30 AM

Hi naitsir. You can call create function when clicking on a button. So you don't need to click on Save button.

For example,

In sale order there is a button Confirm Sale. On clicking on this button you can add sale order line record by calling create method of sale.order.line.

def action_button_confirm(self, cr, uid, ids, context=None):
    sale_order_line_obj = self.pool.get('sale.order.line')
    order_line_id = sale_order_line_obj.create(cr, uid, {'name':'Hello','order_id':ids[0]}, context=context) // Sale order line created for current sale order

If you want to add products as per user's choice then you can create new wizard and add your required fields in wizard which need to be added in sale order line, in wizard button you can write your code that means whichever data was filled in wizard will be added in sale order line. Hope this way it will work.

Thanks

your solution will work but only to add one line and only when the user save the Sale Order. The idea is to add products before to save the Sale Order and add as many products as the user wants. Thank you for your help anyway

naitsir
on 6/12/13, 7:48 PM
0
naitsir
On 6/13/13, 9:02 PM

I check a lot of the code and I found an example of this on account.voucher form. For a Saler Order in my on_change function I need to res['value']['order_line'] = [{order line data1},{order line data2},...] where order line data is the all data related a sale.order.line then the client browser add all lines to my Sale order

this work for all forms with one2many, many2many fields :)

regards, and thank your for your help

HI could yo explain better where you found these features, I have similar problems and I can't find what you mention in this post

MEXYTUL, Diego Calzadilla
on 10/10/13, 1:08 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 6/11/13, 1:48 PM
Seen: 3891 times
Last updated: 3/27/15, 6:36 PM