Hi,
I am working on one shopify integration, and now one problem is I cannot cancel the sales invoice through the frappe api, here is the general configuration of my erpnext server:
ERPNext: v6.7.8
ERPNext Shopify: v0.0.1
Frappe Framework: v6.7.11
and here is part of my code which related to this cancel function:
so = frappe.db.get_value("Sales Order", {"shopify_id": order.get("id")}, "name")
if not so:
so = frappe.get_doc({
"doctype": "Sales Order",
"naming_series": shopify_settings.sales_order_series or "SO-Shopify-",
"shopify_id": order.get("id"),
"customer": frappe.db.get_value("Customer", {"shopify_id": order.get("customer").get("id")}, "name"),
"membership_number": order["customer"]["membership_number"],
"transaction_date": order.get("processed_at"),
"delivery_date": order.get("processed_at"),
"selling_price_list": shopify_settings.price_list,
"ignore_pricing_rule": 1,
"apply_discount_on": "Net Total",
"discount_amount": flt(order.get("total_discounts")),
"items": get_item_line(order.get("line_items"), shopify_settings),
"taxes": get_tax_line(order, order.get("shipping_lines"), shopify_settings)
}).insert()
so.submit()
else:
so = frappe.get_doc("Sales Order", so)
if order.get("financial_status") == "refunded":
if not frappe.db.sql("""select name from `tabSales Order` where shopify_id = %(shopify_id)s and docstatus = 2""", {"shopify_id": order.get("id")}):
#
## Cancel the corresponding "Delivery Note" first
## We didn't submit the "Delivery Note" for now, so don't need to cancel it for canceling a "Sales Invoice"
#
# core_delivery_note = frappe.db.get_value("Delivery Note", {"shopify_id": order.get("id")}, "name")
# core_delivery_note_doc = frappe.get_doc("Delivery Note", core_delivery_note)
# core_delivery_note_doc.cancel()
# core_delivery_note_doc.submit()
# Cancel the corresponding "Sales Invoice" first
#
## Don't know why the "cancel and submit" doesn't work here, according to the document, what the "cancel" does is:
## Sets the docstatus = 2, then saves
## https://docs.frappe.io/current/api/model/frappe.model.document
## So here just achieve this through the set_value api
#
## frappe.db.set_value("Sales Invoice", cstr(corre_sales_invoice), "docstatus", 2)
#
corre_sales_invoice = frappe.db.get_value("Sales Invoice", {"shopify_id": order.get("id")}, "name")
corre_sales_invoice_doc = frappe.get_doc("Sales Invoice", corre_sales_invoice)
corre_sales_invoice_doc.cancel()
corre_sales_invoice_doc.submit()
# Then cancel this order
so.cancel()
so.submit()
return so
actually when i didn’t try to cancel the sales invoice, the code will raise the error message: need to cancel the corresponding sales invoice first, after i add the code for cancelling the corresponding sales invoice, i got nothing, no exceptions, no errors, but nothing got changed in the erpnext.
can any one help on this?