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"));
|
||||
} else if (this.frm.doc.docstatus === 1) {
|
||||
this.frm.add_custom_button(__('Create Maintenance Visit'), function () {
|
||||
frappe.model.open_mapped_doc({
|
||||
method: "erpnext.maintenance.doctype.maintenance_schedule.maintenance_schedule.make_maintenance_visit",
|
||||
source_name: me.frm.doc.name,
|
||||
frm: me.frm
|
||||
});
|
||||
let items = me.frm.doc.items;
|
||||
let s = me.frm.doc.schedules;
|
||||
let options = "";
|
||||
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'));
|
||||
}
|
||||
},
|
||||
|
@ -32,8 +32,7 @@ class MaintenanceSchedule(TransactionBase):
|
||||
child.idx = count
|
||||
count = count + 1
|
||||
child.sales_person = d.sales_person
|
||||
|
||||
|
||||
child.completion_status = "Pending"
|
||||
|
||||
def on_submit(self):
|
||||
if not self.get('schedules'):
|
||||
@ -58,9 +57,9 @@ class MaintenanceSchedule(TransactionBase):
|
||||
|
||||
if no_email_sp:
|
||||
frappe.msgprint(
|
||||
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)
|
||||
))
|
||||
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)
|
||||
))
|
||||
|
||||
scheduled_date = frappe.db.sql("""select scheduled_date from
|
||||
`tabMaintenance Schedule Detail` where sales_person=%s and item_code=%s and
|
||||
@ -69,12 +68,12 @@ class MaintenanceSchedule(TransactionBase):
|
||||
for key in scheduled_date:
|
||||
description =frappe._("Reference: {0}, Item Code: {1} and Customer: {2}").format(self.name, d.item_code, self.customer)
|
||||
event = frappe.get_doc({
|
||||
"doctype": "Event",
|
||||
"owner": email_map.get(d.sales_person, self.owner),
|
||||
"subject": description,
|
||||
"description": description,
|
||||
"starts_on": cstr(key["scheduled_date"]) + " 10:00:00",
|
||||
"event_type": "Private",
|
||||
"doctype": "Event",
|
||||
"owner": email_map.get(d.sales_person, self.owner),
|
||||
"subject": description,
|
||||
"description": description,
|
||||
"starts_on": cstr(key["scheduled_date"]) + " 10:00:00",
|
||||
"event_type": "Private",
|
||||
})
|
||||
event.add_participant(self.doctype, self.name)
|
||||
event.insert(ignore_permissions=1)
|
||||
@ -92,7 +91,7 @@ class MaintenanceSchedule(TransactionBase):
|
||||
start_date_copy = add_days(start_date_copy, add_by)
|
||||
if len(schedule_list) < no_of_visit:
|
||||
schedule_date = self.validate_schedule_date_for_holiday_list(getdate(start_date_copy),
|
||||
sales_person)
|
||||
sales_person)
|
||||
if schedule_date > getdate(end_date):
|
||||
schedule_date = getdate(end_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":
|
||||
date_diff = (getdate(d.end_date) - getdate(d.start_date)).days + 1
|
||||
days_in_period = {
|
||||
"Weekly": 7,
|
||||
"Monthly": 30,
|
||||
"Quarterly": 90,
|
||||
"Half Yearly": 180,
|
||||
"Yearly": 365
|
||||
"Weekly": 7,
|
||||
"Monthly": 30,
|
||||
"Quarterly": 90,
|
||||
"Half Yearly": 180,
|
||||
"Yearly": 365
|
||||
}
|
||||
|
||||
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}")
|
||||
.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):
|
||||
if not self.get('items'):
|
||||
@ -172,8 +171,8 @@ class MaintenanceSchedule(TransactionBase):
|
||||
|
||||
def on_update(self):
|
||||
frappe.db.set(self, 'status', 'Draft')
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def update_amc_date(self, serial_nos, amc_expiry_date=None):
|
||||
for serial_no in serial_nos:
|
||||
@ -184,27 +183,27 @@ class MaintenanceSchedule(TransactionBase):
|
||||
def validate_serial_no(self, item_code, serial_nos, amc_start_date):
|
||||
for serial_no in serial_nos:
|
||||
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:
|
||||
frappe.throw(_("Serial No {0} not found").format(serial_no))
|
||||
|
||||
if sr_details.get("item_code") != item_code:
|
||||
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 \
|
||||
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}")
|
||||
.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):
|
||||
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 \
|
||||
getdate(sr_details.delivery_date) >= getdate(amc_start_date):
|
||||
throw(_("Maintenance start date can not be before delivery date for Serial No {0}")
|
||||
getdate(sr_details.delivery_date) >= getdate(amc_start_date):
|
||||
throw(_("Maintenance start date can not be before delivery date for Serial No {0}")
|
||||
.format(serial_no))
|
||||
|
||||
def validate_schedule(self):
|
||||
@ -248,31 +247,37 @@ class MaintenanceSchedule(TransactionBase):
|
||||
delete_events(self.doctype, self.name)
|
||||
|
||||
@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
|
||||
|
||||
def update_status(source, target, parent):
|
||||
target.maintenance_type = "Scheduled"
|
||||
|
||||
def update_sid(source, target, parent):
|
||||
target.prevdoc_detail_docname = s_id
|
||||
|
||||
doclist = get_mapped_doc("Maintenance Schedule", source_name, {
|
||||
"Maintenance Schedule": {
|
||||
"doctype": "Maintenance Visit",
|
||||
"field_map": {
|
||||
"name": "maintenance_schedule"
|
||||
"Maintenance Schedule": {
|
||||
"doctype": "Maintenance Visit",
|
||||
"field_map": {
|
||||
"name": "maintenance_schedule"
|
||||
},
|
||||
"validation": {
|
||||
"docstatus": ["=", 1]
|
||||
},
|
||||
"postprocess": update_status
|
||||
},
|
||||
"validation": {
|
||||
"docstatus": ["=", 1]
|
||||
},
|
||||
"postprocess": update_status
|
||||
},
|
||||
"Maintenance Schedule Item": {
|
||||
"doctype": "Maintenance Visit Purpose",
|
||||
"field_map": {
|
||||
"parent": "prevdoc_docname",
|
||||
"parenttype": "prevdoc_doctype",
|
||||
"sales_person": "service_person"
|
||||
"Maintenance Schedule Item": {
|
||||
"doctype": "Maintenance Visit Purpose",
|
||||
"field_map": {
|
||||
"parent": "prevdoc_docname",
|
||||
"parenttype": "prevdoc_doctype",
|
||||
},
|
||||
"condition": lambda doc: doc.item_name == item_name,
|
||||
|
||||
"postprocess": update_sid
|
||||
|
||||
}
|
||||
}
|
||||
}, target_doc)
|
||||
|
||||
return doclist
|
||||
|
@ -12,7 +12,8 @@
|
||||
"scheduled_date",
|
||||
"actual_date",
|
||||
"sales_person",
|
||||
"serial_no"
|
||||
"serial_no",
|
||||
"completion_status"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
@ -52,6 +53,7 @@
|
||||
{
|
||||
"fieldname": "actual_date",
|
||||
"fieldtype": "Date",
|
||||
"in_list_view": 1,
|
||||
"label": "Actual Date",
|
||||
"no_copy": 1,
|
||||
"oldfieldname": "actual_date",
|
||||
@ -81,12 +83,18 @@
|
||||
"print_width": "160px",
|
||||
"read_only": 1,
|
||||
"width": "160px"
|
||||
},
|
||||
{
|
||||
"fieldname": "completion_status",
|
||||
"fieldtype": "Select",
|
||||
"label": "Completion Status",
|
||||
"options": "Pending\nPartially Completed\nFully Completed"
|
||||
}
|
||||
],
|
||||
"idx": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-04-16 16:01:53.271287",
|
||||
"modified": "2021-04-19 16:18:36.723319",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Maintenance",
|
||||
"name": "Maintenance Schedule Detail",
|
||||
|
@ -1,4 +1,5 @@
|
||||
{
|
||||
"actions": [],
|
||||
"autoname": "hash",
|
||||
"creation": "2013-02-22 01:28:06",
|
||||
"doctype": "DocType",
|
||||
@ -62,6 +63,8 @@
|
||||
"fieldtype": "Section Break"
|
||||
},
|
||||
{
|
||||
"fetch_from": "prevdoc_detail_docname.sales_person",
|
||||
"fetch_if_empty": 1,
|
||||
"fieldname": "service_person",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
@ -110,12 +113,12 @@
|
||||
},
|
||||
{
|
||||
"fieldname": "prevdoc_detail_docname",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 1,
|
||||
"fieldtype": "Link",
|
||||
"label": "Against Document Detail No",
|
||||
"no_copy": 1,
|
||||
"oldfieldname": "prevdoc_detail_docname",
|
||||
"oldfieldtype": "Data",
|
||||
"options": "Maintenance Schedule Detail",
|
||||
"print_hide": 1,
|
||||
"print_width": "160px",
|
||||
"read_only": 1,
|
||||
@ -125,7 +128,8 @@
|
||||
],
|
||||
"idx": 1,
|
||||
"istable": 1,
|
||||
"modified": "2020-09-18 17:26:09.703215",
|
||||
"links": [],
|
||||
"modified": "2021-04-19 16:08:10.671163",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Maintenance",
|
||||
"name": "Maintenance Visit Purpose",
|
||||
|
Loading…
x
Reference in New Issue
Block a user