feat: add total_billing_hours to Sales Invoice (#26652)

* feat: add `total_billing_hours` to Sales Invoice

* refactor: sider fixes

* style: use double quotes
This commit is contained in:
Raffael Meyer
2021-08-26 09:04:09 +02:00
committed by GitHub
parent aa358b021e
commit 710c1c1786
3 changed files with 37 additions and 31 deletions

View File

@@ -825,45 +825,43 @@ frappe.ui.form.on('Sales Invoice', {
method: "erpnext.accounts.doctype.sales_invoice.sales_invoice.create_invoice_discounting",
frm: frm
});
}
})
},
frappe.ui.form.on('Sales Invoice Timesheet', {
calculate_timesheet_totals: function(frm) {
frm.set_value("total_billing_amount",
frm.doc.timesheets.reduce((a, b) => a + (b["billing_amount"] || 0.0), 0.0));
frm.set_value("total_billing_hours",
frm.doc.timesheets.reduce((a, b) => a + (b["billing_hours"] || 0.0), 0.0));
}
});
frappe.ui.form.on("Sales Invoice Timesheet", {
time_sheet: function(frm, cdt, cdn){
var d = locals[cdt][cdn];
if(d.time_sheet) {
frappe.call({
method: "erpnext.projects.doctype.timesheet.timesheet.get_timesheet_data",
args: {
'name': d.time_sheet,
'project': frm.doc.project || null
"name": d.time_sheet,
"project": frm.doc.project || null
},
callback: function(r, rt) {
callback: function(r) {
if(r.message){
data = r.message;
frappe.model.set_value(cdt, cdn, "billing_hours", data.billing_hours);
frappe.model.set_value(cdt, cdn, "billing_amount", data.billing_amount);
frappe.model.set_value(cdt, cdn, "timesheet_detail", data.timesheet_detail);
calculate_total_billing_amount(frm)
frappe.model.set_value(cdt, cdn, "billing_hours", r.message.billing_hours);
frappe.model.set_value(cdt, cdn, "billing_amount", r.message.billing_amount);
frappe.model.set_value(cdt, cdn, "timesheet_detail", r.message.timesheet_detail);
frm.trigger("calculate_timesheet_totals");
}
}
})
});
}
},
timesheets_remove: function(frm, cdt, cdn) {
frm.trigger("calculate_timesheet_totals");
}
})
});
var calculate_total_billing_amount = function(frm) {
var doc = frm.doc;
doc.total_billing_amount = 0.0
if(doc.timesheets) {
$.each(doc.timesheets, function(index, data){
doc.total_billing_amount += data.billing_amount
})
}
refresh_field('total_billing_amount')
}
var select_loyalty_program = function(frm, loyalty_programs) {
var dialog = new frappe.ui.Dialog({

View File

@@ -69,6 +69,7 @@
"time_sheet_list",
"timesheets",
"total_billing_amount",
"total_billing_hours",
"section_break_30",
"total_qty",
"base_total",
@@ -1564,12 +1565,20 @@
{
"fieldname": "dimension_col_break",
"fieldtype": "Column Break"
},
{
"default": "0",
"fieldname": "total_billing_hours",
"fieldtype": "Float",
"label": "Total Billing Hours",
"print_hide": 1,
"read_only": 1
}
],
"icon": "fa fa-file-text",
"idx": 181,
"is_submittable": 1,
"modified": "2020-07-01 12:41:29.484813",
"modified": "2021-07-26 14:01:34.605644",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Sales Invoice",

View File

@@ -683,12 +683,11 @@ class SalesInvoice(SellingController):
self.calculate_billing_amount_for_timesheet()
def calculate_billing_amount_for_timesheet(self):
total_billing_amount = 0.0
for data in self.timesheets:
if data.billing_amount:
total_billing_amount += data.billing_amount
def timesheet_sum(field):
return sum((ts.get(field) or 0.0) for ts in self.timesheets)
self.total_billing_amount = total_billing_amount
self.total_billing_amount = timesheet_sum("billing_amount")
self.total_billing_hours = timesheet_sum("billing_hours")
def get_warehouse(self):
user_pos_profile = frappe.db.sql("""select name, warehouse from `tabPOS Profile`