mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-25 07:54:46 +00:00
* allow to make expense claim from employee advance * make expense claim only if claimed amount < paid_amount * expense claim made from employee advance is paid
This commit is contained in:
@@ -32,6 +32,19 @@ frappe.ui.form.on('Employee Advance', {
|
|||||||
frm.add_custom_button(__('Payment'),
|
frm.add_custom_button(__('Payment'),
|
||||||
function() { frm.events.make_payment_entry(frm); }, __("Make"));
|
function() { frm.events.make_payment_entry(frm); }, __("Make"));
|
||||||
}
|
}
|
||||||
|
else if (
|
||||||
|
frm.doc.docstatus === 1
|
||||||
|
&& flt(frm.doc.claimed_amount) < flt(frm.doc.paid_amount)
|
||||||
|
&& frappe.model.can_create("Expense Claim")
|
||||||
|
) {
|
||||||
|
frm.add_custom_button(
|
||||||
|
__("Expense Claim"),
|
||||||
|
function() {
|
||||||
|
frm.events.make_expense_claim(frm);
|
||||||
|
},
|
||||||
|
__("Make")
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
make_payment_entry: function(frm) {
|
make_payment_entry: function(frm) {
|
||||||
@@ -51,4 +64,22 @@ frappe.ui.form.on('Employee Advance', {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
make_expense_claim: function(frm) {
|
||||||
|
return frappe.call({
|
||||||
|
method: "erpnext.hr.doctype.expense_claim.expense_claim.get_expense_claim",
|
||||||
|
args: {
|
||||||
|
"employee_name": frm.doc.employee,
|
||||||
|
"company": frm.doc.company,
|
||||||
|
"employee_advance_name": frm.doc.name,
|
||||||
|
"posting_date": frm.doc.posting_date,
|
||||||
|
"paid_amount": frm.doc.paid_amount,
|
||||||
|
"claimed_amount": frm.doc.claimed_amount
|
||||||
|
},
|
||||||
|
callback: function(r) {
|
||||||
|
const doclist = frappe.model.sync(r.message);
|
||||||
|
frappe.set_route("Form", doclist[0].doctype, doclist[0].name);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -298,3 +298,29 @@ def get_advances(employee, advance_id=None):
|
|||||||
`tabEmployee Advance`
|
`tabEmployee Advance`
|
||||||
where {0}
|
where {0}
|
||||||
""".format(condition), as_dict=1)
|
""".format(condition), as_dict=1)
|
||||||
|
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def get_expense_claim(
|
||||||
|
employee_name, company, employee_advance_name, posting_date, paid_amount, claimed_amount):
|
||||||
|
default_payable_account = frappe.db.get_value("Company", company, "default_payable_account")
|
||||||
|
default_cost_center = frappe.db.get_value('Company', company, 'cost_center')
|
||||||
|
|
||||||
|
expense_claim = frappe.new_doc('Expense Claim')
|
||||||
|
expense_claim.company = company
|
||||||
|
expense_claim.employee = employee_name
|
||||||
|
expense_claim.payable_account = default_payable_account
|
||||||
|
expense_claim.cost_center = default_cost_center
|
||||||
|
expense_claim.is_paid = 1 if flt(paid_amount) else 0
|
||||||
|
expense_claim.append(
|
||||||
|
'advances',
|
||||||
|
{
|
||||||
|
'employee_advance': employee_advance_name,
|
||||||
|
'posting_date': posting_date,
|
||||||
|
'advance_paid': flt(paid_amount),
|
||||||
|
'unclaimed_amount': flt(paid_amount) - flt(claimed_amount),
|
||||||
|
'allocated_amount': flt(paid_amount) - flt(claimed_amount)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
return expense_claim
|
||||||
|
|||||||
Reference in New Issue
Block a user