fixes to frappe/erpnext#1456, frappe/erpnext#1440