From d676a67769b52b1698d173ce02befed54abdc32e Mon Sep 17 00:00:00 2001 From: Zlash65 Date: Sat, 25 Aug 2018 20:15:28 +0530 Subject: [PATCH] validate changing service stop date once its set --- .../doctype/sales_invoice/sales_invoice.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 1e5166f99e..f071a069b2 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -534,15 +534,23 @@ class SalesInvoice(SellingController): frappe.throw(_("Could not update stock, invoice contains drop shipping item.")) def validate_service_stop_date(self): - frappe.errprint("here") + old_doc = frappe.db.get_all("Sales Invoice Item", {"parent": self.name}, ["name", "service_stop_date"]) + old_stop_dates = {} + for d in old_doc: + old_stop_dates[d.name] = d.service_stop_date or "" + for item in self.items: - print(date_diff(item.service_stop_date, item.service_start_date)) if item.enable_deferred_revenue: + print(vars(item)) if date_diff(item.service_stop_date, item.service_start_date) < 0: frappe.throw(_("Service Stop Date cannot be before Service Start Date")) - elif date_diff(item.service_stop_date, item.service_end_date) > 0: + + if date_diff(item.service_stop_date, item.service_end_date) > 0: frappe.throw(_("Service Stop Date cannot be after Service End Date")) + if old_stop_dates[item.name] and item.service_stop_date!=old_stop_dates[item.name]: + frappe.throw(_("Cannot change Service Stop Date for item in row {0}".format(item.idx))) + def update_current_stock(self): for d in self.get('items'): if d.item_code and d.warehouse: