refactor: using parent form links of maintenance schedule
This commit is contained in:
parent
3bca90dbe6
commit
7fa045c1c9
@ -17,70 +17,61 @@ 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):
|
def validate_maintenance_date(self):
|
||||||
if self.maintenance_type == "Scheduled":
|
if self.maintenance_type == "Scheduled" and self.maintenance_schedule_detail:
|
||||||
p = self.purposes
|
item_ref = frappe.db.get_value('Maintenance Schedule Detail', self.maintenance_schedule_detail, 'item_reference')
|
||||||
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'])
|
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):
|
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))
|
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()
|
self.validate_maintenance_date()
|
||||||
|
|
||||||
def get_schedule_datail_ref(self):
|
|
||||||
if self.maintenance_type == "Scheduled":
|
|
||||||
p = self.purposes
|
|
||||||
for i in p:
|
|
||||||
detail_ref = i.prevdoc_detail_docname
|
|
||||||
return detail_ref
|
|
||||||
|
|
||||||
def update_completion_status(self):
|
def update_completion_status(self):
|
||||||
detail_ref = self.get_schedule_datail_ref()
|
if self.maintenance_schedule_detail:
|
||||||
frappe.db.set_value('Maintenance Schedule Detail', detail_ref, 'completion_status', self.completion_status)
|
frappe.db.set_value('Maintenance Schedule Detail', self.maintenance_schedule_detail, 'completion_status', self.completion_status)
|
||||||
|
|
||||||
def update_actual_date(self):
|
def update_actual_date(self):
|
||||||
detail_ref = self.get_schedule_datail_ref()
|
if self.maintenance_schedule_detail:
|
||||||
frappe.db.set_value('Maintenance Schedule Detail', detail_ref, 'actual_date', self.mntc_date)
|
frappe.db.set_value('Maintenance Schedule Detail', self.maintenance_schedule_detail, 'actual_date', self.mntc_date)
|
||||||
|
|
||||||
def update_customer_issue(self, flag):
|
def update_customer_issue(self, flag):
|
||||||
for d in self.get('purposes'):
|
if not self.maintenance_schedule:
|
||||||
if d.prevdoc_docname and d.prevdoc_doctype == 'Warranty Claim' :
|
for d in self.get('purposes'):
|
||||||
if flag==1:
|
if d.prevdoc_docname and d.prevdoc_doctype == 'Warranty Claim' :
|
||||||
mntc_date = self.mntc_date
|
if flag==1:
|
||||||
service_person = d.service_person
|
mntc_date = self.mntc_date
|
||||||
work_done = d.work_done
|
service_person = d.service_person
|
||||||
status = "Open"
|
work_done = d.work_done
|
||||||
if self.completion_status == 'Fully Completed':
|
status = "Open"
|
||||||
status = 'Closed'
|
if self.completion_status == 'Fully Completed':
|
||||||
elif self.completion_status == 'Partially Completed':
|
status = 'Closed'
|
||||||
status = 'Work In Progress'
|
elif self.completion_status == 'Partially Completed':
|
||||||
else:
|
status = 'Work In Progress'
|
||||||
nm = frappe.db.sql("select t1.name, t1.mntc_date, t2.service_person, t2.work_done from `tabMaintenance Visit` t1, `tabMaintenance Visit Purpose` t2 where t2.parent = t1.name and t1.completion_status = 'Partially Completed' and t2.prevdoc_docname = %s and t1.name!=%s and t1.docstatus = 1 order by t1.name desc limit 1", (d.prevdoc_docname, self.name))
|
|
||||||
|
|
||||||
if nm:
|
|
||||||
status = 'Work In Progress'
|
|
||||||
mntc_date = nm and nm[0][1] or ''
|
|
||||||
service_person = nm and nm[0][2] or ''
|
|
||||||
work_done = nm and nm[0][3] or ''
|
|
||||||
else:
|
else:
|
||||||
status = 'Open'
|
nm = frappe.db.sql("select t1.name, t1.mntc_date, t2.service_person, t2.work_done from `tabMaintenance Visit` t1, `tabMaintenance Visit Purpose` t2 where t2.parent = t1.name and t1.completion_status = 'Partially Completed' and t2.prevdoc_docname = %s and t1.name!=%s and t1.docstatus = 1 order by t1.name desc limit 1", (d.prevdoc_docname, self.name))
|
||||||
mntc_date = None
|
|
||||||
service_person = None
|
|
||||||
work_done = None
|
|
||||||
|
|
||||||
wc_doc = frappe.get_doc('Warranty Claim', d.prevdoc_docname)
|
if nm:
|
||||||
wc_doc.update({
|
status = 'Work In Progress'
|
||||||
'resolution_date': mntc_date,
|
mntc_date = nm and nm[0][1] or ''
|
||||||
'resolved_by': service_person,
|
service_person = nm and nm[0][2] or ''
|
||||||
'resolution_details': work_done,
|
work_done = nm and nm[0][3] or ''
|
||||||
'status': status
|
else:
|
||||||
})
|
status = 'Open'
|
||||||
|
mntc_date = None
|
||||||
|
service_person = None
|
||||||
|
work_done = None
|
||||||
|
|
||||||
wc_doc.db_update()
|
wc_doc = frappe.get_doc('Warranty Claim', d.prevdoc_docname)
|
||||||
|
wc_doc.update({
|
||||||
|
'resolution_date': mntc_date,
|
||||||
|
'resolved_by': service_person,
|
||||||
|
'resolution_details': work_done,
|
||||||
|
'status': status
|
||||||
|
})
|
||||||
|
|
||||||
|
wc_doc.db_update()
|
||||||
|
|
||||||
def check_if_last_visit(self):
|
def check_if_last_visit(self):
|
||||||
"""check if last maintenance visit against same sales order/ Warranty Claim"""
|
"""check if last maintenance visit against same sales order/ Warranty Claim"""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user