跳至内容
菜单
此问题已终结
6 回复
14047 查看

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

最佳答案

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

形象
丢弃
最佳答案

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

编写者 最佳答案

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

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

相关帖文 回复 查看 活动
3
5月 20
4432
0
6月 21
1385
4
4月 15
5655
0
3月 15
6081
0
10月 24
3761