fixed maintenance schedule

This commit is contained in:
Akhilesh Darjee 2013-12-31 17:45:20 +05:30
parent 064d2ba16a
commit 5c96b75a68
13 changed files with 170 additions and 150 deletions

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

@ -1,3 +1,4 @@
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

View File

@ -0,0 +1,9 @@
# 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.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

@ -1,29 +1,26 @@
// 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) { 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');
if (doc.based_on == 'Not Applicable')
if(doc.based_on == 'Grand Total' || doc.based_on == 'Average Discount' || doc.based_on == 'Not Applicable') hide_field('master_name'); hide_field('value');
else unhide_field('master_name'); else
unhide_field('value');
if(doc.based_on == 'Not Applicable') hide_field('value');
else unhide_field('value');
if (doc.transaction == 'Appraisal') { if (doc.transaction == 'Appraisal') {
hide_field(['master_name','system_role', 'system_user']); hide_field(['master_name','system_role', 'system_user']);
unhide_field(['to_emp','to_designation']); unhide_field(['to_emp','to_designation']);
if(doc.transaction == 'Appraisal') hide_field('value');
else unhide_field('value'); if (doc.transaction == 'Appraisal')
hide_field('value');
else
unhide_field('value');
} }
else { else {
unhide_field(['master_name','system_role', 'system_user','value']); unhide_field(['master_name','system_role', 'system_user','value']);
@ -37,22 +34,23 @@ cur_frm.cscript.based_on = function(doc){
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 unhide_field('value'); else
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.based_on == 'Not Applicable';
doc.master_name = doc.system_role = doc.system_user = ''; doc.master_name = doc.system_role = doc.system_user = '';
refresh_many(['master_name','system_role', 'system_user']); refresh_many(['master_name','system_role', 'system_user', 'based_on']);
hide_field(['master_name','system_role', 'system_user']); hide_field(['master_name','system_role', 'system_user']);
unhide_field(['to_emp','to_designation']); unhide_field(['to_emp','to_designation']);
doc.value = 0; doc.value = 0;
@ -64,15 +62,15 @@ cur_frm.cscript.transaction = function(doc,cdt,cdn){
hide_field(['to_emp','to_designation']); 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) { cur_frm.fields_dict.system_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) { 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_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;
@ -111,4 +109,5 @@ cur_frm.fields_dict['master_name'].get_query = function(doc){
} }
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,11 +15,6 @@ 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{
@ -37,4 +32,5 @@ cur_frm.fields_dict['target_details'].grid.get_field("item_group").get_query = f
} }
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,7 +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.msgprint("User ID (Profile) not set for Employee %s" % self.doc.employee,
raise_exception=True) 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,6 +5,8 @@ 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() {
var me = this;
if (this.frm.doc.docstatus === 0) { if (this.frm.doc.docstatus === 0) {
this.frm.add_custom_button(wn._('From Sales Order'), this.frm.add_custom_button(wn._('From Sales Order'),
function() { function() {
@ -23,7 +25,7 @@ erpnext.support.MaintenanceSchedule = wn.ui.form.Controller.extend({
this.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
}) })
}); });
} }

View File

@ -32,7 +32,7 @@ class DocType(TransactionBase):
self.validate_maintenance_detail() self.validate_maintenance_detail()
count = 1 count = 1
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)
@ -43,7 +43,7 @@ class DocType(TransactionBase):
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()
@ -60,21 +60,21 @@ class DocType(TransactionBase):
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 scheduled_date = webnotes.conn.sql("""select scheduled_date from
`tabMaintenance Schedule Detail` where incharge_name=%s and item_code=%s and `tabMaintenance Schedule Detail` where sales_person=%s and item_code=%s and
parent=%s""", (d.incharge_name, 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",
@ -87,7 +87,7 @@ 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_date_copy = 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
@ -96,9 +96,29 @@ class DocType(TransactionBase):
while (getdate(start_date_copy) < getdate(end_date)): while (getdate(start_date_copy) < getdate(end_date)):
start_date_copy = add_days(start_date_copy, add_by) start_date_copy = add_days(start_date_copy, add_by)
if len(schedule_list) < no_of_visit: if len(schedule_list) < no_of_visit:
schedule_list.append(getdate(start_date_copy)) 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):
validated = False
holiday_list = webnotes.conn.sql_list("""select h.holiday_date from `tabEmployee` emp,
`tabSales Person` sp, `tabHoliday` h where sp.name=%s and emp.name=sp.employee
and h.parent=emp.holiday_list""", sales_person)
while not validated:
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):
@ -147,7 +167,7 @@ class DocType(TransactionBase):
throw(_("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)
elif not d.no_of_visits: elif not d.no_of_visits:
throw(_("Please mention no of visits required")) throw(_("Please mention no of visits required"))
elif not d.incharge_name: elif not d.sales_person:
throw(_("Please select Incharge Person's name")) throw(_("Please select Incharge Person's name"))
if getdate(d.start_date) >= getdate(d.end_date): if getdate(d.start_date) >= getdate(d.end_date):
@ -297,7 +317,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-30 19:32:30", "modified": "2013-12-31 12:13:38",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -52,7 +52,7 @@
"search_index": 0 "search_index": 0
}, },
{ {
"allow_on_submit": 1, "allow_on_submit": 0,
"doctype": "DocField", "doctype": "DocField",
"fieldname": "scheduled_date", "fieldname": "scheduled_date",
"fieldtype": "Date", "fieldtype": "Date",
@ -79,13 +79,13 @@
"report_hide": 1 "report_hide": 1
}, },
{ {
"allow_on_submit": 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"