Merge pull request #1261 from akhileshdarjee/maintenance2

Fixed Maintenance Schedule
This commit is contained in:
Nabin Hait 2014-01-27 03:57:15 -08:00
commit db7901ec49
13 changed files with 322 additions and 288 deletions

View File

@ -4,10 +4,10 @@
wn.provide("erpnext.hr"); wn.provide("erpnext.hr");
erpnext.hr.EmployeeController = wn.ui.form.Controller.extend({ erpnext.hr.EmployeeController = wn.ui.form.Controller.extend({
setup: function() { setup: function() {
this.frm.fields_dict.user_id.get_query = function(doc,cdt,cdn) { this.frm.fields_dict.user_id.get_query = function(doc, cdt, cdn) {
return { query:"webnotes.core.doctype.profile.profile.profile_query"} } return { query:"webnotes.core.doctype.profile.profile.profile_query"} }
this.frm.fields_dict.reports_to.get_query = function(doc,cdt,cdn) { this.frm.fields_dict.reports_to.get_query = function(doc, cdt, cdn) {
return{ query: "erpnext.controllers.queries.employee_query"} } return { query: "erpnext.controllers.queries.employee_query"} }
}, },
onload: function() { onload: function() {
@ -93,4 +93,4 @@ erpnext.hr.EmployeeController = wn.ui.form.Controller.extend({
}); });
}, },
}); });
cur_frm.cscript = new erpnext.hr.EmployeeController({frm: cur_frm}); cur_frm.cscript = new erpnext.hr.EmployeeController({frm: cur_frm});

View File

