Updating Sales Order items and taxes by code

Hello there,

I am writing code to import json data as Sales Order. On the whole it is working. Now I want to implement a update feature.

I have done this with several other doctypes, which is working nicely.

Sales Order takes the 2 lists “items” and “taxes” as seen here:

	item = frappe.get_doc({
		"doctype": "Sales Order",
		"customer": customer.name,
		"transaction_date": date_purchased,
		"delivery_date": delivery_date,
		"currency": data['currency_code'],
		"price_list": "Standard-Shop",
		"price_list_currency": data['currency_code'],
		"territory": territory.name,
		"customer_group": customer_group.name,
		"customer_address": customer_address.name,
		"fiscal_year": fiscal_year,
		"source": "Shop",
		"order_type": "Sales",
		"ignore_pricing_rule": 1,
		"apply_discount_on": "Net Total",
		"items": get_items_list(data['items']),
		"taxes": get_taxes_list(data['items'], data['totals']),
		"my_id": data['my_id']
	})

The code above is working for me. It creates a Sales Order with Items and correctly calculated taxes and shipping charges.

After running that code in a loop, I have a bunch of Sales Orders.

Now I run another loop which is iterating on all my sales and use the following code.

update = frappe.get_doc("Sales Order", {"my_id": str(data['orders_id'])})
update.status = "Changed"
update.items = get_items_list(data['items'])
update.taxes = get_taxes_list(data['items'], data['totals'])
update.save()

That code does not work. I just want to change some attributes and save the Sales Order changes. The Exception I get tells me:

'dict' object has no attribute 'docstatus

This is a strange behaviour. I also tried to empty update.items and update.taxes by using update.items = [] and update.taxes = [] and saved it, which was successfully removing the entries in the database. After calling update.save() I tried to repeat the update code above, which was causing the same error again.

I am grateful for your support.

Share the full trace.

If you truly are, please help out others too!