Ir al contenido
Menú
Se marcó esta pregunta
6 Respuestas
14009 Vistas

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.

Avatar
Descartar
Autor

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

Mejor respuesta

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

Avatar
Descartar
Mejor respuesta

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

Avatar
Descartar
Autor

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

Autor Mejor respuesta

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

Avatar
Descartar

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

After 8 years, if I do that from the sale order onchange order_line it's fine, it changes records but it doesn't save them until user does this

But as soon as I call it from a wizard for instance, it's saving the data as well automatically

I was wondering if there is a way to avoid that

Publicaciones relacionadas Respuestas Vistas Actividad
3
may 20
4410
0
jun 21
1363
4
abr 15
5618
0
mar 15
6040
0
oct 24
3743