Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions hrms/hr/doctype/employee_advance/employee_advance.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,7 @@ frappe.ui.form.on("Employee Advance", {
frm.doc.docstatus === 1 &&
flt(frm.doc.paid_amount) < flt(frm.doc.advance_amount) &&
frappe.model.can_create("Payment Entry") &&
!(
(frm.doc.repay_unclaimed_amount_from_salary == 1 && frm.doc.paid_amount) ||
(frm.doc.__onload &&
frm.doc.__onload.make_payment_via_journal_entry == 1 &&
frm.doc.paid_amount)
)
!(frm.doc.repay_unclaimed_amount_from_salary == 1 && frm.doc.paid_amount)
) {
frm.add_custom_button(
__("Payment"),
Expand Down Expand Up @@ -105,12 +100,8 @@ frappe.ui.form.on("Employee Advance", {
},

make_payment_entry: function (frm) {
let method = "hrms.overrides.employee_payment_entry.get_payment_entry_for_employee";
if (frm.doc.__onload && frm.doc.__onload.make_payment_via_journal_entry) {
method = "hrms.hr.doctype.employee_advance.employee_advance.make_bank_entry";
}
return frappe.call({
method: method,
method: "hrms.overrides.employee_payment_entry.get_payment_entry_for_employee",
args: {
dt: frm.doc.doctype,
dn: frm.doc.name,
Expand All @@ -127,7 +118,6 @@ frappe.ui.form.on("Employee Advance", {
method: "hrms.hr.doctype.expense_claim.expense_claim.get_expense_claim",
args: {
employee_advance: frm.doc.name,
payment_via_journal_entry: frm.doc.__onload.make_payment_via_journal_entry,
},
callback: function (r) {
const doclist = frappe.model.sync(r.message);
Expand Down
46 changes: 0 additions & 46 deletions hrms/hr/doctype/employee_advance/employee_advance.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ class EmployeeAdvance(Document):
]
# end: auto-generated types

def onload(self):
self.get("__onload").make_payment_via_journal_entry = frappe.db.get_single_value(
"Accounts Settings", "make_payment_via_journal_entry"
)

def validate(self):
validate_active_employee(self.employee)
self.validate_advance_account_currency()
Expand Down Expand Up @@ -286,47 +281,6 @@ def check_linked_payment_entry(self):
update_accounting_ledgers_after_reference_removal(self.doctype, self.name)


@frappe.whitelist()
def make_bank_entry(dt: str, dn: str) -> dict:
doc = frappe.get_doc(dt, dn)
payment_account = get_same_currency_bank_cash_account(doc.company, doc.currency, doc.mode_of_payment)

je = frappe.new_doc("Journal Entry")
je.posting_date = nowdate()
je.voucher_type = "Bank Entry"
je.company = doc.company
je.remark = "Payment against Employee Advance: " + dn + "\n" + doc.purpose
je.multi_currency = 1 if doc.currency != erpnext.get_company_currency(doc.company) else 0

je.append(
"accounts",
{
"account": doc.advance_account,
"account_currency": doc.currency,
"debit_in_account_currency": flt(doc.advance_amount),
"reference_type": "Employee Advance",
"reference_name": doc.name,
"party_type": "Employee",
"cost_center": erpnext.get_default_cost_center(doc.company),
"party": doc.employee,
"is_advance": "Yes",
},
)

je.append(
"accounts",
{
"account": payment_account.account or payment_account.name,
"cost_center": erpnext.get_default_cost_center(doc.company),
"credit_in_account_currency": flt(doc.advance_amount),
"account_currency": doc.currency,
"account_type": payment_account.account_type,
},
)

return je.as_dict()


@frappe.whitelist()
def create_return_through_additional_salary(doc: str | dict | Document) -> Document:
import json
Expand Down
75 changes: 49 additions & 26 deletions hrms/hr/doctype/employee_advance/test_employee_advance.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from hrms.hr.doctype.employee_advance.employee_advance import (
EmployeeAdvanceOverPayment,
create_return_through_additional_salary,
make_bank_entry,
get_same_currency_bank_cash_account,
make_return_entry,
)
from hrms.hr.doctype.expense_claim.expense_claim import get_advances
Expand All @@ -35,7 +35,7 @@ def test_paid_amount_and_status(self):
employee_name = make_employee("_T@employee.advance", "_Test Company")
advance = make_employee_advance(employee_name)

journal_entry = make_journal_entry_for_advance(advance)
journal_entry = manual_journal_entry_for_advance(advance)
journal_entry.submit()

advance.reload()
Expand All @@ -44,22 +44,19 @@ def test_paid_amount_and_status(self):
self.assertEqual(advance.status, "Paid")

# try making over payment
journal_entry1 = make_journal_entry_for_advance(advance)
journal_entry1 = manual_journal_entry_for_advance(advance)
self.assertRaises(EmployeeAdvanceOverPayment, journal_entry1.submit)

def test_paid_amount_on_pe_cancellation(self):
employee_name = make_employee("_T@employee.advance", "_Test Company")
advance = make_employee_advance(employee_name)

journal_entry = make_journal_entry_for_advance(advance)
journal_entry.submit()

payment_entry = make_payment_entry(advance)
advance.reload()

self.assertEqual(advance.paid_amount, 1000)
self.assertEqual(advance.status, "Paid")

journal_entry.cancel()
payment_entry.cancel()
advance.reload()

self.assertEqual(advance.paid_amount, 0)
Expand All @@ -77,8 +74,7 @@ def test_claimed_status(self):
)

advance = make_employee_advance(claim.employee)
journal_entry = make_journal_entry_for_advance(advance)
journal_entry.submit()
make_payment_entry(advance)

claim = get_advances_for_claim(claim, advance.name)
claim.save()
Expand Down Expand Up @@ -107,8 +103,7 @@ def test_partly_claimed_and_returned_status(self):
)

advance = make_employee_advance(claim.employee)
journal_entry = make_journal_entry_for_advance(advance)
journal_entry.submit()
make_payment_entry(advance)

# PARTLY CLAIMED AND RETURNED status check
# 500 Claimed, 500 Returned
Expand All @@ -117,8 +112,7 @@ def test_partly_claimed_and_returned_status(self):
)

advance = make_employee_advance(claim.employee)
journal_entry = make_journal_entry_for_advance(advance)
journal_entry.submit()
make_payment_entry(advance)

claim = get_advances_for_claim(claim, advance.name, amount=500)
claim.save()
Expand Down Expand Up @@ -165,8 +159,7 @@ def test_partly_claimed_and_returned_status(self):
def test_repay_unclaimed_amount_from_salary(self):
employee_name = make_employee("_T@employee.advance", "_Test Company")
advance = make_employee_advance(employee_name, {"repay_unclaimed_amount_from_salary": 1})
journal_entry = make_journal_entry_for_advance(advance)
journal_entry.submit()
make_payment_entry(advance)

args = {"type": "Deduction"}
create_salary_component("Advance Salary - Deduction", **args)
Expand Down Expand Up @@ -229,8 +222,7 @@ def test_payment_entry_against_advance(self):
def test_precision(self):
employee_name = make_employee("_T@employee.advance", "_Test Company")
advance = make_employee_advance(employee_name)
journal_entry = make_journal_entry_for_advance(advance)
journal_entry.submit()
make_payment_entry(advance)

# PARTLY CLAIMED AND RETURNED
payable_account = get_payable_account("_Test Company")
Expand Down Expand Up @@ -375,18 +367,49 @@ def test_status_on_discard(self):
self.assertEqual(advance.status, "Cancelled")


def make_journal_entry_for_advance(advance):
frappe.db.set_single_value("Accounts Settings", "make_payment_via_journal_entry", True)
journal_entry = frappe.get_doc(make_bank_entry("Employee Advance", advance.name))
journal_entry.cheque_no = "123123"
journal_entry.cheque_date = nowdate()
journal_entry.save()
def manual_journal_entry_for_advance(advance) -> dict:
doc = frappe.get_doc("Employee Advance", advance.name)
payment_account = get_same_currency_bank_cash_account(doc.company, doc.currency, doc.mode_of_payment)

je = frappe.new_doc("Journal Entry")
je.posting_date = nowdate()
je.voucher_type = "Bank Entry"
je.company = doc.company
je.remark = "Payment against Employee Advance: " + advance.name + "\n" + doc.purpose
je.multi_currency = 1 if doc.currency != erpnext.get_company_currency(doc.company) else 0

je.append(
"accounts",
{
"account": doc.advance_account,
"account_currency": doc.currency,
"debit_in_account_currency": flt(doc.advance_amount),
"reference_type": "Employee Advance",
"reference_name": doc.name,
"party_type": "Employee",
"cost_center": erpnext.get_default_cost_center(doc.company),
"party": doc.employee,
"is_advance": "Yes",
},
)

return journal_entry
je.append(
"accounts",
{
"account": payment_account.account or payment_account.name,
"cost_center": erpnext.get_default_cost_center(doc.company),
"credit_in_account_currency": flt(doc.advance_amount),
"account_currency": doc.currency,
"account_type": payment_account.account_type,
},
)
je.cheque_no = "123123"
je.cheque_date = nowdate()
je.save()
return je


def make_payment_entry(advance, amount=None):
frappe.db.set_single_value("Accounts Settings", "make_payment_via_journal_entry", False)
from hrms.overrides.employee_payment_entry import get_payment_entry_for_employee

payment_entry = get_payment_entry_for_employee(advance.doctype, advance.name)
Expand Down
25 changes: 6 additions & 19 deletions hrms/hr/doctype/expense_claim/expense_claim.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,16 +270,7 @@ frappe.ui.form.on("Expense Claim", {
}

if (!frm.doc.__islocal && frm.doc.docstatus === 1) {
let entry_doctype, entry_reference_doctype, entry_reference_name;
if (frm.doc.__onload.make_payment_via_journal_entry) {
entry_doctype = "Journal Entry";
entry_reference_doctype = "Journal Entry Account.reference_type";
entry_reference_name = "Journal Entry.reference_name";
} else {
entry_doctype = "Payment Entry";
entry_reference_doctype = "Payment Entry Reference.reference_doctype";
entry_reference_name = "Payment Entry Reference.reference_name";
}
const entry_doctype = "Payment Entry";

if (
cint(frm.doc.total_amount_reimbursed) > 0 &&
Expand Down Expand Up @@ -366,12 +357,8 @@ frappe.ui.form.on("Expense Claim", {
});
},
make_payment_entry: function (frm) {
let method = "hrms.overrides.employee_payment_entry.get_payment_entry_for_employee";
if (frm.doc.__onload && frm.doc.__onload.make_payment_via_journal_entry) {
method = "hrms.hr.doctype.expense_claim.expense_claim.make_bank_entry";
}
return frappe.call({
method: method,
method: "hrms.overrides.employee_payment_entry.get_payment_entry_for_employee",
args: {
dt: frm.doc.doctype,
dn: frm.doc.name,
Expand Down Expand Up @@ -486,8 +473,8 @@ frappe.ui.form.on("Expense Claim", {
row.return_amount = flt(d.return_amount);
row.allocated_amount = d.allocated_amount;
row.exchange_rate = d.exchange_rate;
row.payment_entry = d.payment_entry;
row.payment_entry_reference = d.payment_entry_reference;
row.reference_type = d.reference_type;
row.reference_name = d.reference_name;
});
refresh_field("advances");
}
Expand Down Expand Up @@ -589,8 +576,8 @@ frappe.ui.form.on("Expense Claim Advance", {
child.return_amount = flt(r.message[0].return_amount);
child.allocated_amount = flt(r.message[0].allocated_amount);
child.exchange_rate = r.message[0].exchange_rate;
child.payment_entry = r.message[0].payment_entry;
child.payment_entry_reference = r.message[0].payment_entry_reference;
child.reference_type = r.message[0].reference_type;
child.reference_name = r.message[0].reference_name;
set_in_company_currency(
frm,
child,
Expand Down
Loading
Loading