From 745e3bfb733bdbce034b9b1fb3cd83a502a423a7 Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Thu, 23 Nov 2023 11:40:46 +0530 Subject: [PATCH] chore: notify user on SCO creation --- .../doctype/purchase_order/purchase_order.py | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.py b/erpnext/buying/doctype/purchase_order/purchase_order.py index 86a652b4876c..5db048ee62cd 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/purchase_order.py @@ -8,7 +8,7 @@ from frappe import _, msgprint from frappe.desk.notifications import clear_doctype_notifications from frappe.model.mapper import get_mapped_doc -from frappe.utils import cint, cstr, flt +from frappe.utils import cint, cstr, flt, get_link_to_form from erpnext.accounts.doctype.sales_invoice.sales_invoice import ( unlink_inter_company_doc, @@ -492,9 +492,9 @@ def auto_create_subcontracting_order(self): "Buying Settings", "action_on_purchase_order_submission" ): if action == "Create Subcontracting Order": - make_subcontracting_order(self.name, save=True) + make_subcontracting_order(self.name, save=True, notify=True) elif action == "Create and Submit Subcontracting Order": - make_subcontracting_order(self.name, submit=True) + make_subcontracting_order(self.name, submit=True, notify=True) def item_last_purchase_rate(name, conversion_rate, item_code, conversion_factor=1.0): @@ -698,17 +698,29 @@ def make_inter_company_sales_order(source_name, target_doc=None): @frappe.whitelist() -def make_subcontracting_order(source_name, target_doc=None, save=False, submit=False): +def make_subcontracting_order( + source_name, target_doc=None, save=False, submit=False, notify=False +): target_doc = get_mapped_subcontracting_order(source_name, target_doc) if (save or submit) and frappe.has_permission(target_doc.doctype, "create"): target_doc.save() + if submit and frappe.has_permission(target_doc.doctype, "submit", target_doc): try: target_doc.submit() except Exception as e: target_doc.add_comment("Comment", _("Submit Action Failed") + "

" + str(e)) + if notify: + frappe.msgprint( + _("Subcontracting Order {0} created.").format( + get_link_to_form(target_doc.doctype, target_doc.name) + ), + indicator="green", + alert=True, + ) + return target_doc