How to programmatically create a sale order line (Odoo 13)

梦想的初衷 提交于 2020-12-12 11:07:34

问题


I have a sales record

models.execute_kw(db, uid, password, 'sale.order', 'create', [{
         
            'partner_id': 10,
            'order_line': [(0, 0, {'product_id':1,'product_uom_qty':2}),

        

I need to be able to create 'order_line' programaticaly based on a number from a variable. For example if variable = 3

  models.execute_kw(db, uid, password, 'sale.order', 'create', [{

         
            'partner_id': 10,
            'order_line': [(0, 0, {'product_id':1,'product_uom_qty':2}),
            'order_line': [(0, 0, {'product_id':1,'product_uom_qty':2}),
            'order_line': [(0, 0, {'product_id':1,'product_uom_qty':2}),

I followed the exact steps from here, https://www.odoo.com/forum/help-1/question/programmatically-create-a-sale-order-line-99981. But I keep getting errors as it seems Odoo has changed quite a bit since 2016. What would be the best way to go about this?


回答1:


In your second example, you forgot the closing bracket when you provide the value of the order line, and when you write order_line three times, it is equivalent to provide only the last value.

If you need to create three lines, you need to pass three tuples in a list using the special commands.

The following example will create a sale order with three identical lines:

models.execute_kw(DB, uid, PASSWORD, 'sale.order', 'create', [{

            'partner_id': 10,
            'order_line': [(0, 0, {'product_id':1,'product_uom_qty':2}),
                           (0, 0, {'product_id':1,'product_uom_qty':2}),
                           (0, 0, {'product_id':1,'product_uom_qty':2})
                          ]
            }])


来源:https://stackoverflow.com/questions/63142788/how-to-programmatically-create-a-sale-order-line-odoo-13

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!