fixed sr no in maintenance schedule
diff --git a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.js b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.js
index 75773e0..bcb1bf3 100644
--- a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.js
+++ b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.js
@@ -5,107 +5,115 @@
// TODO commonify this code
erpnext.support.MaintenanceSchedule = wn.ui.form.Controller.extend({
refresh: function() {
- if (this.frm.doc.docstatus===0) {
- cur_frm.add_custom_button(wn._('From Sales Order'),
+ if (this.frm.doc.docstatus === 0) {
+ this.frm.add_custom_button(wn._('From Sales Order'),
function() {
wn.model.map_current_doc({
method: "erpnext.selling.doctype.sales_order.sales_order.make_maintenance_schedule",
source_doctype: "Sales Order",
get_query_filters: {
docstatus: 1,
- order_type: cur_frm.doc.order_type,
- customer: cur_frm.doc.customer || undefined,
- company: cur_frm.doc.company
+ order_type: me.frm.doc.order_type,
+ customer: me.frm.doc.customer || undefined,
+ company: me.frm.doc.company
}
- })
+ });
});
- } else if (this.frm.doc.docstatus===1) {
- cur_frm.add_custom_button(wn._("Make Maintenance Visit"), function() {
+ } else if (this.frm.doc.docstatus === 1) {
+ this.frm.add_custom_button(wn._("Make Maintenance Visit"), function() {
wn.model.open_mapped_doc({
method: "erpnext.support.doctype.maintenance_schedule.maintenance_schedule.make_maintenance_visit",
source_name: cur_frm.doc.name
})
- })
+ });
}
},
customer: function() {
var me = this;
if(this.frm.doc.customer) {
return this.frm.call({
- doc: this.frm.doc,
+ doc: me.frm.doc,
method: "set_customer_defaults",
});
- }
- },
+ }
+ },
});
$.extend(cur_frm.cscript, new erpnext.support.MaintenanceSchedule({frm: cur_frm}));
cur_frm.cscript.onload = function(doc, dt, dn) {
- if(!doc.status) set_multiple(dt,dn,{status:'Draft'});
-
- if(doc.__islocal){
- set_multiple(dt,dn,{transaction_date:get_today()});
- hide_field(['customer_address','contact_person','customer_name','address_display','contact_display','contact_mobile','contact_email','territory','customer_group']);
- }
+ if(!doc.status)
+ set_multiple(dt, dn, { status:'Draft' });
+
+ if (doc.__islocal) {
+ set_multiple(dt, dn, { transaction_date:get_today() });
+ hide_field(['customer_address', 'contact_person', 'customer_name', 'address_display',
+ 'contact_display', 'contact_mobile', 'contact_email', 'territory', 'customer_group']);
+ }
}
-cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc,dt,dn) {
- if(doc.customer) return get_server_fields('get_customer_address', JSON.stringify({customer: doc.customer, address: doc.customer_address, contact: doc.contact_person}),'', doc, dt, dn, 1);
+cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc, dt, dn) {
+ if (doc.customer) {
+ return get_server_fields('get_customer_address',
+ JSON.stringify({customer: doc.customer, address: doc.customer_address,
+ contact: doc.contact_person}), '', doc, dt, dn, 1);
+ }
}
cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) {
- return{
- filters:{ 'customer': doc.customer}
- }
+ return {
+ filters:{ 'customer': doc.customer }
+ }
}
cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) {
- return{
- filters:{ 'customer': doc.customer}
- }
+ return {
+ filters:{ 'customer': doc.customer }
+ }
}
//
cur_frm.fields_dict['item_maintenance_detail'].grid.get_field('item_code').get_query = function(doc, cdt, cdn) {
- return{
- filters:{ 'is_service_item': "Yes"}
- }
+ return {
+ filters:{ 'is_service_item': "Yes" }
+ }
}
cur_frm.cscript.item_code = function(doc, cdt, cdn) {
- var fname = cur_frm.cscript.fname;
- var d = locals[cdt][cdn];
- if (d.item_code) {
- return get_server_fields('get_item_details',d.item_code, 'item_maintenance_detail',doc,cdt,cdn,1);
- }
+ var fname = cur_frm.cscript.fname;
+ var d = locals[cdt][cdn];
+ if (d.item_code) {
+ return get_server_fields('get_item_details', d.item_code, 'item_maintenance_detail',
+ doc, cdt, cdn, 1);
+ }
}
cur_frm.cscript.periodicity = function(doc, cdt, cdn){
- var d = locals[cdt][cdn];
- if(d.start_date && d.end_date){
- arg = {}
- arg.start_date = d.start_date;
- arg.end_date = d.end_date;
- arg.periodicity = d.periodicity;
- return get_server_fields('get_no_of_visits',docstring(arg),'item_maintenance_detail',doc, cdt, cdn, 1);
- }
- else{
- msgprint(wn._("Please enter Start Date and End Date"));
- }
+ var d = locals[cdt][cdn];
+ if(d.start_date && d.end_date) {
+ arg = {}
+ arg.start_date = d.start_date;
+ arg.end_date = d.end_date;
+ arg.periodicity = d.periodicity;
+ return get_server_fields('get_no_of_visits', docstring(arg),
+ 'item_maintenance_detail', doc, cdt, cdn, 1);
+ } else {
+ msgprint(wn._("Please enter Start Date and End Date"));
+ }
}
cur_frm.cscript.generate_schedule = function(doc, cdt, cdn) {
- if (!doc.__islocal) {
- return $c('runserverobj', args={'method':'generate_schedule', 'docs':wn.model.compress(make_doclist(cdt,cdn))},
- function(r,rt){
- refresh_field('maintenance_schedule_detail');
- }
- );
- } else {
- alert(wn._("Please save the document before generating maintenance schedule"));
- }
+ if (!doc.__islocal) {
+ return $c('runserverobj', args={'method':'generate_schedule',
+ 'docs':wn.model.compress(make_doclist(cdt,cdn))},
+ function(r, rt) {
+ refresh_field('maintenance_schedule_detail');
+ });
+ } else {
+ msgprint(wn._("Please save the document before generating maintenance schedule"));
+ }
}
cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) {
- return{ query: "erpnext.controllers.queries.customer_query" } }
+ return { query: "erpnext.controllers.queries.customer_query" }
+}
diff --git a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py
index 8263b19..270f954 100644
--- a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py
+++ b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py
@@ -7,10 +7,7 @@
from webnotes.utils import add_days, cstr, getdate
from webnotes.model.doc import addchild
from webnotes.model.bean import getlist
-from webnotes import msgprint
-
-
-
+from webnotes import msgprint, throw, _
from erpnext.utilities.transaction_base import TransactionBase, delete_events
class DocType(TransactionBase):
@@ -19,7 +16,8 @@
self.doclist = doclist
def get_item_details(self, item_code):
- item = webnotes.conn.sql("select item_name, description from `tabItem` where name = '%s'" %(item_code), as_dict=1)
+ item = webnotes.conn.sql("""select item_name, description from `tabItem`
+ where name=%s""", (item_code), as_dict=1)
ret = {
'item_name': item and item[0]['item_name'] or '',
'description' : item and item[0]['description'] or ''
@@ -28,13 +26,14 @@
def generate_schedule(self):
self.doclist = self.doc.clear_table(self.doclist, 'maintenance_schedule_detail')
- count = 0
- webnotes.conn.sql("delete from `tabMaintenance Schedule Detail` where parent='%s'" %(self.doc.name))
+ webnotes.conn.sql("""delete from `tabMaintenance Schedule Detail`
+ where parent=%s""", (self.doc.name))
for d in getlist(self.doclist, 'item_maintenance_detail'):
self.validate_maintenance_detail()
- s_list =[]
+ count = 1
+ s_list = []
s_list = self.create_schedule_list(d.start_date, d.end_date, d.no_of_visits)
- for i in range(d.no_of_visits):
+ for i in range(d.no_of_visits):
child = addchild(self.doc, 'maintenance_schedule_detail',
'Maintenance Schedule Detail', self.doclist)
child.item_code = d.item_code
@@ -43,7 +42,7 @@
if d.serial_no:
child.serial_no = d.serial_no
child.idx = count
- count = count+1
+ count = count + 1
child.incharge_name = d.incharge_name
child.save(1)
@@ -51,8 +50,7 @@
def on_submit(self):
if not getlist(self.doclist, 'maintenance_schedule_detail'):
- msgprint("Please click on 'Generate Schedule' to get schedule")
- raise Exception
+ throw("Please click on 'Generate Schedule' to get schedule")
self.check_serial_no_added()
self.validate_serial_no_warranty()
self.validate_schedule()
@@ -66,9 +64,9 @@
email_map[d.incharge_name] = webnotes.bean("Sales Person",
d.incharge_name).run_method("get_email_id")
- scheduled_date =webnotes.conn.sql("select scheduled_date from `tabMaintenance Schedule Detail` \
- where incharge_name='%s' and item_code='%s' and parent='%s' " %(d.incharge_name, \
- d.item_code, self.doc.name), as_dict=1)
+ scheduled_date =webnotes.conn.sql("""select scheduled_date from
+ `tabMaintenance Schedule Detail` where incharge_name=%s and item_code=%s and
+ parent=%s""", (d.incharge_name, d.item_code, self.doc.name), as_dict=1)
for key in scheduled_date:
if email_map[d.incharge_name]:
@@ -91,90 +89,80 @@
#----------------------
def create_schedule_list(self, start_date, end_date, no_of_visit):
schedule_list = []
- start_date1 = start_date
+ start_date_copy = start_date
date_diff = (getdate(end_date) - getdate(start_date)).days
- add_by = date_diff/no_of_visit
- #schedule_list.append(start_date1)
- while(getdate(start_date1) < getdate(end_date)):
- start_date1 = add_days(start_date1, add_by)
+ add_by = date_diff / no_of_visit
+
+ while (getdate(start_date_copy) < getdate(end_date)):
+ start_date_copy = add_days(start_date_copy, add_by)
if len(schedule_list) < no_of_visit:
- schedule_list.append(getdate(start_date1))
+ schedule_list.append(getdate(start_date_copy))
return schedule_list
#validate date range and periodicity selected
#-------------------------------------------------
def validate_period(self, arg):
- arg1 = eval(arg)
- if getdate(arg1['start_date']) >= getdate(arg1['end_date']):
- msgprint("Start date should be less than end date ")
- raise Exception
-
- period = (getdate(arg1['end_date'])-getdate(arg1['start_date'])).days+1
-
- if (arg1['periodicity']=='Yearly' or arg1['periodicity']=='Half Yearly' or arg1['periodicity']=='Quarterly') and period<365:
- msgprint(cstr(arg1['periodicity'])+ " periodicity can be set for period of atleast 1 year or more only")
- raise Exception
- elif arg1['periodicity']=='Monthly' and period<30:
- msgprint("Monthly periodicity can be set for period of atleast 1 month or more")
- raise Exception
- elif arg1['periodicity']=='Weekly' and period<7:
- msgprint("Weekly periodicity can be set for period of atleast 1 week or more")
- raise Exception
+ args = eval(arg)
+ if getdate(args['start_date']) >= getdate(args['end_date']):
+ throw(_("Start date should be less than end date."))
+
+ period = (getdate(args['end_date']) - getdate(args['start_date'])).days + 1
+
+ if (args['periodicity'] == 'Yearly' or args['periodicity'] == 'Half Yearly' or
+ args['periodicity'] == 'Quarterly') and period < 365:
+ throw(cstr(args['periodicity']) + " periodicity can be set for period of atleast 1 year or more only")
+ elif args['periodicity'] == 'Monthly' and period < 30:
+ throw("Monthly periodicity can be set for period of atleast 1 month or more")
+ elif args['periodicity'] == 'Weekly' and period < 7:
+ throw("Weekly periodicity can be set for period of atleast 1 week or more")
def get_no_of_visits(self, arg):
- arg1 = eval(arg)
+ args = eval(arg)
self.validate_period(arg)
- period = (getdate(arg1['end_date'])-getdate(arg1['start_date'])).days+1
-
- count =0
- if arg1['periodicity'] == 'Weekly':
+ period = (getdate(args['end_date']) - getdate(args['start_date'])).days + 1
+ count = 0
+
+ if args['periodicity'] == 'Weekly':
count = period/7
- elif arg1['periodicity'] == 'Monthly':
+ elif args['periodicity'] == 'Monthly':
count = period/30
- elif arg1['periodicity'] == 'Quarterly':
+ elif args['periodicity'] == 'Quarterly':
count = period/91
- elif arg1['periodicity'] == 'Half Yearly':
+ elif args['periodicity'] == 'Half Yearly':
count = period/182
- elif arg1['periodicity'] == 'Yearly':
+ elif args['periodicity'] == 'Yearly':
count = period/365
- ret = {'no_of_visits':count}
+ ret = {'no_of_visits' : count}
return ret
-
-
def validate_maintenance_detail(self):
if not getlist(self.doclist, 'item_maintenance_detail'):
- msgprint("Please enter Maintaince Details first")
- raise Exception
+ throw(_("Please enter Maintaince Details first"))
for d in getlist(self.doclist, 'item_maintenance_detail'):
if not d.item_code:
- msgprint("Please select item code")
- raise Exception
+ throw(_("Please select item code"))
elif not d.start_date or not d.end_date:
- msgprint("Please select Start Date and End Date for item "+d.item_code)
- raise Exception
+ throw(_("Please select Start Date and End Date for item") + " " + d.item_code)
elif not d.no_of_visits:
- msgprint("Please mention no of visits required")
- raise Exception
+ throw(_("Please mention no of visits required"))
elif not d.incharge_name:
- msgprint("Please select Incharge Person's name")
- raise Exception
+ throw(_("Please select Incharge Person's name"))
if getdate(d.start_date) >= getdate(d.end_date):
- msgprint("Start date should be less than end date for item "+d.item_code)
- raise Exception
+ throw(_("Start date should be less than end date for item") + " " + d.item_code)
#check if maintenance schedule already created against same sales order
#-----------------------------------------------------------------------------------
def validate_sales_order(self):
for d in getlist(self.doclist, 'item_maintenance_detail'):
if d.prevdoc_docname:
- chk = webnotes.conn.sql("select t1.name from `tabMaintenance Schedule` t1, `tabMaintenance Schedule Item` t2 where t2.parent=t1.name and t2.prevdoc_docname=%s and t1.docstatus=1", d.prevdoc_docname)
+ chk = webnotes.conn.sql("""select ms.name from `tabMaintenance Schedule` ms,
+ `tabMaintenance Schedule Item` msi where msi.parent=ms.name and
+ msi.prevdoc_docname=%s and ms.docstatus=1""", d.prevdoc_docname)
if chk:
- msgprint("Maintenance Schedule against "+d.prevdoc_docname+" already exist")
- raise Exception
+ throw("Maintenance Schedule against " + d.prevdoc_docname + " already exist")
def validate_serial_no(self):
@@ -185,13 +173,13 @@
cur_s_no = cur_serial_no.split(',')
for x in cur_s_no:
- chk = webnotes.conn.sql("select name, status from `tabSerial No` where docstatus!=2 and name=%s", (x))
+ chk = webnotes.conn.sql("""select name, status from `tabSerial No`
+ where docstatus!=2 and name=%s""", (x))
chk1 = chk and chk[0][0] or ''
status = chk and chk[0][1] or ''
if not chk1:
- msgprint("Serial no "+x+" does not exist in system.")
- raise Exception
+ throw("Serial no " + x + " does not exist in system.")
def validate(self):
self.validate_maintenance_detail()
@@ -208,13 +196,13 @@
cur_s_no = cur_serial_no.split(',')
for x in cur_s_no:
- dt = webnotes.conn.sql("select delivery_date from `tabSerial No` where name = %s", x)
+ dt = webnotes.conn.sql("""select delivery_date from `tabSerial No`
+ where name=%s""", x)
dt = dt and dt[0][0] or ''
if dt:
if dt > getdate(d.start_date):
- msgprint("Maintenance start date can not be before delivery date "+dt.strftime('%Y-%m-%d')+" for serial no "+x)
- raise Exception
+ throw("Maintenance start date can not be before delivery date " + dt.strftime('%Y-%m-%d') + " for serial no " + x)
#update amc expiry date in serial no
#------------------------------------------
@@ -224,7 +212,8 @@
cur_s_no = cur_serial_no.split(',')
for x in cur_s_no:
- webnotes.conn.sql("update `tabSerial No` set amc_expiry_date = '%s', maintenance_status = 'Under AMC' where name = '%s'"% (amc_end_date,x))
+ webnotes.conn.sql("""update `tabSerial No` set amc_expiry_date=%s,
+ maintenance_status='Under AMC' where name=%s""", (amc_end_date, x))
def on_update(self):
webnotes.conn.set(self.doc, 'status', 'Draft')
@@ -233,16 +222,16 @@
for d in getlist(self.doclist, 'item_maintenance_detail'):
if cstr(d.serial_no).strip():
dt = webnotes.conn.sql("""select warranty_expiry_date, amc_expiry_date
- from `tabSerial No` where name = %s""", d.serial_no, as_dict=1)
+ from `tabSerial No` where name=%s""", d.serial_no, as_dict=1)
if dt[0]['warranty_expiry_date'] and dt[0]['warranty_expiry_date'] >= d.start_date:
- webnotes.msgprint("""Serial No: %s is already under warranty upto %s.
+ throw("""Serial No: %s is already under warranty upto %s.
Please check AMC Start Date.""" %
- (d.serial_no, dt[0]["warranty_expiry_date"]), raise_exception=1)
+ (d.serial_no, dt[0]["warranty_expiry_date"]))
if dt[0]['amc_expiry_date'] and dt[0]['amc_expiry_date'] >= d.start_date:
- webnotes.msgprint("""Serial No: %s is already under AMC upto %s.
+ throw("""Serial No: %s is already under AMC upto %s.
Please check AMC Start Date.""" %
- (d.serial_no, dt[0]["amc_expiry_date"]), raise_exception=1)
+ (d.serial_no, dt[0]["amc_expiry_date"]))
def validate_schedule(self):
item_lst1 =[]
@@ -256,13 +245,11 @@
item_lst2.append(m.item_code)
if len(item_lst1) != len(item_lst2):
- msgprint("Maintenance Schedule is not generated for all the items. Please click on 'Generate Schedule'")
- raise Exception
+ throw("Maintenance Schedule is not generated for all the items. Please click on 'Generate Schedule'")
else:
for x in item_lst1:
if x not in item_lst2:
- msgprint("Maintenance Schedule is not generated for item "+x+". Please click on 'Generate Schedule'")
- raise Exception
+ throw("Maintenance Schedule is not generated for item "+x+". Please click on 'Generate Schedule'")
#check if serial no present in item maintenance table
#-----------------------------------------------------------
@@ -275,18 +262,15 @@
for m in getlist(self.doclist, 'maintenance_schedule_detail'):
if serial_present:
if m.item_code in serial_present and not m.serial_no:
- msgprint("Please click on 'Generate Schedule' to fetch serial no added for item "+m.item_code)
- raise Exception
-
-
-
+ throw("Please click on 'Generate Schedule' to fetch serial no added for item "+m.item_code)
+
def on_cancel(self):
for d in getlist(self.doclist, 'item_maintenance_detail'):
if d.serial_no:
self.update_amc_date(d.serial_no, '')
webnotes.conn.set(self.doc, 'status', 'Cancelled')
delete_events(self.doc.doctype, self.doc.name)
-
+
def on_trash(self):
delete_events(self.doc.doctype, self.doc.name)
diff --git a/erpnext/support/doctype/maintenance_schedule_detail/maintenance_schedule_detail.txt b/erpnext/support/doctype/maintenance_schedule_detail/maintenance_schedule_detail.txt
index 8b52d8b..7a79d8d 100644
--- a/erpnext/support/doctype/maintenance_schedule_detail/maintenance_schedule_detail.txt
+++ b/erpnext/support/doctype/maintenance_schedule_detail/maintenance_schedule_detail.txt
@@ -2,7 +2,7 @@
{
"creation": "2013-02-22 01:28:05",
"docstatus": 0,
- "modified": "2013-12-20 19:23:20",
+ "modified": "2013-12-30 19:32:30",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -52,6 +52,7 @@
"search_index": 0
},
{
+ "allow_on_submit": 1,
"doctype": "DocField",
"fieldname": "scheduled_date",
"fieldtype": "Date",
@@ -78,6 +79,7 @@
"report_hide": 1
},
{
+ "allow_on_submit": 1,
"doctype": "DocField",
"fieldname": "incharge_name",
"fieldtype": "Link",