콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
18433 화면


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




아바타
취소
작성자 베스트 답변

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']})
아바타
취소
베스트 답변

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])
아바타
취소
관련 게시물 답글 화면 활동
0
10월 18
3065
OpenERP Java API 해결 완료
2
11월 20
14702
0
3월 19
3168
1
12월 18
25086
3
2월 16
5944