From 28453efeced7e2d449b817b5b4d894977dca7249 Mon Sep 17 00:00:00 2001 From: Maxwell Morais Date: Mon, 16 May 2016 00:50:03 -0300 Subject: [PATCH 1/5] Small improvement in maintenance scheduler This improvement is intended to start disable blocking Maintenance Schedule submit, when the `Sales Person` does not have a `user_id` in the Employee! The old logic try to use the `sales_person` email_id or the `owner` to create the event, but due some fails in the code, it dont occurs! --- .../maintenance_schedule.py | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py index 5fab1ace72..7d762f49ee 100644 --- a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py +++ b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py @@ -49,26 +49,28 @@ class MaintenanceSchedule(TransactionBase): if d.sales_person not in email_map: 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: + pass scheduled_date = frappe.db.sql("""select scheduled_date from `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) for key in scheduled_date: - if email_map[d.sales_person]: - description = "Reference: %s, Item Code: %s and Customer: %s" % \ - (self.name, d.item_code, self.customer) - frappe.get_doc({ - "doctype": "Event", - "owner": email_map[d.sales_person] or self.owner, - "subject": description, - "description": description, - "starts_on": cstr(key["scheduled_date"]) + " 10:00:00", - "event_type": "Private", - "ref_type": self.doctype, - "ref_name": self.name - }).insert(ignore_permissions=1) + description = "Reference: %s, Item Code: %s and Customer: %s" % \ + (self.name, d.item_code, self.customer) + 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", + "ref_type": self.doctype, + "ref_name": self.name + }).insert(ignore_permissions=1) frappe.db.set(self, 'status', 'Submitted') From 4e7b52952ee866fa07b96378b90a683d7594b5a0 Mon Sep 17 00:00:00 2001 From: Maxwell Morais Date: Mon, 16 May 2016 05:38:04 -0300 Subject: [PATCH 2/5] Added warning Added a warning to show a information to the active user --- .../doctype/maintenance_schedule/maintenance_schedule.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py index 7d762f49ee..478c277d38 100644 --- a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py +++ b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py @@ -47,12 +47,19 @@ class MaintenanceSchedule(TransactionBase): self.validate_serial_no(serial_nos, d.start_date) self.update_amc_date(serial_nos, d.end_date) + no_email_sp = [] if d.sales_person not in email_map: sp = frappe.get_doc("Sales Person", d.sales_person) try: email_map[d.sales_person] = sp.get_email_id() except frappe.ValidationError: - pass + no_email_sp.append(d.sales_person) + + if no_email_sp: + frappe.msgprint( + "Setting Events to {0}, since the Employee attached to the below Sales Persons does not have a User ID
{1}".format( + doc.owner, no_email_sp.join("
") + )) scheduled_date = frappe.db.sql("""select scheduled_date from `tabMaintenance Schedule Detail` where sales_person=%s and item_code=%s and From 52a66fc90b320530f325ba2ec5d7c98af3f2800f Mon Sep 17 00:00:00 2001 From: Maxwell Morais Date: Mon, 16 May 2016 06:06:59 -0300 Subject: [PATCH 3/5] Reduce start and end date verification Given the actual scenario, that verify if the start_date <= end_date, do schedule a Maintenance, 2 days are required, but in many cases only one day is required! --- .../doctype/maintenance_schedule/maintenance_schedule.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py index 478c277d38..f30598f8a4 100644 --- a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py +++ b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py @@ -153,7 +153,7 @@ class MaintenanceSchedule(TransactionBase): elif not d.sales_person: 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)) def validate_sales_order(self): From 89fdbdf404590575c9d5d90e1235cf96b43773bb Mon Sep 17 00:00:00 2001 From: Maxwell Morais Date: Mon, 16 May 2016 06:08:51 -0300 Subject: [PATCH 4/5] Translation improvements Translation improvements --- .../doctype/maintenance_schedule/maintenance_schedule.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py index f30598f8a4..c2395e8b2b 100644 --- a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py +++ b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py @@ -57,7 +57,7 @@ class MaintenanceSchedule(TransactionBase): if no_email_sp: frappe.msgprint( - "Setting Events to {0}, since the Employee attached to the below Sales Persons does not have a User ID
{1}".format( + frappe._("Setting Events to {0}, since the Employee attached to the below Sales Persons does not have a User ID
{1}").format( doc.owner, no_email_sp.join("
") )) @@ -66,7 +66,7 @@ class MaintenanceSchedule(TransactionBase): parent=%s""", (d.sales_person, d.item_code, self.name), as_dict=1) for key in scheduled_date: - description = "Reference: %s, Item Code: %s and Customer: %s" % \ + description = frappe._("Reference: %s, Item Code: %s and Customer: %s") % \ (self.name, d.item_code, self.customer) frappe.get_doc({ "doctype": "Event", From 92b0be93c747090fed107a17ab8c6f3a577a470a Mon Sep 17 00:00:00 2001 From: Maxwell Morais Date: Mon, 16 May 2016 06:24:55 -0300 Subject: [PATCH 5/5] Removed HTML tags from messages Remove HTML from messages --- .../doctype/maintenance_schedule/maintenance_schedule.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py index c2395e8b2b..9821246129 100644 --- a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py +++ b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py @@ -57,8 +57,8 @@ 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( - doc.owner, no_email_sp.join("
") + frappe._("Setting Events to {0}, since the Employee attached to the below Sales Persons does not have a User ID{1}").format( + doc.owner, "
"+no_email_sp.join("
") )) scheduled_date = frappe.db.sql("""select scheduled_date from