fix for making the invoice from the timesheet (#12803)
diff --git a/erpnext/projects/doctype/timesheet/timesheet.js b/erpnext/projects/doctype/timesheet/timesheet.js
index 43f5705..99ee2a2 100644
--- a/erpnext/projects/doctype/timesheet/timesheet.js
+++ b/erpnext/projects/doctype/timesheet/timesheet.js
@@ -39,7 +39,7 @@
refresh: function(frm) {
if(frm.doc.docstatus==1) {
- if(frm.doc.per_billed < 100){
+ if(frm.doc.per_billed < 100 && frm.doc.total_billable_hours && frm.doc.total_billable_hours > frm.doc.total_billed_hours){
frm.add_custom_button(__("Make Sales Invoice"), function() { frm.trigger("make_invoice") },
"fa fa-file-alt");
}
diff --git a/erpnext/projects/doctype/timesheet/timesheet.py b/erpnext/projects/doctype/timesheet/timesheet.py
index 01552a5..8d339b9 100644
--- a/erpnext/projects/doctype/timesheet/timesheet.py
+++ b/erpnext/projects/doctype/timesheet/timesheet.py
@@ -310,16 +310,16 @@
@frappe.whitelist()
def get_timesheet_data(name, project):
+ data = None
if project and project!='':
data = get_projectwise_timesheet_data(project, name)
else:
data = frappe.get_all('Timesheet',
fields = ["(total_billable_amount - total_billed_amount) as billing_amt", "total_billable_hours as billing_hours"], filters = {'name': name})
-
return {
- 'billing_hours': data[0].billing_hours,
- 'billing_amount': data[0].billing_amt,
- 'timesheet_detail': data[0].name if project and project!= '' else None
+ 'billing_hours': data[0].billing_hours if data else None,
+ 'billing_amount': data[0].billing_amt if data else None,
+ 'timesheet_detail': data[0].name if data and project and project!= '' else None
}
@frappe.whitelist()
@@ -327,6 +327,12 @@
target = frappe.new_doc("Sales Invoice")
timesheet = frappe.get_doc('Timesheet', source_name)
+ if not timesheet.total_billable_hours:
+ frappe.throw(_("Invoice can't be made for zero billing hour"))
+
+ if timesheet.total_billable_hours == timesheet.total_billed_hours:
+ frappe.throw(_("Invoice already created for all billing hours"))
+
hours = flt(timesheet.total_billable_hours) - flt(timesheet.total_billed_hours)
billing_amount = flt(timesheet.total_billable_amount) - flt(timesheet.total_billed_amount)
billing_rate = billing_amount / hours