Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
18307 Vistas


I try to create sales order using web services API, 

I do this : 

product2 = objects.execute_kw(db,uid,pwd, 'product.template','search',[[['id','=',11]]])

product2_ids = objects.execute_kw(db,uid,pwd,'product.template','read',[product2],{'fields':

['name',

'type',

'default_code',

'barcode']})

customer = objects.execute_kw(db,uid,pwd, 'res.partner','search',[[['customer','=',1],['id','=',31]]])

customer_ids = objects.execute_kw(db,uid,pwd,'res.partner','read',[customer],{'fields':

['name',

'street']})

print 'customer id :', customer_ids[0].get('id')

print 'Product id :', product2_ids[0].get('id')

param = objects.execute_kw(db, uid, pwd,'sale.order', 'create',[

{'partner_id' :customer_ids[0].get('id'),

'validity_date':datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S'),

'order_line': {'product_id':product2_ids[0].get('id'),'name':'test','product_uom_qty':10,'price_unit':30000}}])

salesorder = objects.execute_kw(db,uid,pwd, 'sale.order','search',[[['id','=',param]]])

print objects.execute_kw(db,uid,pwd,'sale.order','read',[salesorder],{'fields':

['name',

'id',

'order_line']})


Then when I See the result,

customer id : 31

Product id : 11

[{'id': 31, 'name': 'SO16060031', 'order_line': []}]

Process finished with exit code 0


the object successfully Create Sales Order, but cannot insert the order line..

So how to fix it ? is there any sample or documentation about insert sale.order  and sale.order.line or similar


Best Regards




Avatar
Descartar
Autor Mejor respuesta

Solve,

 my mistake .. I should create sale.order first, get the return value, then create sale.order.line with the return value as "order_id:


param =  objects.execute_kw(db, uid, pwd,'sale.order', 'create',[
{'partner_id' :customer_ids[0].get('id'),
'validity_date':datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S'),
'order_line': {'product_id':product2_ids[0].get('id'),'name':'test','product_uom_qty':10,'price_unit':30000}}])
objects.execute_kw(db, uid, pwd,'sale.order.line', 'create',[
{'order_id' :param,'product_id':product_ids[0].get('id'),
'name':'test2','product_uom':product_ids[0].get('uom_id')[0],'product_uom_qty':20,'price_unit':50000,'price_total':1000000}])
objects.execute_kw(db, uid, pwd,'sale.order.line', 'create',[
{'order_id' :param,'product_id':product2_ids[0].get('id'),
'name':'test45','product_uom':product2_ids[0].get('uom_id')[0],'product_uom_qty':10,'price_unit':50000,'price_total':5000000}])
salesorder = objects.execute_kw(db,uid,pwd, 'sale.order','search',[[['id','=',param]]])
print objects.execute_kw(db,uid,pwd,'sale.order','read',[salesorder],{'fields':
['name',
'id',
'order_line']})
Avatar
Descartar
Mejor respuesta

The value given for the one2many field order_line should be a list of commands.  Use the command (0, 0, vals) to create a new line:


line_vals = {
'product_id': product2_ids[0].get('id'),
'name':'test',
'product_uom_qty': 10,
'price_unit': 30000,
}
order_vals = {
'partner_id': customer_ids[0].get('id'),
'validity_date': datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S'),
'order_line': [(0, 0, line_vals)],
}
salesorder = objects.execute_kw(db, uid, pwd, 'sale.order', 'create', [order_vals])
Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
0
oct 18
2976
2
nov 20
14649
0
mar 19
3102
1
dic 18
25006
3
feb 16
5900