Merge pull request #24772 from anupamvs/si-timesheet

feat: provision to pull timesheet in sales invoice
This commit is contained in:
Deepesh Garg 2021-03-02 18:05:42 +05:30 committed by GitHub
commit 7a5b6021b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 66 additions and 4 deletions

View File

@ -695,6 +695,7 @@ frappe.ui.form.on('Sales Invoice', {
refresh_field(['timesheets'])
}
})
frm.refresh();
},
onload: function(frm) {
@ -810,6 +811,65 @@ frappe.ui.form.on('Sales Invoice', {
},
refresh: function(frm) {
if (frm.doc.project) {
frm.add_custom_button(__('Fetch Timesheet'), function() {
let d = new frappe.ui.Dialog({
title: __('Fetch Timesheet'),
fields: [
{
"label" : "From",
"fieldname": "from_time",
"fieldtype": "Date",
"reqd": 1,
},
{
fieldtype: 'Column Break',
fieldname: 'col_break_1',
},
{
"label" : "To",
"fieldname": "to_time",
"fieldtype": "Date",
"reqd": 1,
}
],
primary_action: function() {
let data = d.get_values();
frappe.call({
method: "erpnext.projects.doctype.timesheet.timesheet.get_projectwise_timesheet_data",
args: {
from_time: data.from_time,
to_time: data.to_time,
project: frm.doc.project
},
callback: function(r) {
if(!r.exc) {
if(r.message.length > 0) {
frm.clear_table('timesheets')
r.message.forEach((d) => {
frm.add_child('timesheets',{
'time_sheet': d.parent,
'billing_hours': d.billing_hours,
'billing_amount': d.billing_amt,
'timesheet_detail': d.name
});
});
frm.refresh_field('timesheets')
}
else {
frappe.msgprint(__('No Timesheet Found.'))
}
d.hide();
}
}
});
},
primary_action_label: __('Get Timesheets')
});
d.show();
})
}
if (frappe.boot.active_domains.includes("Healthcare")) {
frm.set_df_property("patient", "hidden", 0);
frm.set_df_property("patient_name", "hidden", 0);

View File

@ -204,14 +204,16 @@ class Timesheet(Document):
ts_detail.billing_rate = 0.0
@frappe.whitelist()
def get_projectwise_timesheet_data(project, parent=None):
cond = ''
def get_projectwise_timesheet_data(project, parent=None, from_time=None, to_time=None):
condition = ''
if parent:
cond = "and parent = %(parent)s"
condition = "AND parent = %(parent)s"
if from_time and to_time:
condition += "AND from_time BETWEEN %(from_time)s AND %(to_time)s"
return frappe.db.sql("""select name, parent, billing_hours, billing_amount as billing_amt
from `tabTimesheet Detail` where parenttype = 'Timesheet' and docstatus=1 and project = %(project)s {0} and billable = 1
and sales_invoice is null""".format(cond), {'project': project, 'parent': parent}, as_dict=1)
and sales_invoice is null""".format(condition), {'project': project, 'parent': parent, 'from_time': from_time, 'to_time': to_time}, as_dict=1)
@frappe.whitelist()
@frappe.validate_and_sanitize_search_inputs