Add or append to Sales order

Trying to add sales order and items via Py
Sales =Frappe.get_doc ({doctype…)
The code is correct now how to add the itens?
Itm = Sales.get(“itens”)
Itm.item_code = 123
It says no object has no attribute item_code
How to add the itens as I cannot save the sales order?

Hi @Helio_Jesus

Use code
sales.append(‘items’, [{
‘item_code’: 1st item’s code,
‘item_name’: name of an item,
‘qty’: quantity
}, {
‘item_code’: 2nd item’s code,
‘item_name’: name of an item,
‘qty’: quantity
}])

You can also refer the below code
https://github.com/frappe/erpnext/blob/develop/erpnext/demo/user/hr.py#L139-L152

1 Like

@rohit_w Thanks it worked.