validation for stop date added

This commit is contained in:
Zlash65 2018-08-24 16:02:48 +05:30
parent 33cff7735e
commit 243863a290
2 changed files with 33 additions and 0 deletions

View File

@ -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;

View File

@ -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: