feat: add total_billing_hours to Sales Invoice

This commit is contained in:
barredterra
2021-08-02 18:37:45 +02:00
parent db40d88fc2
commit b57521a337
3 changed files with 36 additions and 33 deletions

View File

@@ -829,7 +829,7 @@ frappe.ui.form.on('Sales Invoice', {
'timesheet_detail': row.name
});
frm.refresh_field('timesheets');
calculate_total_billing_amount(frm);
frm.trigger("calculate_timesheet_totals");
},
refresh: function(frm) {
@@ -937,50 +937,46 @@ frappe.ui.form.on('Sales Invoice', {
frm: frm
});
},
create_dunning: function(frm) {
frappe.model.open_mapped_doc({
method: "erpnext.accounts.doctype.sales_invoice.sales_invoice.create_dunning",
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) {
if(r.message){
let 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)
callback: function(r) {
if(r.message) {
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");
}
}
})
});
}
}
})
});
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

@@ -74,6 +74,7 @@
"time_sheet_list",
"timesheets",
"total_billing_amount",
"total_billing_hours",
"section_break_30",
"total_qty",
"base_total",
@@ -1983,6 +1984,13 @@
"fieldtype": "Small Text",
"label": "Dispatch Address",
"read_only": 1
},
{
"fieldname": "total_billing_hours",
"fieldtype": "Float",
"label": "Total Billing Hours",
"print_hide": 1,
"read_only": 1
}
],
"icon": "fa fa-file-text",
@@ -1995,7 +2003,7 @@
"link_fieldname": "consolidated_invoice"
}
],
"modified": "2021-07-08 14:03:55.502522",
"modified": "2021-08-02 18:36:51.978581",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Sales Invoice",

View File

@@ -764,12 +764,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`