feat: Schedule status is now updated on submitting a visit.

This commit is contained in:
noahjacob 2021-04-19 18:39:34 +05:30
parent 9a0a561ec6
commit 5d7d338d2a
4 changed files with 59 additions and 12 deletions

View File

@ -64,6 +64,14 @@ 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) {
var s = me.frm.doc.schedules;
let flag = 0
for(let i in s){
if (s[i].completion_status == pending){
flag = 1
}
}
if(count){
this.frm.add_custom_button(__('Create Maintenance Visit'), function () { this.frm.add_custom_button(__('Create Maintenance Visit'), function () {
let items = me.frm.doc.items; let items = me.frm.doc.items;
let s = me.frm.doc.schedules; let s = me.frm.doc.schedules;
@ -103,7 +111,7 @@ erpnext.maintenance.MaintenanceSchedule = frappe.ui.form.Controller.extend({
let field = d.get_field("scheduled_date"); let field = d.get_field("scheduled_date");
dates = "" dates = ""
for (let i in s) { for (let i in s) {
if (s[i].item_name == this.value) { if (s[i].item_name == this.value && s[i].completion_status == "Pending") {
dates = dates + '\n' + formatDate(s[i].scheduled_date); dates = dates + '\n' + formatDate(s[i].scheduled_date);
} }
@ -154,6 +162,7 @@ erpnext.maintenance.MaintenanceSchedule = frappe.ui.form.Controller.extend({
}, __('Create')); }, __('Create'));
} }
}
}, },
start_date: function (doc, cdt, cdn) { start_date: function (doc, cdt, cdn) {

View File

@ -33,6 +33,7 @@ class MaintenanceSchedule(TransactionBase):
count = count + 1 count = count + 1
child.sales_person = d.sales_person child.sales_person = d.sales_person
child.completion_status = "Pending" child.completion_status = "Pending"
child.item_ref = d.name
def on_submit(self): def on_submit(self):
if not self.get('schedules'): if not self.get('schedules'):
@ -172,8 +173,6 @@ class MaintenanceSchedule(TransactionBase):
def on_update(self): def on_update(self):
frappe.db.set(self, 'status', 'Draft') frappe.db.set(self, 'status', 'Draft')
def update_amc_date(self, serial_nos, amc_expiry_date=None): def update_amc_date(self, serial_nos, amc_expiry_date=None):
for serial_no in serial_nos: for serial_no in serial_nos:
serial_no_doc = frappe.get_doc("Serial No", serial_no) serial_no_doc = frappe.get_doc("Serial No", serial_no)
@ -255,6 +254,8 @@ def make_maintenance_visit(source_name, target_doc=None,item_name=None,s_id=None
def update_sid(source, target, parent): def update_sid(source, target, parent):
target.prevdoc_detail_docname = s_id target.prevdoc_detail_docname = s_id
sales_person = frappe.db.get_value('Maintenance Schedule Detail', s_id, 'sales_person')
target.service_person = sales_person
doclist = get_mapped_doc("Maintenance Schedule", source_name, { doclist = get_mapped_doc("Maintenance Schedule", source_name, {
"Maintenance Schedule": { "Maintenance Schedule": {

View File

@ -10,10 +10,11 @@
"item_code", "item_code",
"item_name", "item_name",
"scheduled_date", "scheduled_date",
"actual_date",
"sales_person", "sales_person",
"actual_date",
"completion_status",
"serial_no", "serial_no",
"completion_status" "item_ref"
], ],
"fields": [ "fields": [
{ {
@ -29,11 +30,9 @@
"search_index": 1 "search_index": 1
}, },
{ {
"columns": 2,
"fieldname": "item_name", "fieldname": "item_name",
"fieldtype": "Data", "fieldtype": "Data",
"in_global_search": 1, "in_global_search": 1,
"in_list_view": 1,
"label": "Item Name", "label": "Item Name",
"oldfieldname": "item_name", "oldfieldname": "item_name",
"oldfieldtype": "Data", "oldfieldtype": "Data",
@ -71,7 +70,8 @@
"label": "Sales Person", "label": "Sales Person",
"oldfieldname": "incharge_name", "oldfieldname": "incharge_name",
"oldfieldtype": "Link", "oldfieldtype": "Link",
"options": "Sales Person" "options": "Sales Person",
"read_only_depends_on": "eval:doc.completion_status != \"Pending\""
}, },
{ {
"fieldname": "serial_no", "fieldname": "serial_no",
@ -85,16 +85,25 @@
"width": "160px" "width": "160px"
}, },
{ {
"columns": 2,
"fieldname": "completion_status", "fieldname": "completion_status",
"fieldtype": "Select", "fieldtype": "Select",
"in_list_view": 1,
"label": "Completion Status", "label": "Completion Status",
"options": "Pending\nPartially Completed\nFully Completed" "options": "Pending\nPartially Completed\nFully Completed",
"read_only": 1
},
{
"fieldname": "item_ref",
"fieldtype": "Data",
"label": "Item Reference",
"read_only": 1
} }
], ],
"idx": 1, "idx": 1,
"istable": 1, "istable": 1,
"links": [], "links": [],
"modified": "2021-04-19 16:18:36.723319", "modified": "2021-04-19 17:42:31.685710",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Maintenance", "module": "Maintenance",
"name": "Maintenance Schedule Detail", "name": "Maintenance Schedule Detail",

View File

@ -4,6 +4,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from frappe import _ from frappe import _
from frappe.utils import get_datetime
from erpnext.utilities.transaction_base import TransactionBase from erpnext.utilities.transaction_base import TransactionBase
@ -16,8 +17,33 @@ class MaintenanceVisit(TransactionBase):
if d.serial_no and not frappe.db.exists("Serial No", d.serial_no): if d.serial_no and not frappe.db.exists("Serial No", d.serial_no):
frappe.throw(_("Serial No {0} does not exist").format(d.serial_no)) frappe.throw(_("Serial No {0} does not exist").format(d.serial_no))
def validate_mntc_date(self):
if self.maintenance_type == "Scheduled":
p = self.purposes
for i in p:
detail_ref = i.prevdoc_detail_docname
item_ref = frappe.db.get_value('Maintenance Schedule Detail', detail_ref , 'item_ref')
start_date, end_date = frappe.db.get_value('Maintenance Schedule Item', item_ref, ['start_date', 'end_date'])
if get_datetime(self.mntc_date) < get_datetime(start_date) or get_datetime(self.mntc_date) > get_datetime(end_date):
frappe.throw(_("Date must be between {0} and {1}").format(start_date,end_date))
def validate(self): def validate(self):
self.validate_serial_no() self.validate_serial_no()
self.validate_mntc_date()
def update_completion_status(self):
if self.maintenance_type == "Scheduled":
p = self.purposes
for i in p:
detail_ref = i.prevdoc_detail_docname
frappe.db.set_value('Maintenance Schedule Detail', detail_ref, 'completion_status', self.completion_status)
def update_actual_date(self):
if self.maintenance_type == "Scheduled":
p = self.purposes
for i in p:
detail_ref = i.prevdoc_detail_docname
frappe.db.set_value('Maintenance Schedule Detail', detail_ref, 'actual_date', self.mntc_date)
def update_customer_issue(self, flag): def update_customer_issue(self, flag):
for d in self.get('purposes'): for d in self.get('purposes'):
@ -77,6 +103,8 @@ class MaintenanceVisit(TransactionBase):
def on_submit(self): def on_submit(self):
self.update_customer_issue(1) self.update_customer_issue(1)
frappe.db.set(self, 'status', 'Submitted') frappe.db.set(self, 'status', 'Submitted')
self.update_completion_status()
self.update_actual_date()
def on_cancel(self): def on_cancel(self):
self.check_if_last_visit() self.check_if_last_visit()