Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaurav Naik committed May 20, 2017
2 parents 4ed1c0a + a76547c commit 6b5ecfd
Show file tree
Hide file tree
Showing 7 changed files with 334 additions and 298 deletions.
2 changes: 1 addition & 1 deletion refreshednow_erpnext/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

__version__ = '2.1.5'
__version__ = '2.1.6'

40 changes: 27 additions & 13 deletions refreshednow_erpnext/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,14 @@ def cancel_all_allocations(employee, day_of_week):
frappe.db.commit()

def item_validate(self, method):
if (self.rn_break_duration % 15 != 0):
frappe.throw("Break duration must be in intervals of 15 minutes.")
if self.is_stock_item == 0:
if (self.rn_break_duration % 15 != 0):
frappe.throw("Break duration must be in intervals of 15 minutes.")

if (self.rn_service_duration % 15 != 0):
frappe.throw("Service duration must be in intervals of 15 minutes.")
if (self.rn_service_duration % 15 != 0):
frappe.throw("Service duration must be in intervals of 15 minutes.")
else:
pass

@frappe.whitelist()
def get_availability_for_team_dow(team, day_of_week):
Expand Down Expand Up @@ -510,14 +513,15 @@ def print_job_sheet(names):
pdf_options = {
"no-outline": None,
"encoding": "UTF-8",
"title": "Job Sheet"
"title": "Job Sheet",
"orientation": "landscape"
}

#frappe.local.response.filename = "{filename}.pdf".format(filename="job_sheet_list".replace(" ", "-").replace("/", "-"))
filecontent, filename = rn_get_pdf(final_html, options=pdf_options)

frappe.local.response.filecontent = filecontent
frappe.local.response.filename = "{filename}.pdf".format(filename=filename).replace(" ", "-").replace("/", "-")
frappe.local.response.filename = "refreshed-jobsheet-{0}.pdf".format(frappe.utils.data.format_datetime(frappe.utils.today(),"YYYY-MM-dd"))
frappe.local.response.type = "download"

def prepare_bulk_print_html(names):
Expand All @@ -539,8 +543,9 @@ def prepare_bulk_print_html(names):

ss_rn_golist = sorted(ss_rn_golist, key=lambda v:v.get("starts_on"))
ss_rn_prolist = sorted(ss_rn_prolist, key=lambda v:v.get("starts_on"))
date_for_title = frappe.utils.data.format_datetime(frappe.utils.data.add_to_date(frappe.utils.today(), days=1),"d-MMM")

html_params = { "ss_rn_golist": ss_rn_golist or [], "ss_rn_prolist": ss_rn_prolist or []}
html_params = { "ss_rn_golist": ss_rn_golist or [], "ss_rn_prolist": ss_rn_prolist or [], "date_for_title": date_for_title or ""}
final_html = frappe.render_template("refreshednow_erpnext/templates/includes/refreshed_jobsheet.html", html_params)

return final_html
Expand All @@ -549,7 +554,7 @@ def prepare_bulk_print_html(names):
def rn_get_pdf(html, options=None):
print "RN GET PDF"
date = frappe.utils.add_days(frappe.utils.getdate(), 1)
fname = os.path.join(frappe.get_site_path(), "public","files", "refreshed-jobsheet-{0}.pdf ".format(frappe.utils.data.format_datetime(date,"YYYY-MM-dd")))
fname = os.path.join(frappe.get_site_path(), "public","files", "refreshed-jobsheet-{0}.pdf".format(frappe.utils.data.format_datetime(date,"YYYY-MM-dd")))
cleanup(fname)
try:
pdfkit.from_string(html, fname, options=options or {})
Expand Down Expand Up @@ -595,11 +600,12 @@ def get_tomorrows_servicelist():
pdf_options = {
"no-outline": None,
"encoding": "UTF-8",
"title": "Job Sheet"
"title": "Job Sheet",
"orientation": "landscape"
}
pdf_data, pdf_fname = rn_get_pdf(final_html, pdf_options)

return pdf_data, pdf_fname
return tomorrow, pdf_data, pdf_fname