@ -8,9 +8,7 @@ from webnotes.utils import add_days, add_years, cint, getdate
from webnotes.model import db_exists from webnotes.model import db_exists
from webnotes.model.doc import addchild, make_autoname from webnotes.model.doc import addchild, make_autoname
from webnotes.model.bean import copy_doclist from webnotes.model.bean import copy_doclist
from webnotes import msgprint from webnotes import msgprint, throw, _
import datetime import datetime
class DocType: class DocType:
@ -19,7 +17,7 @@ class DocType:
self.doclist = doclist self.doclist = doclist
def autoname(self): def autoname(self):
self.doc.name = make_autoname(self.doc.fiscal_year +"/"+ self.doc.holiday_list_name+"/.###") self.doc.name = make_autoname(self.doc.fiscal_year + "/" + self.doc.holiday_list_name + "/.###")
def validate(self): def validate(self):
self.update_default_holiday_list() self.update_default_holiday_list()
@ -38,11 +36,9 @@ class DocType:
def validate_values(self): def validate_values(self):
if not self.doc.fiscal_year: if not self.doc.fiscal_year:
msgprint("Please select Fiscal Year") throw(_("Please select Fiscal Year"))
raise Exception
if not self.doc.weekly_off: if not self.doc.weekly_off:
msgprint("Please select weekly off day") throw(_("Please select weekly off day"))
raise Exception
def get_fy_start_end_dates(self): def get_fy_start_end_dates(self):
return webnotes.conn.sql("""select year_start_date, year_end_date return webnotes.conn.sql("""select year_start_date, year_end_date

View File

@ -2,7 +2,7 @@ erpnext.patches.1401.enable_all_price_list
erpnext.patches.4_0.update_user_properties erpnext.patches.4_0.update_user_properties
erpnext.patches.4_0.move_warehouse_user_to_restrictions erpnext.patches.4_0.move_warehouse_user_to_restrictions
erpnext.patches.4_0.new_permissions erpnext.patches.4_0.new_permissions
erpnext.patches.4_0.update_incharge_name_to_sales_person_in_maintenance_schedule
execute:webnotes.reload_doc('accounts', 'doctype', 'sales_invoice') # 2014-01-03 execute:webnotes.reload_doc('accounts', 'doctype', 'sales_invoice') # 2014-01-03
execute:webnotes.reload_doc('selling', 'doctype', 'sales_order') # 2014-01-03 execute:webnotes.reload_doc('selling', 'doctype', 'sales_order') # 2014-01-03
execute:webnotes.reload_doc('selling', 'doctype', 'quotation') # 2014-01-03 execute:webnotes.reload_doc('selling', 'doctype', 'quotation') # 2014-01-03
@ -19,4 +19,4 @@ execute:webnotes.reload_doc('selling', 'Print Format', 'Sales Order Modern') # 2
execute:webnotes.reload_doc('selling', 'Print Format', 'Sales Order Spartan') # 2014-01-03 execute:webnotes.reload_doc('selling', 'Print Format', 'Sales Order Spartan') # 2014-01-03
execute:webnotes.reload_doc('stock', 'Print Format', 'Delivery Note Classic') # 2014-01-03 execute:webnotes.reload_doc('stock', 'Print Format', 'Delivery Note Classic') # 2014-01-03
execute:webnotes.reload_doc('stock', 'Print Format', 'Delivery Note Modern') # 2014-01-03 execute:webnotes.reload_doc('stock', 'Print Format', 'Delivery Note Modern') # 2014-01-03
execute:webnotes.reload_doc('stock', 'Print Format', 'Delivery Note Spartan') # 2014-01-03 execute:webnotes.reload_doc('stock', 'Print Format', 'Delivery Note Spartan') # 2014-01-03

View File

@ -0,0 +1,12 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import webnotes
def execute():
webnotes.reload_doc("support", "doctype", "maintenance_schedule_detail")
webnotes.reload_doc("support", "doctype", "maintenance_schedule_item")
webnotes.conn.sql("""update `tabMaintenance Schedule Detail` set sales_person=incharge_name""")
webnotes.conn.sql("""update `tabMaintenance Schedule Item` set sales_person=incharge_name""")

View File

@ -7,18 +7,18 @@
wn.provide("erpnext"); wn.provide("erpnext");
erpnext.LeadController = wn.ui.form.Controller.extend({ erpnext.LeadController = wn.ui.form.Controller.extend({
setup: function() { setup: function() {
this.frm.fields_dict.customer.get_query = function(doc,cdt,cdn) { this.frm.fields_dict.customer.get_query = function(doc, cdt, cdn) {
return { query: "erpnext.controllers.queries.customer_query" } } return { query: "erpnext.controllers.queries.customer_query" } }
}, },
onload: function() { onload: function() {
if(cur_frm.fields_dict.lead_owner.df.options.match(/^Profile/)) { if(cur_frm.fields_dict.lead_owner.df.options.match(/^Profile/)) {
cur_frm.fields_dict.lead_owner.get_query = function(doc,cdt,cdn) { cur_frm.fields_dict.lead_owner.get_query = function(doc, cdt, cdn) {
return { query:"webnotes.core.doctype.profile.profile.profile_query" } } return { query:"webnotes.core.doctype.profile.profile.profile_query" } }
} }
if(cur_frm.fields_dict.contact_by.df.options.match(/^Profile/)) { if(cur_frm.fields_dict.contact_by.df.options.match(/^Profile/)) {
cur_frm.fields_dict.contact_by.get_query = function(doc,cdt,cdn) { cur_frm.fields_dict.contact_by.get_query = function(doc, cdt, cdn) {
return { query:"webnotes.core.doctype.profile.profile.profile_query" } } return { query:"webnotes.core.doctype.profile.profile.profile_query" } }
} }
@ -90,4 +90,4 @@ erpnext.LeadController = wn.ui.form.Controller.extend({
} }
}); });
$.extend(cur_frm.cscript, new erpnext.LeadController({frm: cur_frm})); $.extend(cur_frm.cscript, new erpnext.LeadController({frm: cur_frm}));

View File

@ -1,114 +1,113 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt // License: GNU General Public License v3. See license.txt
//--------- ONLOAD -------------
cur_frm.cscript.onload = function(doc, cdt, cdn) {
}
// Settings Module // Settings Module
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
if (doc.based_on == 'Grand Total' || doc.based_on == 'Average Discount' || doc.based_on == 'Not Applicable')
hide_field('master_name');
else
unhide_field('master_name');
cur_frm.cscript.refresh = function(doc,cdt,cdn){ if (doc.based_on == 'Not Applicable')
hide_field('value');
else
unhide_field('value');
if(doc.based_on == 'Grand Total' || doc.based_on == 'Average Discount' || doc.based_on == 'Not Applicable') hide_field('master_name'); if (doc.transaction == 'Appraisal') {
else unhide_field('master_name'); hide_field(['master_name','system_role', 'system_user']);
unhide_field(['to_emp','to_designation']);
if(doc.based_on == 'Not Applicable') hide_field('value');
else unhide_field('value'); if (doc.transaction == 'Appraisal')
hide_field('value');
if(doc.transaction == 'Appraisal'){ else
hide_field(['master_name','system_role', 'system_user']); unhide_field('value');
unhide_field(['to_emp','to_designation']); }
if(doc.transaction == 'Appraisal') hide_field('value'); else {
else unhide_field('value'); unhide_field(['master_name','system_role', 'system_user','value']);
} hide_field(['to_emp','to_designation']);
else { }
unhide_field(['master_name','system_role', 'system_user','value']);
hide_field(['to_emp','to_designation']);
}
} }
cur_frm.cscript.based_on = function(doc){ cur_frm.cscript.based_on = function(doc) {
if(doc.based_on == 'Grand Total' || doc.based_on == 'Average Discount' || doc.based_on == 'Not Applicable'){ if (doc.based_on == 'Grand Total' || doc.based_on == 'Average Discount' || doc.based_on == 'Not Applicable') {
doc.master_name = ''; doc.master_name = '';
refresh_field('master_name'); refresh_field('master_name');
hide_field('master_name'); hide_field('master_name');
} }
else{ else
unhide_field('master_name'); unhide_field('master_name');
}
if (doc.based_on == 'Not Applicable') {
if(doc.based_on == 'Not Applicable') { doc.value =0;
doc.value =0; refresh_field('value');
refresh_field('value'); hide_field('value');
hide_field('value'); }
} else
else unhide_field('value'); unhide_field('value');
} }
cur_frm.cscript.transaction = function(doc,cdt,cdn){ cur_frm.cscript.transaction = function(doc, cdt, cdn){
if (doc.transaction == 'Appraisal'){ if (doc.transaction == 'Appraisal') {
doc.master_name = doc.system_role = doc.system_user = ''; doc.based_on == 'Not Applicable';
refresh_many(['master_name','system_role', 'system_user']); doc.master_name = doc.system_role = doc.system_user = '';
hide_field(['master_name','system_role', 'system_user']); refresh_many(['master_name','system_role', 'system_user', 'based_on']);
unhide_field(['to_emp','to_designation']); hide_field(['master_name','system_role', 'system_user']);
doc.value =0; unhide_field(['to_emp','to_designation']);
refresh_many('value'); doc.value = 0;
hide_field('value'); refresh_many('value');
} hide_field('value');
else { }
unhide_field(['master_name','system_role', 'system_user','value']); else {
hide_field(['to_emp','to_designation']); unhide_field(['master_name','system_role', 'system_user','value']);
} hide_field(['to_emp','to_designation']);
}
if(doc.transaction == 'Appraisal') doc.based_on == 'Not Applicable';
} }
cur_frm.fields_dict.system_user.get_query = function(doc, cdt, cdn) {
return { query:"webnotes.core.doctype.profile.profile.profile_query" }
}
cur_frm.fields_dict.system_user.get_query = function(doc,cdt,cdn) { cur_frm.fields_dict.approving_user.get_query = function(doc, cdt, cdn) {
return{ query:"webnotes.core.doctype.profile.profile.profile_query" } } return { query:"webnotes.core.doctype.profile.profile.profile_query" }
}
cur_frm.fields_dict.approving_user.get_query = function(doc,cdt,cdn) {
return{ query:"webnotes.core.doctype.profile.profile.profile_query" } }
cur_frm.fields_dict['approving_role'].get_query = cur_frm.fields_dict['system_role'].get_query; cur_frm.fields_dict['approving_role'].get_query = cur_frm.fields_dict['system_role'].get_query;
// System Role Trigger // System Role Trigger
// ----------------------- // -----------------------
cur_frm.fields_dict['system_role'].get_query = function(doc) { cur_frm.fields_dict['system_role'].get_query = function(doc) {
return{ return {
filters:[ filters:[
['Role', 'name', 'not in', 'Administrator, Guest, All'] ['Role', 'name', 'not in', 'Administrator, Guest, All']
] ]
} }
} }
// Master Name Trigger // Master Name Trigger
// -------------------- // --------------------
cur_frm.fields_dict['master_name'].get_query = function(doc){ cur_frm.fields_dict['master_name'].get_query = function(doc) {
if(doc.based_on == 'Customerwise Discount') if (doc.based_on == 'Customerwise Discount')
return { return {
doctype: "Customer", doctype: "Customer",
filters:[ filters:[
['Customer', 'docstatus', '!=', 2] ['Customer', 'docstatus', '!=', 2]
] ]
} }
else if(doc.based_on == 'Itemwise Discount') else if (doc.based_on == 'Itemwise Discount')
return { return {
doctype: "Item", doctype: "Item",
query: "erpnext.controllers.queries.item_query" query: "erpnext.controllers.queries.item_query"
} }
else else
return { return {
filters: [ filters: [
['Item', 'name', '=', 'cheating done to avoid null'] ['Item', 'name', '=', 'cheating done to avoid null']
] ]
} }
} }
cur_frm.fields_dict.to_emp.get_query = function(doc,cdt,cdn) { cur_frm.fields_dict.to_emp.get_query = function(doc, cdt, cdn) {
return{ query: "erpnext.controllers.queries.employee_query" } } return { query: "erpnext.controllers.queries.employee_query" }
}

View File

@ -15,15 +15,10 @@ cur_frm.cscript.set_root_readonly = function(doc) {
} }
} }
cur_frm.cscript.onload = function(){
}
//get query select sales person //get query select sales person
cur_frm.fields_dict['parent_sales_person'].get_query = function(doc,cdt,cdn) { cur_frm.fields_dict['parent_sales_person'].get_query = function(doc, cdt, cdn) {
return{ return{
filters:[ filters: [
['Sales Person', 'is_group', '=', 'Yes'], ['Sales Person', 'is_group', '=', 'Yes'],
['Sales Person', 'name', '!=', doc.sales_person_name] ['Sales Person', 'name', '!=', doc.sales_person_name]
] ]
@ -31,10 +26,11 @@ cur_frm.fields_dict['parent_sales_person'].get_query = function(doc,cdt,cdn) {
} }
cur_frm.fields_dict['target_details'].grid.get_field("item_group").get_query = function(doc, cdt, cdn) { cur_frm.fields_dict['target_details'].grid.get_field("item_group").get_query = function(doc, cdt, cdn) {
return{ return {
filters:{ 'is_group': "No" } filters: { 'is_group': "No" }
} }
} }
cur_frm.fields_dict.employee.get_query = function(doc,cdt,cdn) { cur_frm.fields_dict.employee.get_query = function(doc, cdt, cdn) {
return{ query: "erpnext.controllers.queries.employee_query" } } return { query: "erpnext.controllers.queries.employee_query" }
}

View File

@ -3,10 +3,8 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes import webnotes
from webnotes.model.bean import getlist from webnotes.model.bean import getlist
from webnotes.utils import flt from webnotes.utils import flt
from webnotes.utils.nestedset import DocTypeNestedSet from webnotes.utils.nestedset import DocTypeNestedSet
class DocType(DocTypeNestedSet): class DocType(DocTypeNestedSet):
@ -18,8 +16,7 @@ class DocType(DocTypeNestedSet):
def validate(self): def validate(self):
for d in getlist(self.doclist, 'target_details'): for d in getlist(self.doclist, 'target_details'):
if not flt(d.target_qty) and not flt(d.target_amount): if not flt(d.target_qty) and not flt(d.target_amount):
webnotes.msgprint("Either target qty or target amount is mandatory.") webnotes.throw(_("Either target qty or target amount is mandatory."))
raise Exception
def on_update(self): def on_update(self):
super(DocType, self).on_update() super(DocType, self).on_update()
@ -28,8 +25,7 @@ class DocType(DocTypeNestedSet):
def get_email_id(self): def get_email_id(self):
profile = webnotes.conn.get_value("Employee", self.doc.employee, "user_id") profile = webnotes.conn.get_value("Employee", self.doc.employee, "user_id")
if not profile: if not profile:
webnotes.msgprint("User ID (Profile) no set for Employee %s" % self.doc.employee, webnotes.throw("User ID (Profile) not set for Employee %s" % self.doc.employee)
raise_exception=True)
else: else:
return webnotes.conn.get_value("Profile", profile, "email") or profile return webnotes.conn.get_value("Profile", profile, "email") or profile

View File

@ -5,107 +5,117 @@ wn.provide("erpnext.support");
// TODO commonify this code // TODO commonify this code
erpnext.support.MaintenanceSchedule = wn.ui.form.Controller.extend({ erpnext.support.MaintenanceSchedule = wn.ui.form.Controller.extend({
refresh: function() { refresh: function() {
if (this.frm.doc.docstatus===0) { var me = this;
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() { function() {
wn.model.map_current_doc({ wn.model.map_current_doc({
method: "erpnext.selling.doctype.sales_order.sales_order.make_maintenance_schedule", method: "erpnext.selling.doctype.sales_order.sales_order.make_maintenance_schedule",
source_doctype: "Sales Order", source_doctype: "Sales Order",
get_query_filters: { get_query_filters: {
docstatus: 1, docstatus: 1,
order_type: cur_frm.doc.order_type, order_type: me.frm.doc.order_type,
customer: cur_frm.doc.customer || undefined, customer: me.frm.doc.customer || undefined,
company: cur_frm.doc.company company: me.frm.doc.company
} }
}) });
}); });
} else if (this.frm.doc.docstatus===1) { } else if (this.frm.doc.docstatus === 1) {
cur_frm.add_custom_button(wn._("Make Maintenance Visit"), function() { this.frm.add_custom_button(wn._("Make Maintenance Visit"), function() {
wn.model.open_mapped_doc({ wn.model.open_mapped_doc({
method: "erpnext.support.doctype.maintenance_schedule.maintenance_schedule.make_maintenance_visit", method: "erpnext.support.doctype.maintenance_schedule.maintenance_schedule.make_maintenance_visit",
source_name: cur_frm.doc.name source_name: me.frm.doc.name
}) })
}) });
} }
}, },
customer: function() { customer: function() {
var me = this; var me = this;
if(this.frm.doc.customer) { if(this.frm.doc.customer) {
return this.frm.call({ return this.frm.call({
doc: this.frm.doc, doc: me.frm.doc,
method: "set_customer_defaults", method: "set_customer_defaults",
}); });
} }
}, },
}); });
$.extend(cur_frm.cscript, new erpnext.support.MaintenanceSchedule({frm: cur_frm})); $.extend(cur_frm.cscript, new erpnext.support.MaintenanceSchedule({frm: cur_frm}));
cur_frm.cscript.onload = function(doc, dt, dn) { cur_frm.cscript.onload = function(doc, dt, dn) {
if(!doc.status) set_multiple(dt,dn,{status:'Draft'}); if (!doc.status)
set_multiple(dt, dn, { status:'Draft' });
if(doc.__islocal){
set_multiple(dt,dn,{transaction_date:get_today()}); if (doc.__islocal) {
hide_field(['customer_address','contact_person','customer_name','address_display','contact_display','contact_mobile','contact_email','territory','customer_group']); 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) { 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); 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) { cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) {
return{ return {
filters:{ 'customer': doc.customer} filters:{ 'customer': doc.customer }
} }
} }
cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) { cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) {
return{ return {
filters:{ 'customer': doc.customer} filters:{ 'customer': doc.customer }
} }
} }
// //
cur_frm.fields_dict['item_maintenance_detail'].grid.get_field('item_code').get_query = function(doc, cdt, cdn) { cur_frm.fields_dict['item_maintenance_detail'].grid.get_field('item_code').get_query = function(doc, cdt, cdn) {
return{ return {
filters:{ 'is_service_item': "Yes"} filters:{ 'is_service_item': "Yes" }
} }
} }
cur_frm.cscript.item_code = function(doc, cdt, cdn) { cur_frm.cscript.item_code = function(doc, cdt, cdn) {
var fname = cur_frm.cscript.fname; var fname = cur_frm.cscript.fname;
var d = locals[cdt][cdn]; var d = locals[cdt][cdn];
if (d.item_code) { if (d.item_code) {
return get_server_fields('get_item_details',d.item_code, 'item_maintenance_detail',doc,cdt,cdn,1); 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){ cur_frm.cscript.periodicity = function(doc, cdt, cdn){
var d = locals[cdt][cdn]; var d = locals[cdt][cdn];
if(d.start_date && d.end_date){ if(d.start_date && d.end_date) {
arg = {} arg = {}
arg.start_date = d.start_date; arg.start_date = d.start_date;
arg.end_date = d.end_date; arg.end_date = d.end_date;
arg.periodicity = d.periodicity; arg.periodicity = d.periodicity;
return get_server_fields('get_no_of_visits',docstring(arg),'item_maintenance_detail',doc, cdt, cdn, 1); return get_server_fields('get_no_of_visits', docstring(arg),
} 'item_maintenance_detail', doc, cdt, cdn, 1);
else{ } else {
msgprint(wn._("Please enter Start Date and End Date")); msgprint(wn._("Please enter Start Date and End Date"));
} }
} }
cur_frm.cscript.generate_schedule = function(doc, cdt, cdn) { cur_frm.cscript.generate_schedule = function(doc, cdt, cdn) {
if (!doc.__islocal) { if (!doc.__islocal) {
return $c('runserverobj', args={'method':'generate_schedule', 'docs':wn.model.compress(make_doclist(cdt,cdn))}, return $c('runserverobj', args={'method':'generate_schedule',
function(r,rt){ 'docs':wn.model.compress(make_doclist(cdt,cdn))},
refresh_field('maintenance_schedule_detail'); function(r, rt) {
} refresh_field('maintenance_schedule_detail');
); });
} else { } else {
alert(wn._("Please save the document before generating maintenance schedule")); msgprint(wn._("Please save the document before generating maintenance schedule"));
} }
} }
cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) { 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" }
}

View File

@ -4,13 +4,10 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes import webnotes
from webnotes.utils import add_days, cstr, getdate from webnotes.utils import add_days, cstr, getdate, cint
from webnotes.model.doc import addchild from webnotes.model.doc import addchild
from webnotes.model.bean import getlist from webnotes.model.bean import getlist
from webnotes import msgprint from webnotes import msgprint, throw, _
from erpnext.utilities.transaction_base import TransactionBase, delete_events from erpnext.utilities.transaction_base import TransactionBase, delete_events
class DocType(TransactionBase): class DocType(TransactionBase):
@ -19,7 +16,8 @@ class DocType(TransactionBase):
self.doclist = doclist self.doclist = doclist
def get_item_details(self, item_code): 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 = { ret = {
'item_name': item and item[0]['item_name'] or '', 'item_name': item and item[0]['item_name'] or '',
'description' : item and item[0]['description'] or '' 'description' : item and item[0]['description'] or ''
@ -28,13 +26,14 @@ class DocType(TransactionBase):
def generate_schedule(self): def generate_schedule(self):
self.doclist = self.doc.clear_table(self.doclist, 'maintenance_schedule_detail') self.doclist = self.doc.clear_table(self.doclist, 'maintenance_schedule_detail')
count = 0 webnotes.conn.sql("""delete from `tabMaintenance Schedule Detail`
webnotes.conn.sql("delete from `tabMaintenance Schedule Detail` where parent='%s'" %(self.doc.name)) where parent=%s""", (self.doc.name))
count = 1
for d in getlist(self.doclist, 'item_maintenance_detail'): for d in getlist(self.doclist, 'item_maintenance_detail'):
self.validate_maintenance_detail() self.validate_maintenance_detail()
s_list =[] s_list = []
s_list = self.create_schedule_list(d.start_date, d.end_date, d.no_of_visits) s_list = self.create_schedule_list(d.start_date, d.end_date, d.no_of_visits, d.sales_person)
for i in range(d.no_of_visits): for i in range(d.no_of_visits):
child = addchild(self.doc, 'maintenance_schedule_detail', child = addchild(self.doc, 'maintenance_schedule_detail',
'Maintenance Schedule Detail', self.doclist) 'Maintenance Schedule Detail', self.doclist)
child.item_code = d.item_code child.item_code = d.item_code
@ -43,40 +42,39 @@ class DocType(TransactionBase):
if d.serial_no: if d.serial_no:
child.serial_no = d.serial_no child.serial_no = d.serial_no
child.idx = count child.idx = count
count = count+1 count = count + 1
child.incharge_name = d.incharge_name child.sales_person = d.sales_person
child.save(1) child.save(1)
self.on_update() self.on_update()
def on_submit(self): def on_submit(self):
if not getlist(self.doclist, 'maintenance_schedule_detail'): if not getlist(self.doclist, 'maintenance_schedule_detail'):
msgprint("Please click on 'Generate Schedule' to get schedule") throw("Please click on 'Generate Schedule' to get schedule")
raise Exception
self.check_serial_no_added() self.check_serial_no_added()
self.validate_serial_no_warranty() self.validate_serial_no_warranty()
self.validate_schedule() self.validate_schedule()
email_map ={} email_map = {}
for d in getlist(self.doclist, 'item_maintenance_detail'): for d in getlist(self.doclist, 'item_maintenance_detail'):
if d.serial_no: if d.serial_no:
self.update_amc_date(d.serial_no, d.end_date) self.update_amc_date(d.serial_no, d.end_date)
if d.incharge_name not in email_map: if d.sales_person not in email_map:
email_map[d.incharge_name] = webnotes.bean("Sales Person", sp = webnotes.bean("Sales Person", d.sales_person).make_controller()
d.incharge_name).run_method("get_email_id") email_map[d.sales_person] = sp.get_email_id()
scheduled_date =webnotes.conn.sql("select scheduled_date from `tabMaintenance Schedule Detail` \ scheduled_date = webnotes.conn.sql("""select scheduled_date from
where incharge_name='%s' and item_code='%s' and parent='%s' " %(d.incharge_name, \ `tabMaintenance Schedule Detail` where sales_person=%s and item_code=%s and
d.item_code, self.doc.name), as_dict=1) parent=%s""", (d.sales_person, d.item_code, self.doc.name), as_dict=1)
for key in scheduled_date: for key in scheduled_date:
if email_map[d.incharge_name]: if email_map[d.sales_person]:
description = "Reference: %s, Item Code: %s and Customer: %s" % \ description = "Reference: %s, Item Code: %s and Customer: %s" % \
(self.doc.name, d.item_code, self.doc.customer) (self.doc.name, d.item_code, self.doc.customer)
webnotes.bean({ webnotes.bean({
"doctype": "Event", "doctype": "Event",
"owner": email_map[d.incharge_name] or self.doc.owner, "owner": email_map[d.sales_person] or self.doc.owner,
"subject": description, "subject": description,
"description": description, "description": description,
"starts_on": key["scheduled_date"] + " 10:00:00", "starts_on": key["scheduled_date"] + " 10:00:00",
@ -89,92 +87,121 @@ class DocType(TransactionBase):
#get schedule dates #get schedule dates
#---------------------- #----------------------
def create_schedule_list(self, start_date, end_date, no_of_visit): def create_schedule_list(self, start_date, end_date, no_of_visit, sales_person):
schedule_list = [] schedule_list = []
start_date1 = start_date start_date_copy = start_date
date_diff = (getdate(end_date) - getdate(start_date)).days date_diff = (getdate(end_date) - getdate(start_date)).days
add_by = date_diff/no_of_visit add_by = date_diff / no_of_visit
#schedule_list.append(start_date1)
while(getdate(start_date1) < getdate(end_date)): for visit in range(cint(no_of_visit)):
start_date1 = add_days(start_date1, add_by) if (getdate(start_date_copy) < getdate(end_date)):
if len(schedule_list) < no_of_visit: start_date_copy = add_days(start_date_copy, add_by)
schedule_list.append(getdate(start_date1)) if len(schedule_list) < no_of_visit:
schedule_date = self.validate_schedule_date_for_holiday_list(getdate(start_date_copy),
sales_person)
if schedule_date > getdate(end_date):
schedule_date = getdate(end_date)
schedule_list.append(schedule_date)
return schedule_list return schedule_list
def validate_schedule_date_for_holiday_list(self, schedule_date, sales_person):
from erpnext.accounts.utils import get_fiscal_year
validated = False
fy_details = ""
try:
fy_details = get_fiscal_year(date=schedule_date, verbose=0)
except Exception:
pass
if fy_details and fy_details[0]:
# check holiday list in employee master
holiday_list = webnotes.conn.sql_list("""select h.holiday_date from `tabEmployee` emp,
`tabSales Person` sp, `tabHoliday` h, `tabHoliday List` hl
where sp.name=%s and emp.name=sp.employee
and hl.name=emp.holiday_list and
h.parent=hl.name and
hl.fiscal_year=%s""", (sales_person, fy_details[0]))
if not holiday_list:
# check global holiday list
holiday_list = webnotes.conn.sql("""select h.holiday_date from
`tabHoliday` h, `tabHoliday List` hl
where h.parent=hl.name and ifnull(hl.is_default, 0) = 1
and hl.fiscal_year=%s""", fy_details[0])
if not validated and holiday_list:
if schedule_date in holiday_list:
schedule_date = add_days(schedule_date, -1)
else:
validated = True
return schedule_date
#validate date range and periodicity selected #validate date range and periodicity selected
#------------------------------------------------- #-------------------------------------------------
def validate_period(self, arg): def validate_period(self, arg):
arg1 = eval(arg) args = eval(arg)
if getdate(arg1['start_date']) >= getdate(arg1['end_date']): if getdate(args['start_date']) >= getdate(args['end_date']):
msgprint("Start date should be less than end date ") throw(_("Start date should be less than end date."))
raise Exception
period = (getdate(args['end_date']) - getdate(args['start_date'])).days + 1
period = (getdate(arg1['end_date'])-getdate(arg1['start_date'])).days+1
if (args['periodicity'] == 'Yearly' or args['periodicity'] == 'Half Yearly' or
if (arg1['periodicity']=='Yearly' or arg1['periodicity']=='Half Yearly' or arg1['periodicity']=='Quarterly') and period<365: args['periodicity'] == 'Quarterly') and period < 365:
msgprint(cstr(arg1['periodicity'])+ " periodicity can be set for period of atleast 1 year or more only") throw(cstr(args['periodicity']) + " periodicity can be set for period of atleast 1 year or more only")
raise Exception elif args['periodicity'] == 'Monthly' and period < 30:
elif arg1['periodicity']=='Monthly' and period<30: throw("Monthly periodicity can be set for period of atleast 1 month or more")
msgprint("Monthly periodicity can be set for period of atleast 1 month or more") elif args['periodicity'] == 'Weekly' and period < 7:
raise Exception throw("Weekly periodicity can be set for period of atleast 1 week or more")
elif arg1['periodicity']=='Weekly' and period<7:
msgprint("Weekly periodicity can be set for period of atleast 1 week or more")
raise Exception
def get_no_of_visits(self, arg): def get_no_of_visits(self, arg):
arg1 = eval(arg) args = eval(arg)
self.validate_period(arg) self.validate_period(arg)
period = (getdate(arg1['end_date'])-getdate(arg1['start_date'])).days+1 period = (getdate(args['end_date']) - getdate(args['start_date'])).days + 1
count = 0
count =0
if arg1['periodicity'] == 'Weekly': if args['periodicity'] == 'Weekly':
count = period/7 count = period/7
elif arg1['periodicity'] == 'Monthly': elif args['periodicity'] == 'Monthly':
count = period/30 count = period/30
elif arg1['periodicity'] == 'Quarterly': elif args['periodicity'] == 'Quarterly':
count = period/91 count = period/91
elif arg1['periodicity'] == 'Half Yearly': elif args['periodicity'] == 'Half Yearly':
count = period/182 count = period/182
elif arg1['periodicity'] == 'Yearly': elif args['periodicity'] == 'Yearly':
count = period/365 count = period/365
ret = {'no_of_visits':count} ret = {'no_of_visits' : count}
return ret return ret
def validate_maintenance_detail(self): def validate_maintenance_detail(self):
if not getlist(self.doclist, 'item_maintenance_detail'): if not getlist(self.doclist, 'item_maintenance_detail'):
msgprint("Please enter Maintaince Details first") throw(_("Please enter Maintaince Details first"))
raise Exception
for d in getlist(self.doclist, 'item_maintenance_detail'): for d in getlist(self.doclist, 'item_maintenance_detail'):
if not d.item_code: if not d.item_code:
msgprint("Please select item code") throw(_("Please select item code"))
raise Exception
elif not d.start_date or not d.end_date: elif not d.start_date or not d.end_date:
msgprint("Please select Start Date and End Date for item "+d.item_code) throw(_("Please select Start Date and End Date for item") + " " + d.item_code)
raise Exception
elif not d.no_of_visits: elif not d.no_of_visits:
msgprint("Please mention no of visits required") throw(_("Please mention no of visits required"))
raise Exception elif not d.sales_person:
elif not d.incharge_name: throw(_("Please select Incharge Person's name"))
msgprint("Please select Incharge Person's name")
raise Exception
if getdate(d.start_date) >= getdate(d.end_date): if getdate(d.start_date) >= getdate(d.end_date):
msgprint("Start date should be less than end date for item "+d.item_code) throw(_("Start date should be less than end date for item") + " " + d.item_code)
raise Exception
#check if maintenance schedule already created against same sales order #check if maintenance schedule already created against same sales order
#----------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------
def validate_sales_order(self): def validate_sales_order(self):
for d in getlist(self.doclist, 'item_maintenance_detail'): for d in getlist(self.doclist, 'item_maintenance_detail'):
if d.prevdoc_docname: 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: if chk:
msgprint("Maintenance Schedule against "+d.prevdoc_docname+" already exist") throw("Maintenance Schedule against " + d.prevdoc_docname + " already exist")
raise Exception
def validate_serial_no(self): def validate_serial_no(self):
@ -185,13 +212,13 @@ class DocType(TransactionBase):
cur_s_no = cur_serial_no.split(',') cur_s_no = cur_serial_no.split(',')
for x in cur_s_no: 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 '' chk1 = chk and chk[0][0] or ''
status = chk and chk[0][1] or '' status = chk and chk[0][1] or ''
if not chk1: if not chk1:
msgprint("Serial no "+x+" does not exist in system.") throw("Serial no " + x + " does not exist in system.")
raise Exception
def validate(self): def validate(self):
self.validate_maintenance_detail() self.validate_maintenance_detail()
@ -208,13 +235,13 @@ class DocType(TransactionBase):
cur_s_no = cur_serial_no.split(',') cur_s_no = cur_serial_no.split(',')
for x in cur_s_no: 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 '' dt = dt and dt[0][0] or ''
if dt: if dt:
if dt > getdate(d.start_date): 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) throw("Maintenance start date can not be before delivery date " + dt.strftime('%Y-%m-%d') + " for serial no " + x)
raise Exception
#update amc expiry date in serial no #update amc expiry date in serial no
#------------------------------------------ #------------------------------------------
@ -224,7 +251,8 @@ class DocType(TransactionBase):
cur_s_no = cur_serial_no.split(',') cur_s_no = cur_serial_no.split(',')
for x in cur_s_no: 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): def on_update(self):
webnotes.conn.set(self.doc, 'status', 'Draft') webnotes.conn.set(self.doc, 'status', 'Draft')
@ -233,16 +261,16 @@ class DocType(TransactionBase):
for d in getlist(self.doclist, 'item_maintenance_detail'): for d in getlist(self.doclist, 'item_maintenance_detail'):
if cstr(d.serial_no).strip(): if cstr(d.serial_no).strip():
dt = webnotes.conn.sql("""select warranty_expiry_date, amc_expiry_date 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: 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.""" % 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: 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.""" % 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): def validate_schedule(self):
item_lst1 =[] item_lst1 =[]
@ -256,13 +284,11 @@ class DocType(TransactionBase):
item_lst2.append(m.item_code) item_lst2.append(m.item_code)
if len(item_lst1) != len(item_lst2): if len(item_lst1) != len(item_lst2):
msgprint("Maintenance Schedule is not generated for all the items. Please click on 'Generate Schedule'") throw("Maintenance Schedule is not generated for all the items. Please click on 'Generate Schedule'")
raise Exception
else: else:
for x in item_lst1: for x in item_lst1:
if x not in item_lst2: if x not in item_lst2:
msgprint("Maintenance Schedule is not generated for item "+x+". Please click on 'Generate Schedule'") throw("Maintenance Schedule is not generated for item "+x+". Please click on 'Generate Schedule'")
raise Exception
#check if serial no present in item maintenance table #check if serial no present in item maintenance table
#----------------------------------------------------------- #-----------------------------------------------------------
@ -275,18 +301,15 @@ class DocType(TransactionBase):
for m in getlist(self.doclist, 'maintenance_schedule_detail'): for m in getlist(self.doclist, 'maintenance_schedule_detail'):
if serial_present: if serial_present:
if m.item_code in serial_present and not m.serial_no: 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) throw("Please click on 'Generate Schedule' to fetch serial no added for item "+m.item_code)
raise Exception
def on_cancel(self): def on_cancel(self):
for d in getlist(self.doclist, 'item_maintenance_detail'): for d in getlist(self.doclist, 'item_maintenance_detail'):
if d.serial_no: if d.serial_no:
self.update_amc_date(d.serial_no, '') self.update_amc_date(d.serial_no, '')
webnotes.conn.set(self.doc, 'status', 'Cancelled') webnotes.conn.set(self.doc, 'status', 'Cancelled')
delete_events(self.doc.doctype, self.doc.name) delete_events(self.doc.doctype, self.doc.name)
def on_trash(self): def on_trash(self):
delete_events(self.doc.doctype, self.doc.name) delete_events(self.doc.doctype, self.doc.name)
@ -313,7 +336,7 @@ def make_maintenance_visit(source_name, target_doclist=None):
"field_map": { "field_map": {
"parent": "prevdoc_docname", "parent": "prevdoc_docname",
"parenttype": "prevdoc_doctype", "parenttype": "prevdoc_doctype",
"incharge_name": "service_person" "sales_person": "service_person"
} }
} }
}, target_doclist) }, target_doclist)

