Project
Function
Sample CLI
gway odoo fetch-order
Full Code
def fetch_order(order_id):
"""
Fetch the details of a specific order by its ID from Odoo, including all line details.
"""
order_model = 'sale.order'
order_method = 'read'
line_model = 'sale.order.line'
line_method = 'search_read'
order_fields = ['name', 'amount_total', 'partner_id', 'state']
line_fields = ['product_id', 'name', 'price_unit', 'product_uom_qty']
# Check if order_id is a string that starts with 'S' and fetch by name instead of ID
if isinstance(order_id, str) and order_id.startswith('S'):
order_domain_filter = [('name', '=', order_id)]
order_result = execute_kw(
order_model, 'search_read', [order_domain_filter], {'fields': order_fields})
if order_result:
order_id = order_result[0]['id']
else:
return {'error': 'Order not found.'}
else:
order_result = execute_kw(
[[order_id]], {'fields': order_fields},
model=order_model, method=order_method,
)
line_domain_filter = [('order_id', '=', order_id)]
line_result = execute_kw(
[line_domain_filter], {'fields': line_fields},
model=line_model, method=line_method,
)
result = {
'order_info': order_result,
'line_details': line_result
}
return result