fix for making the invoice from the timesheet (#12803)

This commit is contained in:
Manas Solanki 2018-02-07 12:07:27 +05:30 committed by Nabin Hait
parent ba31369764
commit b4693c6957
2 changed files with 11 additions and 5 deletions

View File

@ -39,7 +39,7 @@ frappe.ui.form.on("Timesheet", {
refresh: function(frm) { refresh: function(frm) {
if(frm.doc.docstatus==1) { 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") }, frm.add_custom_button(__("Make Sales Invoice"), function() { frm.trigger("make_invoice") },
"fa fa-file-alt"); "fa fa-file-alt");
} }

View File

@ -310,16 +310,16 @@ def get_timesheet(doctype, txt, searchfield, start, page_len, filters):
@frappe.whitelist() @frappe.whitelist()
def get_timesheet_data(name, project): def get_timesheet_data(name, project):
data = None
if project and project!='': if project and project!='':
data = get_projectwise_timesheet_data(project, name) data = get_projectwise_timesheet_data(project, name)
else: else:
data = frappe.get_all('Timesheet', data = frappe.get_all('Timesheet',
fields = ["(total_billable_amount - total_billed_amount) as billing_amt", "total_billable_hours as billing_hours"], filters = {'name': name}) fields = ["(total_billable_amount - total_billed_amount) as billing_amt", "total_billable_hours as billing_hours"], filters = {'name': name})
return { return {
'billing_hours': data[0].billing_hours, 'billing_hours': data[0].billing_hours if data else None,
'billing_amount': data[0].billing_amt, 'billing_amount': data[0].billing_amt if data else None,
'timesheet_detail': data[0].name if project and project!= '' else None 'timesheet_detail': data[0].name if data and project and project!= '' else None
} }
@frappe.whitelist() @frappe.whitelist()
@ -327,6 +327,12 @@ def make_sales_invoice(source_name, item_code=None, customer=None):
target = frappe.new_doc("Sales Invoice") target = frappe.new_doc("Sales Invoice")
timesheet = frappe.get_doc('Timesheet', source_name) 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) hours = flt(timesheet.total_billable_hours) - flt(timesheet.total_billed_hours)
billing_amount = flt(timesheet.total_billable_amount) - flt(timesheet.total_billed_amount) billing_amount = flt(timesheet.total_billable_amount) - flt(timesheet.total_billed_amount)
billing_rate = billing_amount / hours billing_rate = billing_amount / hours