Merge pull request #5353 from MaxMorais/patch-4

Small improvement in maintenance scheduler
This commit is contained in:
Rushabh Mehta 2016-05-16 14:56:17 +05:30
commit a484ff751b

View File

@ -47,28 +47,37 @@ class MaintenanceSchedule(TransactionBase):
self.validate_serial_no(serial_nos, d.start_date) self.validate_serial_no(serial_nos, d.start_date)
self.update_amc_date(serial_nos, d.end_date) self.update_amc_date(serial_nos, d.end_date)
no_email_sp = []
if d.sales_person not in email_map: if d.sales_person not in email_map:
sp = frappe.get_doc("Sales Person", d.sales_person) sp = frappe.get_doc("Sales Person", d.sales_person)
email_map[d.sales_person] = sp.get_email_id() try:
email_map[d.sales_person] = sp.get_email_id()
except frappe.ValidationError:
no_email_sp.append(d.sales_person)
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(
doc.owner, "<br>"+no_email_sp.join("<br>")
))
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
parent=%s""", (d.sales_person, d.item_code, self.name), as_dict=1) parent=%s""", (d.sales_person, d.item_code, self.name), as_dict=1)
for key in scheduled_date: for key in scheduled_date:
if email_map[d.sales_person]: description = frappe._("Reference: %s, Item Code: %s and Customer: %s") % \
description = "Reference: %s, Item Code: %s and Customer: %s" % \ (self.name, d.item_code, self.customer)
(self.name, d.item_code, self.customer) frappe.get_doc({
frappe.get_doc({ "doctype": "Event",
"doctype": "Event", "owner": email_map.get(d.sales_person, self.owner),
"owner": email_map[d.sales_person] or 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", "ref_type": self.doctype,
"ref_type": self.doctype, "ref_name": self.name
"ref_name": self.name }).insert(ignore_permissions=1)
}).insert(ignore_permissions=1)
frappe.db.set(self, 'status', 'Submitted') frappe.db.set(self, 'status', 'Submitted')
@ -144,7 +153,7 @@ class MaintenanceSchedule(TransactionBase):
elif not d.sales_person: elif not d.sales_person:
throw(_("Please select Incharge Person's name")) throw(_("Please select Incharge Person's name"))
if getdate(d.start_date) >= getdate(d.end_date): if getdate(d.start_date) > getdate(d.end_date):
throw(_("Start date should be less than end date for Item {0}").format(d.item_code)) throw(_("Start date should be less than end date for Item {0}").format(d.item_code))
def validate_sales_order(self): def validate_sales_order(self):