def cleanup(fname):
if os.path.exists(fname):
Expand Down Expand Up @@ -650,9 +656,17 @@ def send_jobsheet():
#Comparison times are adjusted for SF time.
if nowtime_ak.hour in [20]:
try:
pdf_file, pdf_fname = get_tomorrows_servicelist()
attachment = frappe._dict({"fname": pdf_fname, "fcontent":pdf_file})
frappe.sendmail(sender="[email protected]", recipients=["[email protected]", "[email protected]"], subject="Refreshed Now Job Sheet", message="[Test Message] PFA Job Sheet for tomorrow.", attachments=attachment)
tomorrow, pdf_file, pdf_fname = get_tomorrows_servicelist()
# pdf_name = os.path.basename(pdf_fname)
pdf_name = "job-sheet-" + frappe.utils.data.format_datetime(tomorrow,"dd-MM-YYYY") + ".pdf"

attachment = frappe._dict({"fname": pdf_name, "fcontent":pdf_file})
frappe.sendmail(
sender="[email protected]",
recipients=["[email protected]", "[email protected]"],
subject="Refreshed Job Sheet for " + frappe.utils.data.format_datetime(tomorrow,"d-MMM"),
message="Attached is the Job Sheet for " + frappe.utils.data.format_datetime(tomorrow,"EEEE d-MMM-Y"),
attachments=attachment)
except Exception as e:
msg = "Job sheet was not sent. <br> Reason: {0}".format(e.message)
else:
Expand Down
9 changes: 9 additions & 0 deletions refreshednow_erpnext/fixtures/custom_script.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,14 @@
"name": "Contact-Client",
"script": "frappe.ui.form.on(\"Contact\", \"validate\", function(frm) {\n if (frm.doc.phone.length != 10 ) {\n msgprint(\"Please enter a valid 10-digit mobile no in this field.\");\n validated = false;\n }\n});",
"script_type": "Client"
},
{
"docstatus": 0,
"doctype": "Custom Script",
"dt": "Item",
"modified": "2017-05-19 20:27:40.676972",
"name": "Item-Client",
"script": "frappe.ui.form.on(\"Item\", \"is_stock_item\", function(frm) {\n if (frm.doc.is_stock_item == 1 ) {\n\tcur_frm.set_df_property(\"rn_sb_service_item_info\", \"hidden\");\n\tfrm.set_value(\"rn_start_time_hours\", \"\"); \n\tfrm.set_value(\"rn_end_time_hours\", \"\");\n\tfrm.set_value(\"rn_break_start_time_hours\", \"\");\n\tfrm.set_value(\"rn_break_duration\", \"\");\n\tfrm.set_value(\"rn_start_time_minutes\", \"\"); \n\tfrm.set_value(\"rn_end_time_minutes\", \"\");\n\tfrm.set_value(\"rn_break_start_time_minutes\", \"\");\n\tfrm.set_value(\"rn_service_duration\", \"\");\n }\n});",
"script_type": "Client"
}
]
2 changes: 1 addition & 1 deletion refreshednow_erpnext/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
# "frappe.desk.doctype.event.event.get_events": "refreshednow_erpnext.event.get_events"
# }

fixtures = [{"dt":"Custom Script", "filters": [["name", "in", ["Customer-Client","Contact-Client"]]]},
fixtures = [{"dt":"Custom Script", "filters": [["name", "in", ["Item-Client","Customer-Client","Contact-Client"]]]},
{"dt": "Custom Field", "filters": [["name", "in", [
"Item-rn_sb_service_item_info",
"Item-rn_start_time_hours",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,32 @@ frappe.ui.form.on('RN Scheduled Service', {
if (r || r.message) {
console.log("Setting values", r);
cur_frm.set_value("customer", r.message.customer);
cur_frm.set_value("rn_unsubscribe_sms", r.message.sms_check);
var phone = r.message.phone.replace(" ", "");
cur_frm.set_value("contact_phone", phone);
if (r.message.address) {
cur_frm.set_value("billing_address", r.message.address[0].parent);
cur_frm.set_value("service_address", r.message.address[0].parent);
}
cur_frm.set_value("vehicle_count", 1);
//cur_frm.set_value("rn_unsubscribe_sms", r.message.sms_check);
}
}
});
}
}
},
// rn_unsubscribe_sms: function(frm) {
// frappe.call({
// method: "set_unsubscribe_sms",
// doc: frm.doc,
// callback:function(r) {
// if (r.message == 1) {
// frappe.show_alert("SMS alerts will not be sent to " + frm.doc.customer);
// } else {
// frappe.show_alert("SMS alerts will be sent to " + frm.doc.customer);
// }
// }
// });
// }
});

function render_vehicles(frm) {
Expand Down
Loading

0 comments on commit 6b5ecfd

Please sign in to comment.