feat: Created Dialog Box on trying to create a maintenance visit.
This commit is contained in:
parent
5ebc6abfad
commit
9a0a561ec6
@ -65,11 +65,93 @@ erpnext.maintenance.MaintenanceSchedule = frappe.ui.form.Controller.extend({
|
|||||||
}, __("Get Items From"));
|
}, __("Get Items From"));
|
||||||
} else if (this.frm.doc.docstatus === 1) {
|
} else if (this.frm.doc.docstatus === 1) {
|
||||||
this.frm.add_custom_button(__('Create Maintenance Visit'), function () {
|
this.frm.add_custom_button(__('Create Maintenance Visit'), function () {
|
||||||
frappe.model.open_mapped_doc({
|
let items = me.frm.doc.items;
|
||||||
method: "erpnext.maintenance.doctype.maintenance_schedule.maintenance_schedule.make_maintenance_visit",
|
let s = me.frm.doc.schedules;
|
||||||
source_name: me.frm.doc.name,
|
let options = "";
|
||||||
frm: me.frm
|
let dates = "";
|
||||||
});
|
for (let i in items) {
|
||||||
|
for(let d in s){
|
||||||
|
if (s[d].item_name == items[i].item_name && s[d].completion_status == "Pending") {
|
||||||
|
options = options + '\n' + items[i].item_name
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function formatDate(date) {
|
||||||
|
var d = new Date(date),
|
||||||
|
month = '' + (d.getMonth() + 1),
|
||||||
|
day = '' + d.getDate(),
|
||||||
|
year = d.getFullYear();
|
||||||
|
|
||||||
|
if (month.length < 2)
|
||||||
|
month = '0' + month;
|
||||||
|
if (day.length < 2)
|
||||||
|
day = '0' + day;
|
||||||
|
|
||||||
|
return [day, month, year].join('-');
|
||||||
|
}
|
||||||
|
var schedule_id = ""
|
||||||
|
var d = new frappe.ui.Dialog({
|
||||||
|
title: __("Enter Visit Details"),
|
||||||
|
fields: [{
|
||||||
|
fieldtype: "Select",
|
||||||
|
fieldname: "item_name",
|
||||||
|
label: __("Item Name"),
|
||||||
|
options: options,
|
||||||
|
reqd: 1,
|
||||||
|
onchange: function () {
|
||||||
|
let field = d.get_field("scheduled_date");
|
||||||
|
dates = ""
|
||||||
|
for (let i in s) {
|
||||||
|
if (s[i].item_name == this.value) {
|
||||||
|
dates = dates + '\n' + formatDate(s[i].scheduled_date);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
field.df.options = dates;
|
||||||
|
field.refresh();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: __('Scheduled Date'),
|
||||||
|
fieldname: 'scheduled_date',
|
||||||
|
fieldtype: 'Select',
|
||||||
|
options: dates,
|
||||||
|
reqd: 1,
|
||||||
|
onchange: function(){
|
||||||
|
let field = d.get_field('item_name');
|
||||||
|
for(let i in s ){
|
||||||
|
if(s[i].item_name == field.value && formatDate(s[i].scheduled_date) == this.value){
|
||||||
|
schedule_id = s[i].name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
],
|
||||||
|
primary_action_label: 'Create Visit',
|
||||||
|
primary_action(values) {
|
||||||
|
frappe.call({
|
||||||
|
method: "erpnext.maintenance.doctype.maintenance_schedule.maintenance_schedule.make_maintenance_visit",
|
||||||
|
args: {
|
||||||
|
item_name: values.item_name,
|
||||||
|
s_id: schedule_id,
|
||||||
|
source_name: me.frm.doc.name,
|
||||||
|
|
||||||
|
},
|
||||||
|
callback: function (r) {
|
||||||
|
if (!r.exc) {
|
||||||
|
frappe.model.sync(r.message);
|
||||||
|
frappe.set_route("Form", r.message.doctype, r.message.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
d.hide();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
d.show()
|
||||||
|
|
||||||
}, __('Create'));
|
}, __('Create'));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -32,8 +32,7 @@ class MaintenanceSchedule(TransactionBase):
|
|||||||
child.idx = count
|
child.idx = count
|
||||||
count = count + 1
|
count = count + 1
|
||||||
child.sales_person = d.sales_person
|
child.sales_person = d.sales_person
|
||||||
|
child.completion_status = "Pending"
|
||||||
|
|
||||||
|
|
||||||
def on_submit(self):
|
def on_submit(self):
|
||||||
if not self.get('schedules'):
|
if not self.get('schedules'):
|
||||||
@ -58,9 +57,9 @@ class MaintenanceSchedule(TransactionBase):
|
|||||||
|
|
||||||
if no_email_sp:
|
if no_email_sp:
|
||||||
frappe.msgprint(
|
frappe.msgprint(
|
||||||
frappe._("Setting Events to {0}, since the Employee attached to the below Sales Persons does not have a User ID{1}").format(
|
frappe._("Setting Events to {0}, since the Employee attached to the below Sales Persons does not have a User ID{1}").format(
|
||||||
self.owner, "<br>" + "<br>".join(no_email_sp)
|
self.owner, "<br>" + "<br>".join(no_email_sp)
|
||||||
))
|
))
|
||||||
|
|
||||||
scheduled_date = frappe.db.sql("""select scheduled_date from
|
scheduled_date = frappe.db.sql("""select scheduled_date from
|
||||||
`tabMaintenance Schedule Detail` where sales_person=%s and item_code=%s and
|
`tabMaintenance Schedule Detail` where sales_person=%s and item_code=%s and
|
||||||
@ -69,12 +68,12 @@ class MaintenanceSchedule(TransactionBase):
|
|||||||
for key in scheduled_date:
|
for key in scheduled_date:
|
||||||
description =frappe._("Reference: {0}, Item Code: {1} and Customer: {2}").format(self.name, d.item_code, self.customer)
|
description =frappe._("Reference: {0}, Item Code: {1} and Customer: {2}").format(self.name, d.item_code, self.customer)
|
||||||
event = frappe.get_doc({
|
event = frappe.get_doc({
|
||||||
"doctype": "Event",
|
"doctype": "Event",
|
||||||
"owner": email_map.get(d.sales_person, self.owner),
|
"owner": email_map.get(d.sales_person, self.owner),
|
||||||
"subject": description,
|
"subject": description,
|
||||||
"description": description,
|
"description": description,
|
||||||
"starts_on": cstr(key["scheduled_date"]) + " 10:00:00",
|
"starts_on": cstr(key["scheduled_date"]) + " 10:00:00",
|
||||||
"event_type": "Private",
|
"event_type": "Private",
|
||||||
})
|
})
|
||||||
event.add_participant(self.doctype, self.name)
|
event.add_participant(self.doctype, self.name)
|
||||||
event.insert(ignore_permissions=1)
|
event.insert(ignore_permissions=1)
|
||||||
@ -92,7 +91,7 @@ class MaintenanceSchedule(TransactionBase):
|
|||||||
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_date = self.validate_schedule_date_for_holiday_list(getdate(start_date_copy),
|
schedule_date = self.validate_schedule_date_for_holiday_list(getdate(start_date_copy),
|
||||||
sales_person)
|
sales_person)
|
||||||
if schedule_date > getdate(end_date):
|
if schedule_date > getdate(end_date):
|
||||||
schedule_date = getdate(end_date)
|
schedule_date = getdate(end_date)
|
||||||
schedule_list.append(schedule_date)
|
schedule_list.append(schedule_date)
|
||||||
@ -127,16 +126,16 @@ class MaintenanceSchedule(TransactionBase):
|
|||||||
if d.start_date and d.end_date and d.periodicity and d.periodicity!="Random":
|
if d.start_date and d.end_date and d.periodicity and d.periodicity!="Random":
|
||||||
date_diff = (getdate(d.end_date) - getdate(d.start_date)).days + 1
|
date_diff = (getdate(d.end_date) - getdate(d.start_date)).days + 1
|
||||||
days_in_period = {
|
days_in_period = {
|
||||||
"Weekly": 7,
|
"Weekly": 7,
|
||||||
"Monthly": 30,
|
"Monthly": 30,
|
||||||
"Quarterly": 90,
|
"Quarterly": 90,
|
||||||
"Half Yearly": 180,
|
"Half Yearly": 180,
|
||||||
"Yearly": 365
|
"Yearly": 365
|
||||||
}
|
}
|
||||||
|
|
||||||
if date_diff < days_in_period[d.periodicity]:
|
if date_diff < days_in_period[d.periodicity]:
|
||||||
throw(_("Row {0}: To set {1} periodicity, difference between from and to date must be greater than or equal to {2}")
|
throw(_("Row {0}: To set {1} periodicity, difference between from and to date must be greater than or equal to {2}")
|
||||||
.format(d.idx, d.periodicity, days_in_period[d.periodicity]))
|
.format(d.idx, d.periodicity, days_in_period[d.periodicity]))
|
||||||
|
|
||||||
def validate_maintenance_detail(self):
|
def validate_maintenance_detail(self):
|
||||||
if not self.get('items'):
|
if not self.get('items'):
|
||||||
@ -184,27 +183,27 @@ class MaintenanceSchedule(TransactionBase):
|
|||||||
def validate_serial_no(self, item_code, serial_nos, amc_start_date):
|
def validate_serial_no(self, item_code, serial_nos, amc_start_date):
|
||||||
for serial_no in serial_nos:
|
for serial_no in serial_nos:
|
||||||
sr_details = frappe.db.get_value("Serial No", serial_no,
|
sr_details = frappe.db.get_value("Serial No", serial_no,
|
||||||
["warranty_expiry_date", "amc_expiry_date", "warehouse", "delivery_date", "item_code"], as_dict=1)
|
["warranty_expiry_date", "amc_expiry_date", "warehouse", "delivery_date", "item_code"], as_dict=1)
|
||||||
|
|
||||||
if not sr_details:
|
if not sr_details:
|
||||||
frappe.throw(_("Serial No {0} not found").format(serial_no))
|
frappe.throw(_("Serial No {0} not found").format(serial_no))
|
||||||
|
|
||||||
if sr_details.get("item_code") != item_code:
|
if sr_details.get("item_code") != item_code:
|
||||||
frappe.throw(_("Serial No {0} does not belong to Item {1}")
|
frappe.throw(_("Serial No {0} does not belong to Item {1}")
|
||||||
.format(frappe.bold(serial_no), frappe.bold(item_code)), title="Invalid")
|
.format(frappe.bold(serial_no), frappe.bold(item_code)), title="Invalid")
|
||||||
|
|
||||||
if sr_details.warranty_expiry_date \
|
if sr_details.warranty_expiry_date \
|
||||||
and getdate(sr_details.warranty_expiry_date) >= getdate(amc_start_date):
|
and getdate(sr_details.warranty_expiry_date) >= getdate(amc_start_date):
|
||||||
throw(_("Serial No {0} is under warranty upto {1}")
|
throw(_("Serial No {0} is under warranty upto {1}")
|
||||||
.format(serial_no, sr_details.warranty_expiry_date))
|
.format(serial_no, sr_details.warranty_expiry_date))
|
||||||
|
|
||||||
if sr_details.amc_expiry_date and getdate(sr_details.amc_expiry_date) >= getdate(amc_start_date):
|
if sr_details.amc_expiry_date and getdate(sr_details.amc_expiry_date) >= getdate(amc_start_date):
|
||||||
throw(_("Serial No {0} is under maintenance contract upto {1}")
|
throw(_("Serial No {0} is under maintenance contract upto {1}")
|
||||||
.format(serial_no, sr_details.amc_expiry_date))
|
.format(serial_no, sr_details.amc_expiry_date))
|
||||||
|
|
||||||
if not sr_details.warehouse and sr_details.delivery_date and \
|
if not sr_details.warehouse and sr_details.delivery_date and \
|
||||||
getdate(sr_details.delivery_date) >= getdate(amc_start_date):
|
getdate(sr_details.delivery_date) >= getdate(amc_start_date):
|
||||||
throw(_("Maintenance start date can not be before delivery date for Serial No {0}")
|
throw(_("Maintenance start date can not be before delivery date for Serial No {0}")
|
||||||
.format(serial_no))
|
.format(serial_no))
|
||||||
|
|
||||||
def validate_schedule(self):
|
def validate_schedule(self):
|
||||||
@ -248,31 +247,37 @@ class MaintenanceSchedule(TransactionBase):
|
|||||||
delete_events(self.doctype, self.name)
|
delete_events(self.doctype, self.name)
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def make_maintenance_visit(source_name, target_doc=None):
|
def make_maintenance_visit(source_name, target_doc=None,item_name=None,s_id=None):
|
||||||
from frappe.model.mapper import get_mapped_doc
|
from frappe.model.mapper import get_mapped_doc
|
||||||
|
|
||||||
def update_status(source, target, parent):
|
def update_status(source, target, parent):
|
||||||
target.maintenance_type = "Scheduled"
|
target.maintenance_type = "Scheduled"
|
||||||
|
|
||||||
|
def update_sid(source, target, parent):
|
||||||
|
target.prevdoc_detail_docname = s_id
|
||||||
|
|
||||||
doclist = get_mapped_doc("Maintenance Schedule", source_name, {
|
doclist = get_mapped_doc("Maintenance Schedule", source_name, {
|
||||||
"Maintenance Schedule": {
|
"Maintenance Schedule": {
|
||||||
"doctype": "Maintenance Visit",
|
"doctype": "Maintenance Visit",
|
||||||
"field_map": {
|
"field_map": {
|
||||||
"name": "maintenance_schedule"
|
"name": "maintenance_schedule"
|
||||||
|
},
|
||||||
|
"validation": {
|
||||||
|
"docstatus": ["=", 1]
|
||||||
|
},
|
||||||
|
"postprocess": update_status
|
||||||
},
|
},
|
||||||
"validation": {
|
"Maintenance Schedule Item": {
|
||||||
"docstatus": ["=", 1]
|
"doctype": "Maintenance Visit Purpose",
|
||||||
},
|
"field_map": {
|
||||||
"postprocess": update_status
|
"parent": "prevdoc_docname",
|
||||||
},
|
"parenttype": "prevdoc_doctype",
|
||||||
"Maintenance Schedule Item": {
|
},
|
||||||
"doctype": "Maintenance Visit Purpose",
|
"condition": lambda doc: doc.item_name == item_name,
|
||||||
"field_map": {
|
|
||||||
"parent": "prevdoc_docname",
|
"postprocess": update_sid
|
||||||
"parenttype": "prevdoc_doctype",
|
|
||||||
"sales_person": "service_person"
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}, target_doc)
|
}, target_doc)
|
||||||
|
|
||||||
return doclist
|
return doclist
|
||||||
|
|||||||
@ -12,7 +12,8 @@
|
|||||||
"scheduled_date",
|
"scheduled_date",
|
||||||
"actual_date",
|
"actual_date",
|
||||||
"sales_person",
|
"sales_person",
|
||||||
"serial_no"
|
"serial_no",
|
||||||
|
"completion_status"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@ -52,6 +53,7 @@
|
|||||||
{
|
{
|
||||||
"fieldname": "actual_date",
|
"fieldname": "actual_date",
|
||||||
"fieldtype": "Date",
|
"fieldtype": "Date",
|
||||||
|
"in_list_view": 1,
|
||||||
"label": "Actual Date",
|
"label": "Actual Date",
|
||||||
"no_copy": 1,
|
"no_copy": 1,
|
||||||
"oldfieldname": "actual_date",
|
"oldfieldname": "actual_date",
|
||||||
@ -81,12 +83,18 @@
|
|||||||
"print_width": "160px",
|
"print_width": "160px",
|
||||||
"read_only": 1,
|
"read_only": 1,
|
||||||
"width": "160px"
|
"width": "160px"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "completion_status",
|
||||||
|
"fieldtype": "Select",
|
||||||
|
"label": "Completion Status",
|
||||||
|
"options": "Pending\nPartially Completed\nFully Completed"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"idx": 1,
|
"idx": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2021-04-16 16:01:53.271287",
|
"modified": "2021-04-19 16:18:36.723319",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Maintenance",
|
"module": "Maintenance",
|
||||||
"name": "Maintenance Schedule Detail",
|
"name": "Maintenance Schedule Detail",
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"actions": [],
|
||||||
"autoname": "hash",
|
"autoname": "hash",
|
||||||
"creation": "2013-02-22 01:28:06",
|
"creation": "2013-02-22 01:28:06",
|
||||||
"doctype": "DocType",
|
"doctype": "DocType",
|
||||||
@ -62,6 +63,8 @@
|
|||||||
"fieldtype": "Section Break"
|
"fieldtype": "Section Break"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"fetch_from": "prevdoc_detail_docname.sales_person",
|
||||||
|
"fetch_if_empty": 1,
|
||||||
"fieldname": "service_person",
|
"fieldname": "service_person",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
@ -110,12 +113,12 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "prevdoc_detail_docname",
|
"fieldname": "prevdoc_detail_docname",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Link",
|
||||||
"hidden": 1,
|
|
||||||
"label": "Against Document Detail No",
|
"label": "Against Document Detail No",
|
||||||
"no_copy": 1,
|
"no_copy": 1,
|
||||||
"oldfieldname": "prevdoc_detail_docname",
|
"oldfieldname": "prevdoc_detail_docname",
|
||||||
"oldfieldtype": "Data",
|
"oldfieldtype": "Data",
|
||||||
|
"options": "Maintenance Schedule Detail",
|
||||||
"print_hide": 1,
|
"print_hide": 1,
|
||||||
"print_width": "160px",
|
"print_width": "160px",
|
||||||
"read_only": 1,
|
"read_only": 1,
|
||||||
@ -125,7 +128,8 @@
|
|||||||
],
|
],
|
||||||
"idx": 1,
|
"idx": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"modified": "2020-09-18 17:26:09.703215",
|
"links": [],
|
||||||
|
"modified": "2021-04-19 16:08:10.671163",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Maintenance",
|
"module": "Maintenance",
|
||||||
"name": "Maintenance Visit Purpose",
|
"name": "Maintenance Visit Purpose",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user