From 243863a2903192b45d59f14f7732d4c4426fe421 Mon Sep 17 00:00:00 2001 From: Zlash65 Date: Fri, 24 Aug 2018 16:02:48 +0530 Subject: [PATCH] validation for stop date added --- .../doctype/sales_invoice/sales_invoice.js | 20 +++++++++++++++++++ .../doctype/sales_invoice/sales_invoice.py | 13 ++++++++++++ 2 files changed, 33 insertions(+) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index 194c3641d7c..32195dd9dd3 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -740,6 +740,26 @@ frappe.ui.form.on('Sales Invoice Timesheet', { } }) +frappe.ui.form.on('Sales Invoice Item', { + service_stop_date: function(frm, cdt, cdn) { + var child = locals[cdt][cdn]; + + if(child.service_stop_date) { + let start_date = Date.parse(child.service_start_date); + let end_date = Date.parse(child.service_end_date); + let stop_date = Date.parse(child.service_stop_date); + + if(stop_date < start_date) { + frappe.model.set_value(cdt, cdn, "service_stop_date", ""); + frappe.throw(__("Service Stop Date cannot be before Service Start Date")); + } else if (stop_date > end_date) { + frappe.model.set_value(cdt, cdn, "service_stop_date", ""); + frappe.throw(__("Service Stop Date cannot be after Service End Date")); + } + } + } +}) + var calculate_total_billing_amount = function(frm) { var doc = frm.doc; diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index fd77d4b47ea..16232273922 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -89,6 +89,9 @@ class SalesInvoice(SellingController): self.update_current_stock() self.validate_delivery_note() + # validate service stop date to lie in between start and end date + self.validate_service_stop_date() + if not self.is_opening: self.is_opening = 'No' @@ -530,6 +533,16 @@ class SalesInvoice(SellingController): if frappe.db.get_value("Sales Order Item", item.so_detail, "delivered_by_supplier"): frappe.throw(_("Could not update stock, invoice contains drop shipping item.")) + def validate_service_stop_date(self): + frappe.errprint("here") + for item in self.items: + print(date_diff(item.service_stop_date, item.service_start_date)) + if item.enable_deferred_revenue: + 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: + frappe.throw(_("Service Stop Date cannot be after Service End Date")) + def update_current_stock(self): for d in self.get('items'): if d.item_code and d.warehouse: