chore: Removed payroll dependencies from Loan Management, moved to hrms app

- Salary Slip Loan dt moved to hrms, removed from erpnext app

- Repay from Salary field removed from Loan and Loan Repayment, installed on hrms app setup

- fixed references to salary slip loan fields
This commit is contained in:
Rucha Mahabal 2022-06-21 18:13:01 +05:30
parent fbc1330ab0
commit f6fbcc99a3
13 changed files with 29 additions and 200 deletions

View File

@ -104,7 +104,7 @@ class BankClearance(Document):
loan_repayment = frappe.qb.DocType("Loan Repayment")
loan_repayments = (
query = (
frappe.qb.from_(loan_repayment)
.select(
ConstantColumn("Loan Repayment").as_("payment_document"),
@ -118,13 +118,17 @@ class BankClearance(Document):
)
.where(loan_repayment.docstatus == 1)
.where(loan_repayment.clearance_date.isnull())
.where(loan_repayment.repay_from_salary == 0)
.where(loan_repayment.posting_date >= self.from_date)
.where(loan_repayment.posting_date <= self.to_date)
.where(loan_repayment.payment_account.isin([self.bank_account, self.account]))
.orderby(loan_repayment.posting_date)
.orderby(loan_repayment.name, frappe.qb.desc)
).run(as_dict=1)
)
if frappe.db.has_column("Loan Repayment", "repay_from_salary"):
query = query.where((loan_repayment.repay_from_salary == 0))
query = query.orderby(loan_repayment.posting_date).orderby(loan_repayment.name, frappe.qb.desc)
loan_repayments = query.run(as_dict=True)
pos_sales_invoices, pos_purchase_invoices = [], []
if self.include_pos_transactions:

View File

@ -467,11 +467,13 @@ def get_lr_matching_query(bank_account, amount_condition, filters):
loan_repayment.posting_date,
)
.where(loan_repayment.docstatus == 1)
.where(loan_repayment.repay_from_salary == 0)
.where(loan_repayment.clearance_date.isnull())
.where(loan_repayment.payment_account == bank_account)
)
if frappe.db.has_column("Loan Repayment", "repay_from_salary"):
query = query.where((loan_repayment.repay_from_salary == 0))
if amount_condition:
query.where(loan_repayment.amount_paid == filters.get("amount"))
else:

View File

@ -198,12 +198,10 @@ def get_loan_entries(filters):
amount_field = (loan_doc.disbursed_amount).as_("credit")
posting_date = (loan_doc.disbursement_date).as_("posting_date")
account = loan_doc.disbursement_account
salary_condition = loan_doc.docstatus == 1
else:
amount_field = (loan_doc.amount_paid).as_("debit")
posting_date = (loan_doc.posting_date).as_("posting_date")
account = loan_doc.payment_account
salary_condition = loan_doc.repay_from_salary == 0
query = (
frappe.qb.from_(loan_doc)
@ -216,12 +214,14 @@ def get_loan_entries(filters):
posting_date,
)
.where(loan_doc.docstatus == 1)
.where(salary_condition)
.where(account == filters.get("account"))
.where(posting_date <= getdate(filters.get("report_date")))
.where(ifnull(loan_doc.clearance_date, "4000-01-01") > getdate(filters.get("report_date")))
)
if doctype == "Loan Repayment" and frappe.db.has_column("Loan Repayment", "repay_from_salary"):
query = query.where((loan_doc.repay_from_salary == 0))
entries = query.run(as_dict=1)
loan_docs.extend(entries)
@ -267,13 +267,12 @@ def get_loan_amount(filters):
amount_field = Sum(loan_doc.disbursed_amount)
posting_date = (loan_doc.disbursement_date).as_("posting_date")
account = loan_doc.disbursement_account
salary_condition = loan_doc.docstatus == 1
else:
amount_field = Sum(loan_doc.amount_paid)
posting_date = (loan_doc.posting_date).as_("posting_date")
account = loan_doc.payment_account
salary_condition = loan_doc.repay_from_salary == 0
amount = (
query = (
frappe.qb.from_(loan_doc)
.select(amount_field)
.where(loan_doc.docstatus == 1)
@ -281,9 +280,12 @@ def get_loan_amount(filters):
.where(account == filters.get("account"))
.where(posting_date > getdate(filters.get("report_date")))
.where(ifnull(loan_doc.clearance_date, "4000-01-01") <= getdate(filters.get("report_date")))
.run()[0][0]
)
if doctype == "Loan Repayment" and frappe.db.has_column("Loan Repayment", "repay_from_salary"):
query = query.run((loan_doc.repay_from_salary == 0))
amount = query.run()[0][0]
total_amount += flt(amount)
return total_amount

View File

@ -16,7 +16,6 @@
"company",
"posting_date",
"status",
"repay_from_salary",
"section_break_8",
"loan_type",
"loan_amount",
@ -124,13 +123,6 @@
"options": "Sanctioned\nPartially Disbursed\nDisbursed\nLoan Closure Requested\nClosed",
"read_only": 1
},
{
"default": "0",
"depends_on": "eval:doc.applicant_type==\"Employee\"",
"fieldname": "repay_from_salary",
"fieldtype": "Check",
"label": "Repay From Salary"
},
{
"fieldname": "section_break_8",
"fieldtype": "Section Break",
@ -384,7 +376,7 @@
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2022-03-10 11:50:31.957360",
"modified": "2022-06-21 11:50:31.957360",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Loan",

View File

@ -20,15 +20,12 @@ from erpnext.loan_management.doctype.loan_security_unpledge.loan_security_unpled
class Loan(AccountsController):
def validate(self):
if self.applicant_type == "Employee" and self.repay_from_salary:
validate_employee_currency_with_company_currency(self.applicant, self.company)
self.set_loan_amount()
self.validate_loan_amount()
self.set_missing_fields()
self.validate_cost_center()
self.validate_accounts()
self.check_sanctioned_amount_limit()
self.validate_repay_from_salary()
if self.is_term_loan:
validate_repayment_method(
@ -106,10 +103,6 @@ class Loan(AccountsController):
)
)
def validate_repay_from_salary(self):
if not self.is_term_loan and self.repay_from_salary:
frappe.throw(_("Repay From Salary can be selected only for term loans"))
def make_repayment_schedule(self):
if not self.repayment_start_date:
frappe.throw(_("Repayment Start Date is mandatory for term loans"))
@ -491,25 +484,6 @@ def create_loan_security_unpledge(unpledge_map, loan, company, applicant_type, a
return unpledge_request
def validate_employee_currency_with_company_currency(applicant, company):
from erpnext.payroll.doctype.salary_structure_assignment.salary_structure_assignment import (
get_employee_currency,
)
if not applicant:
frappe.throw(_("Please select Applicant"))
if not company:
frappe.throw(_("Please select Company"))
employee_currency = get_employee_currency(applicant)
company_currency = erpnext.get_company_currency(company)
if employee_currency != company_currency:
frappe.throw(
_(
"Loan cannot be repayed from salary for Employee {0} because salary is processed in currency {1}"
).format(applicant, employee_currency)
)
@frappe.whitelist()
def get_shortfall_applicants():
loans = frappe.get_all("Loan Security Shortfall", {"status": "Pending"}, pluck="loan")

View File

@ -29,11 +29,8 @@ from erpnext.loan_management.doctype.process_loan_interest_accrual.process_loan_
from erpnext.loan_management.doctype.process_loan_security_shortfall.process_loan_security_shortfall import (
create_process_loan_security_shortfall,
)
from erpnext.payroll.doctype.salary_structure.test_salary_structure import (
make_employee,
make_salary_structure,
)
from erpnext.selling.doctype.customer.test_customer import get_customer_dict
from erpnext.setup.doctype.employee.test_employee import make_employee
class TestLoan(unittest.TestCase):
@ -93,13 +90,6 @@ class TestLoan(unittest.TestCase):
)
self.applicant1 = make_employee("robert_loan@loan.com")
make_salary_structure(
"Test Salary Structure Loan",
"Monthly",
employee=self.applicant1,
currency="INR",
company="_Test Company",
)
if not frappe.db.exists("Customer", "_Test Loan Customer"):
frappe.get_doc(get_customer_dict("_Test Loan Customer")).insert(ignore_permissions=True)

View File

@ -6,10 +6,7 @@ import unittest
import frappe
from erpnext.loan_management.doctype.loan.test_loan import create_loan_accounts, create_loan_type
from erpnext.payroll.doctype.salary_structure.test_salary_structure import (
make_employee,
make_salary_structure,
)
from erpnext.setup.doctype.employee.employee import make_employee
class TestLoanApplication(unittest.TestCase):
@ -32,9 +29,6 @@ class TestLoanApplication(unittest.TestCase):
18,
)
self.applicant = make_employee("kate_loan@loan.com", "_Test Company")
make_salary_structure(
"Test Salary Structure Loan", "Monthly", employee=self.applicant, currency="INR"
)
self.create_loan_application()
def create_loan_application(self):

