Skip to content

Commit

Permalink
Merge pull request #1667 from frappe/version-14-hotfix
Browse files Browse the repository at this point in the history
chore: release v14
  • Loading branch information
ruchamahabal committed Apr 17, 2024
2 parents 73cd9d2 + 749ce70 commit cac9fa5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 30 deletions.
20 changes: 1 addition & 19 deletions hrms/hr/doctype/employee_advance/employee_advance.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,25 +151,7 @@ frappe.ui.form.on('Employee Advance', {
},

employee: function(frm) {
if (frm.doc.employee) {
frappe.run_serially([
() => frm.trigger('get_employee_currency'),
() => frm.trigger('get_pending_amount')
]);
}
},

get_pending_amount: function(frm) {
frappe.call({
method: "hrms.hr.doctype.employee_advance.employee_advance.get_pending_amount",
args: {
"employee": frm.doc.employee,
"posting_date": frm.doc.posting_date
},
callback: function(r) {
frm.set_value("pending_amount", r.message);
}
});
if (frm.doc.employee) frm.trigger('get_employee_currency')
},

get_employee_currency: function(frm) {
Expand Down
9 changes: 7 additions & 2 deletions hrms/hr/doctype/employee_advance/employee_advance.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"fieldtype": "Column Break"
},
{
"description": "Amount of expense",
"fieldname": "advance_amount",
"fieldtype": "Currency",
"in_list_view": 1,
Expand All @@ -97,6 +98,7 @@
"reqd": 1
},
{
"description": "Amount that has been paid against this advance",
"fieldname": "paid_amount",
"fieldtype": "Currency",
"label": "Paid Amount",
Expand All @@ -105,6 +107,7 @@
"read_only": 1
},
{
"description": "Amount claimed via Expense Claim",
"fieldname": "claimed_amount",
"fieldtype": "Currency",
"label": "Claimed Amount",
Expand Down Expand Up @@ -160,6 +163,7 @@
},
{
"allow_on_submit": 1,
"description": "Amount returned by the employee after the advance is paid",
"fieldname": "return_amount",
"fieldtype": "Currency",
"label": "Returned Amount",
Expand All @@ -175,6 +179,7 @@
},
{
"depends_on": "eval:cur_frm.doc.employee",
"description": "Pending (unpaid) amount from previous advances",
"fieldname": "pending_amount",
"fieldtype": "Currency",
"label": "Pending Amount",
Expand Down Expand Up @@ -202,7 +207,7 @@
],
"is_submittable": 1,
"links": [],
"modified": "2024-02-26 14:42:01.853329",
"modified": "2024-04-12 13:53:55.442187",
"modified_by": "Administrator",
"module": "HR",
"name": "Employee Advance",
Expand Down Expand Up @@ -271,4 +276,4 @@
],
"title_field": "employee_name",
"track_changes": 1
}
}
22 changes: 13 additions & 9 deletions hrms/hr/doctype/employee_advance/employee_advance.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def onload(self):
def validate(self):
validate_active_employee(self.employee)
self.set_status()
self.set_pending_amount()

def on_cancel(self):
self.ignore_linked_doctypes = "GL Entry"
Expand Down Expand Up @@ -143,15 +144,18 @@ def update_claimed_amount(self):
self.reload()
self.set_status(update=True)


@frappe.whitelist()
def get_pending_amount(employee, posting_date):
employee_due_amount = frappe.get_all(
"Employee Advance",
filters={"employee": employee, "docstatus": 1, "posting_date": ("<=", posting_date)},
fields=["advance_amount", "paid_amount"],
)
return sum([(emp.advance_amount - emp.paid_amount) for emp in employee_due_amount])
def set_pending_amount(self):
Advance = frappe.qb.DocType("Employee Advance")
self.pending_amount = (
frappe.qb.from_(Advance)
.select(Sum(Advance.advance_amount - Advance.paid_amount))
.where(
(Advance.employee == self.employee)
& (Advance.docstatus == 1)
& (Advance.posting_date <= self.posting_date)
& (Advance.status == "Unpaid")
)
).run()[0][0] or 0.0


@frappe.whitelist()
Expand Down
15 changes: 15 additions & 0 deletions hrms/hr/doctype/employee_advance/test_employee_advance.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,21 @@ def test_precision(self):
self.assertEqual(advance.return_amount, 380.66)
self.assertEqual(advance.status, "Partly Claimed and Returned")

def test_pending_amount(self):
employee_name = make_employee("[email protected]")

advance1 = make_employee_advance(employee_name)
make_payment_entry(advance1, 500)

advance2 = make_employee_advance(employee_name)
# 1000 - 500
self.assertEqual(advance2.pending_amount, 500)
make_payment_entry(advance2, 700)

advance3 = make_employee_advance(employee_name)
# (1000 - 500) + (1000 - 700)
self.assertEqual(advance3.pending_amount, 800)


def make_journal_entry_for_advance(advance):
journal_entry = frappe.get_doc(make_bank_entry("Employee Advance", advance.name))
Expand Down

0 comments on commit cac9fa5

Please sign in to comment.