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

How to create sale order line in onchange one2many?

By
Thomas Grellety
on 1/24/14, 9:33 AM 1,903 views

Hello,

I use OpenERP 6.1. My issue is in a one2many wizard(sale.order.line) is that when you created a new line and saved this line with button in wizard, there is no create or write action, due to the code in web client, there is just a temporary id created prefixed as one2many_v_id_xxx (see file data.js in web), changes are really saved only when I push button save of the form, and not when I push button save of the wizard, then in this case operations I want to do can not be done immediately.

So I use the onchange function on the one2many field, this my function :

    def onchange_sale_lines(self, cr, uid, ids, lines,context=None):
        val = {}

        if context.get('order_id',False):
            order  = self.browse(cr,uid,context.get('order_id'))
            if len(lines)>0:
                i = 0
                for l in lines:
                    if l[0] == 0:
                        (l[2]).update({'order_id':context.get('order_id')})
                        self.pool.get('sale.order.line').create(cr,uid,l[2])
        return {'value':val}

It works, but when I push the button save of the form, OpenERP create twice the line. How to get it creates only one line and that is created in the onchange?

Thanks

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

0 follower(s)

Stats

Asked: 1/24/14, 9:33 AM
Seen: 1903 times
Last updated: 3/16/15, 8:10 AM