View File

@ -15,9 +15,7 @@
"posting_date",
"clearance_date",
"rate_of_interest",
"payroll_payable_account",
"is_term_loan",
"repay_from_salary",
"payment_details_section",
"due_date",
"pending_principal_amount",
@ -252,21 +250,6 @@
"options": "Company:company:default_currency",
"read_only": 1
},
{
"depends_on": "eval:doc.repay_from_salary",
"fieldname": "payroll_payable_account",
"fieldtype": "Link",
"label": "Payroll Payable Account",
"mandatory_depends_on": "eval:doc.repay_from_salary",
"options": "Account"
},
{
"default": "0",
"fetch_from": "against_loan.repay_from_salary",
"fieldname": "repay_from_salary",
"fieldtype": "Check",
"label": "Repay From Salary"
},
{
"fieldname": "clearance_date",
"fieldtype": "Date",
@ -311,7 +294,7 @@
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2022-02-18 19:10:07.742298",
"modified": "2022-06-21 10:10:07.742298",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Loan Repayment",

View File

@ -396,7 +396,7 @@ class LoanRepayment(AccountsController):
else:
remarks = _("Repayment against Loan:") + " " + self.against_loan
if self.repay_from_salary:
if hasattr(self, "repay_from_salary") and self.repay_from_salary:
payment_account = self.payroll_payable_account
else:
payment_account = self.payment_account
@ -674,7 +674,9 @@ def get_amounts(amounts, against_loan, posting_date):
if (
no_of_late_days > 0
and (not against_loan_doc.repay_from_salary)
and (
not (hasattr(against_loan_doc, "repay_from_salary") and against_loan_doc.repay_from_salary)
)
and entry.accrual_type == "Regular"
):
penalty_amount += (

View File

@ -1,101 +0,0 @@
{
"actions": [],
"creation": "2019-08-29 18:11:36.829526",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"loan",
"loan_type",
"loan_account",
"interest_income_account",
"column_break_4",
"principal_amount",
"interest_amount",
"total_payment",
"loan_repayment_entry"
],
"fields": [
{
"fieldname": "loan",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Loan",
"options": "Loan",
"read_only": 1,
"reqd": 1
},
{
"fieldname": "loan_account",
"fieldtype": "Link",
"label": "Loan Account",
"options": "Account",
"read_only": 1
},
{
"fieldname": "interest_income_account",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Interest Income Account",
"options": "Account",
"read_only": 1
},
{
"fieldname": "column_break_4",
"fieldtype": "Column Break"
},
{
"fieldname": "principal_amount",
"fieldtype": "Currency",
"in_list_view": 1,
"label": "Principal Amount",
"options": "Company:company:default_currency",
"read_only": 1
},
{
"fieldname": "interest_amount",
"fieldtype": "Currency",
"in_list_view": 1,
"label": "Interest Amount",
"options": "Company:company:default_currency",
"read_only": 1
},
{
"fieldname": "total_payment",
"fieldtype": "Currency",
"in_list_view": 1,
"label": "Total Payment",
"options": "Company:company:default_currency"
},
{
"fieldname": "loan_repayment_entry",
"fieldtype": "Link",
"label": "Loan Repayment Entry",
"no_copy": 1,
"options": "Loan Repayment",
"read_only": 1
},
{
"fetch_from": "loan.loan_type",
"fieldname": "loan_type",
"fieldtype": "Link",
"label": "Loan Type",
"options": "Loan Type",
"read_only": 1
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2022-01-31 14:50:14.823213",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Salary Slip Loan",
"owner": "Administrator",
"permissions": [],
"quick_entry": 1,
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"track_changes": 1
}

View File

@ -1,10 +0,0 @@
# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
# import frappe
from frappe.model.document import Document
class SalarySlipLoan(Document):
pass

View File

@ -36,9 +36,6 @@ def before_tests():
}
)
frappe.db.sql("delete from `tabLeave Allocation`")
frappe.db.sql("delete from `tabLeave Application`")
frappe.db.sql("delete from `tabSalary Slip`")
frappe.db.sql("delete from `tabItem Price`")
_enable_all_roles_for_admin()