View File

@ -2,7 +2,7 @@
{ {
"creation": "2013-02-22 01:28:05", "creation": "2013-02-22 01:28:05",
"docstatus": 0, "docstatus": 0,
"modified": "2013-12-20 19:23:20", "modified": "2013-12-31 12:13:38",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -52,6 +52,7 @@
"search_index": 0 "search_index": 0
}, },
{ {
"allow_on_submit": 0,
"doctype": "DocField", "doctype": "DocField",
"fieldname": "scheduled_date", "fieldname": "scheduled_date",
"fieldtype": "Date", "fieldtype": "Date",
@ -78,12 +79,13 @@
"report_hide": 1 "report_hide": 1
}, },
{ {
"allow_on_submit": 0,
"doctype": "DocField", "doctype": "DocField",
"fieldname": "incharge_name", "fieldname": "sales_person",
"fieldtype": "Link", "fieldtype": "Link",
"in_filter": 1, "in_filter": 1,
"in_list_view": 1, "in_list_view": 1,
"label": "Incharge Name", "label": "Sales Person",
"oldfieldname": "incharge_name", "oldfieldname": "incharge_name",
"oldfieldtype": "Link", "oldfieldtype": "Link",
"options": "Sales Person", "options": "Sales Person",

View File

@ -2,7 +2,7 @@
{ {
"creation": "2013-02-22 01:28:05", "creation": "2013-02-22 01:28:05",
"docstatus": 0, "docstatus": 0,
"modified": "2013-12-20 19:23:20", "modified": "2013-12-31 12:08:32",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -112,10 +112,10 @@
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "incharge_name", "fieldname": "sales_person",
"fieldtype": "Link", "fieldtype": "Link",
"in_filter": 1, "in_filter": 1,
"label": "Sales Person Incharge", "label": "Sales Person",
"oldfieldname": "incharge_name", "oldfieldname": "incharge_name",
"oldfieldtype": "Link", "oldfieldtype": "Link",
"options": "Sales Person", "options": "Sales Person",

View File

@ -2,7 +2,7 @@
{ {
"creation": "2013-05-06 14:25:21", "creation": "2013-05-06 14:25:21",
"docstatus": 0, "docstatus": 0,
"modified": "2013-10-09 12:23:27", "modified": "2013-12-31 12:24:48",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -10,7 +10,7 @@
"doctype": "Report", "doctype": "Report",
"is_standard": "Yes", "is_standard": "Yes",
"name": "__common__", "name": "__common__",
"query": "SELECT\n ms_sch.scheduled_date as \"Schedule Date:Date:120\",\n\tms_sch.item_code as \"Item Code:Link/Item:120\",\n\tms_sch.item_name as \"Item Name::120\",\n\tms_sch.serial_no as \"Serial No::120\",\n\tms_sch.incharge_name as \"Incharge::120\",\n\tms.customer_name as \"Customer:Link/Customer:120\",\n\tms.address_display as \"Customer Address::120\",\n\tms_item.prevdoc_docname as \"Sales Order:Link/Sales Order:120\",\n\tms.company as \"Company:Link/Company:120\"\n\t\nFROM\n\t`tabMaintenance Schedule` ms, \n `tabMaintenance Schedule Detail` ms_sch, \n `tabMaintenance Schedule Item` ms_item\nWHERE\n\tms.name = ms_sch.parent and ms.name = ms_item.parent and ms.docstatus = 1\nORDER BY\n\tms_sch.scheduled_date asc, ms_sch.item_code asc", "query": "SELECT\n ms_sch.scheduled_date as \"Schedule Date:Date:120\",\n\tms_sch.item_code as \"Item Code:Link/Item:120\",\n\tms_sch.item_name as \"Item Name::120\",\n\tms_sch.serial_no as \"Serial No::120\",\n\tms_sch.sales_person as \"Sales Person::120\",\n\tms.customer_name as \"Customer:Link/Customer:120\",\n\tms.address_display as \"Customer Address::120\",\n\tms_item.prevdoc_docname as \"Sales Order:Link/Sales Order:120\",\n\tms.company as \"Company:Link/Company:120\"\n\t\nFROM\n\t`tabMaintenance Schedule` ms, \n `tabMaintenance Schedule Detail` ms_sch, \n `tabMaintenance Schedule Item` ms_item\nWHERE\n\tms.name = ms_sch.parent and ms.name = ms_item.parent and ms.docstatus = 1\nORDER BY\n\tms_sch.scheduled_date asc, ms_sch.item_code asc",
"ref_doctype": "Maintenance Schedule", "ref_doctype": "Maintenance Schedule",
"report_name": "Maintenance Schedules", "report_name": "Maintenance Schedules",
"report_type": "Query Report" "report_type": "Query Report"