Fetch employee advance in expense claim on adding it manually (#12069)
* added trigger on manually adding an advance * improvised the query * codacy fix * updated
This commit is contained in:
parent
0acf687e20
commit
ec1cb79e5f
@ -168,6 +168,16 @@ frappe.ui.form.on("Expense Claim", {
|
||||
frm.trigger("set_query_for_payable_account");
|
||||
frm.add_fetch("company", "cost_center", "cost_center");
|
||||
frm.add_fetch("company", "default_payable_account", "payable_account");
|
||||
frm.set_query("employee_advance", "advances", function(doc) {
|
||||
return {
|
||||
filters: [
|
||||
['docstatus', '=', 1],
|
||||
['employee', '=', doc.employee],
|
||||
['paid_amount', '>', 0],
|
||||
['paid_amount', '>', 'claimed_amount']
|
||||
]
|
||||
};
|
||||
});
|
||||
},
|
||||
|
||||
refresh: function(frm) {
|
||||
@ -294,10 +304,41 @@ frappe.ui.form.on("Expense Claim Detail", {
|
||||
}
|
||||
});
|
||||
|
||||
frappe.ui.form.on("Expense Claim Advance", {
|
||||
employee_advance: function(frm, cdt, cdn) {
|
||||
var child = locals[cdt][cdn];
|
||||
if(!frm.doc.employee){
|
||||
frappe.msgprint('Select an employee to get the employee advance.');
|
||||
frm.doc.advances = [];
|
||||
refresh_field("advances");
|
||||
}
|
||||
else {
|
||||
return frappe.call({
|
||||
method: "erpnext.hr.doctype.expense_claim.expense_claim.get_advances",
|
||||
args: {
|
||||
employee: frm.doc.employee,
|
||||
advance_id: child.employee_advance
|
||||
},
|
||||
callback: function(r, rt) {
|
||||
if(r.message) {
|
||||
child.employee_advance = r.message[0].name;
|
||||
child.posting_date = r.message[0].posting_date;
|
||||
child.advance_account = r.message[0].advance_account;
|
||||
child.advance_paid = r.message[0].paid_amount;
|
||||
child.unclaimed_amount = flt(r.message[0].paid_amount) - flt(r.message[0].claimed_amount);
|
||||
child.allocated_amount = flt(r.message[0].paid_amount) - flt(r.message[0].claimed_amount);
|
||||
refresh_field("advances");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
cur_frm.fields_dict['task'].get_query = function(doc) {
|
||||
return {
|
||||
filters:{
|
||||
'project': doc.project
|
||||
}
|
||||
};
|
||||
};
|
||||
};
|
@ -310,9 +310,16 @@ def get_expense_claim_account(expense_claim_type, company):
|
||||
}
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_advances(employee):
|
||||
def get_advances(employee, advance_id=None):
|
||||
if not advance_id:
|
||||
condition = 'docstatus=1 and employee="{0}" and paid_amount > 0 and paid_amount > claimed_amount'.format(frappe.db.escape(employee))
|
||||
else:
|
||||
condition = 'name="{0}"'.format(frappe.db.escape(advance_id))
|
||||
|
||||
return frappe.db.sql("""
|
||||
select name, posting_date, paid_amount, claimed_amount, advance_account
|
||||
from `tabEmployee Advance`
|
||||
where docstatus=1 and employee=%s and paid_amount > 0 and paid_amount > claimed_amount
|
||||
""", employee, as_dict=1)
|
||||
select
|
||||
name, posting_date, paid_amount, claimed_amount, advance_account
|
||||
from
|
||||
`tabEmployee Advance`
|
||||
where {0}
|
||||
""".format(condition), as_dict=1)
|
Loading…
x
Reference in New Issue
Block a user