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

@ -4,10 +4,10 @@
wn.provide("erpnext.hr");
erpnext.hr.EmployeeController = wn.ui.form.Controller.extend({
setup: function() {
this.frm.fields_dict.user_id.get_query = function(doc,cdt,cdn) {
return { query:"webnotes.core.doctype.profile.profile.profile_query"} }
this.frm.fields_dict.reports_to.get_query = function(doc,cdt,cdn) {
return{ query: "erpnext.controllers.queries.employee_query"} }
this.frm.fields_dict.user_id.get_query = function(doc, cdt, cdn) {
return { query:"webnotes.core.doctype.profile.profile.profile_query"} }
this.frm.fields_dict.reports_to.get_query = function(doc, cdt, cdn) {
return { query: "erpnext.controllers.queries.employee_query"} }
},
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.doc import addchild, make_autoname
from webnotes.model.bean import copy_doclist
from webnotes import msgprint
from webnotes import msgprint, throw, _
import datetime
class DocType:
@ -19,7 +17,7 @@ class DocType:
self.doclist = doclist
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):
self.update_default_holiday_list()
@ -38,11 +36,9 @@ class DocType:
def validate_values(self):
if not self.doc.fiscal_year:
msgprint("Please select Fiscal Year")
raise Exception
throw(_("Please select Fiscal Year"))
if not self.doc.weekly_off:
msgprint("Please select weekly off day")
raise Exception
throw(_("Please select weekly off day"))
def get_fy_start_end_dates(self):
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.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

@ -7,18 +7,18 @@
wn.provide("erpnext");
erpnext.LeadController = wn.ui.form.Controller.extend({
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" } }
},
onload: function() {
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" } }
}
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" } }
}
@ -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
// License: GNU General Public License v3. See license.txt
//--------- ONLOAD -------------
cur_frm.cscript.onload = function(doc, cdt, cdn) {
}
// 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');
else unhide_field('master_name');
if(doc.based_on == 'Not Applicable') hide_field('value');
else unhide_field('value');
if(doc.transaction == 'Appraisal'){
hide_field(['master_name','system_role', 'system_user']);
unhide_field(['to_emp','to_designation']);
if(doc.transaction == 'Appraisal') hide_field('value');
else unhide_field('value');
}
else {
unhide_field(['master_name','system_role', 'system_user','value']);
hide_field(['to_emp','to_designation']);
}
if (doc.transaction == 'Appraisal') {
hide_field(['master_name','system_role', 'system_user']);
unhide_field(['to_emp','to_designation']);
if (doc.transaction == 'Appraisal')
hide_field('value');
else
unhide_field('value');
}
else {
unhide_field(['master_name','system_role', 'system_user','value']);
hide_field(['to_emp','to_designation']);
}
}
cur_frm.cscript.based_on = function(doc){
if(doc.based_on == 'Grand Total' || doc.based_on == 'Average Discount' || doc.based_on == 'Not Applicable'){
doc.master_name = '';
refresh_field('master_name');
hide_field('master_name');
}
else{
unhide_field('master_name');
}
if(doc.based_on == 'Not Applicable') {
doc.value =0;
refresh_field('value');
hide_field('value');
}
else unhide_field('value');
cur_frm.cscript.based_on = function(doc) {
if (doc.based_on == 'Grand Total' || doc.based_on == 'Average Discount' || doc.based_on == 'Not Applicable') {
doc.master_name = '';
refresh_field('master_name');
hide_field('master_name');
}
else
unhide_field('master_name');
if (doc.based_on == 'Not Applicable') {
doc.value =0;
refresh_field('value');
hide_field('value');
}
else
unhide_field('value');
}
cur_frm.cscript.transaction = function(doc,cdt,cdn){
if (doc.transaction == 'Appraisal'){
doc.master_name = doc.system_role = doc.system_user = '';
refresh_many(['master_name','system_role', 'system_user']);
hide_field(['master_name','system_role', 'system_user']);
unhide_field(['to_emp','to_designation']);
doc.value =0;
refresh_many('value');
hide_field('value');
}
else {
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.cscript.transaction = function(doc, cdt, cdn){
if (doc.transaction == 'Appraisal') {
doc.based_on == 'Not Applicable';
doc.master_name = doc.system_role = doc.system_user = '';
refresh_many(['master_name','system_role', 'system_user', 'based_on']);
hide_field(['master_name','system_role', 'system_user']);
unhide_field(['to_emp','to_designation']);
doc.value = 0;
refresh_many('value');
hide_field('value');
}
else {
unhide_field(['master_name','system_role', 'system_user','value']);
hide_field(['to_emp','to_designation']);
}
}
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) {
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_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;
// System Role Trigger
// -----------------------
cur_frm.fields_dict['system_role'].get_query = function(doc) {
return{
filters:[
['Role', 'name', 'not in', 'Administrator, Guest, All']
]
}
return {
filters:[
['Role', 'name', 'not in', 'Administrator, Guest, All']
]
}
}
// Master Name Trigger
// --------------------
cur_frm.fields_dict['master_name'].get_query = function(doc){
if(doc.based_on == 'Customerwise Discount')
return {
doctype: "Customer",
filters:[
['Customer', 'docstatus', '!=', 2]
]
}
else if(doc.based_on == 'Itemwise Discount')
return {
doctype: "Item",
query: "erpnext.controllers.queries.item_query"
}
else
return {
filters: [
['Item', 'name', '=', 'cheating done to avoid null']
]
}
cur_frm.fields_dict['master_name'].get_query = function(doc) {
if (doc.based_on == 'Customerwise Discount')
return {
doctype: "Customer",
filters:[
['Customer', 'docstatus', '!=', 2]
]
}
else if (doc.based_on == 'Itemwise Discount')
return {
doctype: "Item",
query: "erpnext.controllers.queries.item_query"
}
else
return {
filters: [
['Item', 'name', '=', 'cheating done to avoid null']
]
}
}
cur_frm.fields_dict.to_emp.get_query = function(doc,cdt,cdn) {
return{ query: "erpnext.controllers.queries.employee_query" } }
cur_frm.fields_dict.to_emp.get_query = function(doc, cdt, cdn) {
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
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{
filters:[
filters: [
['Sales Person', 'is_group', '=', 'Yes'],
['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) {
return{
filters:{ 'is_group': "No" }
return {
filters: { 'is_group': "No" }
}
}
cur_frm.fields_dict.employee.get_query = function(doc,cdt,cdn) {
return{ query: "erpnext.controllers.queries.employee_query" } }
cur_frm.fields_dict.employee.get_query = function(doc, cdt, cdn) {
return { query: "erpnext.controllers.queries.employee_query" }
}

View File

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

View File

@ -5,6 +5,8 @@ wn.provide("erpnext.support");
// TODO commonify this code
erpnext.support.MaintenanceSchedule = wn.ui.form.Controller.extend({
refresh: function() {
var me = this;
if (this.frm.doc.docstatus === 0) {
this.frm.add_custom_button(wn._('From Sales Order'),
function() {
@ -23,7 +25,7 @@ erpnext.support.MaintenanceSchedule = wn.ui.form.Controller.extend({
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
source_name: me.frm.doc.name
})
});
}
@ -42,7 +44,7 @@ erpnext.support.MaintenanceSchedule = wn.ui.form.Controller.extend({
$.extend(cur_frm.cscript, new erpnext.support.MaintenanceSchedule({frm: cur_frm}));
cur_frm.cscript.onload = function(doc, dt, dn) {
if(!doc.status)
if (!doc.status)
set_multiple(dt, dn, { status:'Draft' });
if (doc.__islocal) {

View File

@ -32,7 +32,7 @@ class DocType(TransactionBase):
self.validate_maintenance_detail()
count = 1
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):
child = addchild(self.doc, 'maintenance_schedule_detail',
'Maintenance Schedule Detail', self.doclist)
@ -43,7 +43,7 @@ class DocType(TransactionBase):
child.serial_no = d.serial_no
child.idx = count
count = count + 1
child.incharge_name = d.incharge_name
child.sales_person = d.sales_person
child.save(1)
self.on_update()
@ -55,26 +55,26 @@ class DocType(TransactionBase):
self.validate_serial_no_warranty()
self.validate_schedule()
email_map ={}
email_map = {}
for d in getlist(self.doclist, 'item_maintenance_detail'):
if d.serial_no:
self.update_amc_date(d.serial_no, d.end_date)
if d.incharge_name not in email_map:
email_map[d.incharge_name] = webnotes.bean("Sales Person",
d.incharge_name).run_method("get_email_id")
if d.sales_person not in email_map:
sp = webnotes.bean("Sales Person", d.sales_person).make_controller()
email_map[d.sales_person] = sp.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 sales_person=%s and item_code=%s and
parent=%s""", (d.sales_person, d.item_code, self.doc.name), as_dict=1)
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" % \
(self.doc.name, d.item_code, self.doc.customer)
webnotes.bean({
"doctype": "Event",
"owner": email_map[d.incharge_name] or self.doc.owner,
"owner": email_map[d.sales_person] or self.doc.owner,
"subject": description,
"description": description,
"starts_on": key["scheduled_date"] + " 10:00:00",
@ -87,7 +87,7 @@ class DocType(TransactionBase):
#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 = []
start_date_copy = start_date
date_diff = (getdate(end_date) - getdate(start_date)).days
@ -96,9 +96,29 @@ class DocType(TransactionBase):
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_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
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
#-------------------------------------------------
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)
elif not d.no_of_visits:
throw(_("Please mention no of visits required"))
elif not d.incharge_name:
elif not d.sales_person:
throw(_("Please select Incharge Person's name"))
if getdate(d.start_date) >= getdate(d.end_date):
@ -297,7 +317,7 @@ def make_maintenance_visit(source_name, target_doclist=None):
"field_map": {
"parent": "prevdoc_docname",
"parenttype": "prevdoc_doctype",
"incharge_name": "service_person"
"sales_person": "service_person"
}
}
}, target_doclist)

View File

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

View File

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

View File

@ -2,7 +2,7 @@
{
"creation": "2013-05-06 14:25:21",
"docstatus": 0,
"modified": "2013-10-09 12:23:27",
"modified": "2013-12-31 12:24:48",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -10,7 +10,7 @@
"doctype": "Report",
"is_standard": "Yes",
"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",
"report_name": "Maintenance Schedules",
"report_type": "Query Report"