diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index 3245e78e13..4886deaa71 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -483,4 +483,5 @@ frappe.ui.form.on('Sales Invoice Timesheet', { } }) +cur_frm.add_fetch("time_sheet", "total_billing_hours", "billing_hours"); cur_frm.add_fetch("time_sheet", "total_billing_amount", "billing_amount"); \ No newline at end of file diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 3ebe873185..3bbd5ad055 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -83,6 +83,7 @@ class SalesInvoice(SellingController): self.validate_time_sheets_are_submitted() self.validate_multiple_billing("Delivery Note", "dn_detail", "amount", "items") self.update_packing_list() + self.set_billing_hours_and_amount() self.calculate_billing_amount_from_timesheet() def before_save(self): @@ -440,6 +441,15 @@ class SalesInvoice(SellingController): else: self.set('packed_items', []) + def set_billing_hours_and_amount(self): + for timesheet in self.timesheets: + ts_doc = frappe.get_doc('Timesheet', timesheet.time_sheet) + if not timesheet.billing_hours and ts_doc.total_billing_hours: + timesheet.billing_hours = ts_doc.total_billing_hours + + if not timesheet.billing_amount and ts_doc.total_billing_amount: + timesheet.billing_amount = ts_doc.total_billing_amount + def calculate_billing_amount_from_timesheet(self): total_billing_amount = 0.0 for data in self.timesheets: diff --git a/erpnext/projects/doctype/timesheet/timesheet.py b/erpnext/projects/doctype/timesheet/timesheet.py index c2a2d3e6d6..63cb8981d0 100644 --- a/erpnext/projects/doctype/timesheet/timesheet.py +++ b/erpnext/projects/doctype/timesheet/timesheet.py @@ -313,7 +313,7 @@ def get_events(start, end, filters=None): conditions = get_conditions(filters) return frappe.db.sql("""select `tabTimesheet Detail`.name as name, `tabTimesheet Detail`.parent as parent, from_time, hours, activity_type, project, to_time from `tabTimesheet Detail`, - `tabTimesheet` where `tabTimesheet Detail`.parent = `tabTimesheet`.name and + `tabTimesheet` where `tabTimesheet Detail`.parent = `tabTimesheet`.name and `tabTimesheet`.docstatus < 2 and (from_time between %(start)s and %(end)s) {conditions}""".format(conditions=conditions), { "start": start,