Fixes frappe/erpnext#1732 and frappe/erpnext#1733