feat: Created Dialog Box on trying to create a maintenance visit.

This commit is contained in:
noahjacob 2021-04-19 16:42:50 +05:30
parent 5ebc6abfad
commit 9a0a561ec6
4 changed files with 153 additions and 54 deletions

View File

@ -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({
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,
frm: me.frm
},
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'));
}
},

View File

@ -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'):
@ -248,12 +247,15 @@ 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",
@ -270,8 +272,11 @@ def make_maintenance_visit(source_name, target_doc=None):
"field_map": {
"parent": "prevdoc_docname",
"parenttype": "prevdoc_doctype",
"sales_person": "service_person"
}
},
"condition": lambda doc: doc.item_name == item_name,
"postprocess": update_sid
}
}, target_doc)

View File

@ -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",

View File

@ -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",