From f6fbcc99a38032dc34e6bcf346bb44e15080c2d9 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Tue, 21 Jun 2022 18:13:01 +0530 Subject: [PATCH] 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 --- .../doctype/bank_clearance/bank_clearance.py | 14 ++- .../bank_reconciliation_tool.py | 4 +- .../bank_reconciliation_statement.py | 16 +-- .../loan_management/doctype/loan/loan.json | 10 +- erpnext/loan_management/doctype/loan/loan.py | 26 ----- .../loan_management/doctype/loan/test_loan.py | 12 +-- .../loan_application/test_loan_application.py | 8 +- .../loan_repayment/loan_repayment.json | 19 +--- .../doctype/loan_repayment/loan_repayment.py | 6 +- .../doctype/salary_slip_loan/__init__.py | 0 .../salary_slip_loan/salary_slip_loan.json | 101 ------------------ .../salary_slip_loan/salary_slip_loan.py | 10 -- erpnext/setup/utils.py | 3 - 13 files changed, 29 insertions(+), 200 deletions(-) delete mode 100644 erpnext/loan_management/doctype/salary_slip_loan/__init__.py delete mode 100644 erpnext/loan_management/doctype/salary_slip_loan/salary_slip_loan.json delete mode 100644 erpnext/loan_management/doctype/salary_slip_loan/salary_slip_loan.py diff --git a/erpnext/accounts/doctype/bank_clearance/bank_clearance.py b/erpnext/accounts/doctype/bank_clearance/bank_clearance.py index 98ba399a35d..1a572d9823e 100644 --- a/erpnext/accounts/doctype/bank_clearance/bank_clearance.py +++ b/erpnext/accounts/doctype/bank_clearance/bank_clearance.py @@ -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: diff --git a/erpnext/accounts/doctype/bank_reconciliation_tool/bank_reconciliation_tool.py b/erpnext/accounts/doctype/bank_reconciliation_tool/bank_reconciliation_tool.py index 0efe086d94e..4cc6bf7fe5f 100644 --- a/erpnext/accounts/doctype/bank_reconciliation_tool/bank_reconciliation_tool.py +++ b/erpnext/accounts/doctype/bank_reconciliation_tool/bank_reconciliation_tool.py @@ -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: diff --git a/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.py b/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.py index c41d0d10ffe..c26eddeac6a 100644 --- a/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.py +++ b/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.py @@ -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 diff --git a/erpnext/loan_management/doctype/loan/loan.json b/erpnext/loan_management/doctype/loan/loan.json index ef78a640aa0..ffcbbfe5e64 100644 --- a/erpnext/loan_management/doctype/loan/loan.json +++ b/erpnext/loan_management/doctype/loan/loan.json @@ -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", diff --git a/erpnext/loan_management/doctype/loan/loan.py b/erpnext/loan_management/doctype/loan/loan.py index ac8b3629d97..a79566857c8 100644 --- a/erpnext/loan_management/doctype/loan/loan.py +++ b/erpnext/loan_management/doctype/loan/loan.py @@ -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") diff --git a/erpnext/loan_management/doctype/loan/test_loan.py b/erpnext/loan_management/doctype/loan/test_loan.py index e2b0870c322..da05c8e90c4 100644 --- a/erpnext/loan_management/doctype/loan/test_loan.py +++ b/erpnext/loan_management/doctype/loan/test_loan.py @@ -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) diff --git a/erpnext/loan_management/doctype/loan_application/test_loan_application.py b/erpnext/loan_management/doctype/loan_application/test_loan_application.py index 2a4bb882a8e..7a444893988 100644 --- a/erpnext/loan_management/doctype/loan_application/test_loan_application.py +++ b/erpnext/loan_management/doctype/loan_application/test_loan_application.py @@ -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): diff --git a/erpnext/loan_management/doctype/loan_repayment/loan_repayment.json b/erpnext/loan_management/doctype/loan_repayment/loan_repayment.json index 480e010b49a..76dc8b462e3 100644 --- a/erpnext/loan_management/doctype/loan_repayment/loan_repayment.json +++ b/erpnext/loan_management/doctype/loan_repayment/loan_repayment.json @@ -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", diff --git a/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py b/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py index dcbdf8a81e6..262545bb0a1 100644 --- a/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py +++ b/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py @@ -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 += ( diff --git a/erpnext/loan_management/doctype/salary_slip_loan/__init__.py b/erpnext/loan_management/doctype/salary_slip_loan/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/erpnext/loan_management/doctype/salary_slip_loan/salary_slip_loan.json b/erpnext/loan_management/doctype/salary_slip_loan/salary_slip_loan.json deleted file mode 100644 index b7b20d945d6..00000000000 --- a/erpnext/loan_management/doctype/salary_slip_loan/salary_slip_loan.json +++ /dev/null @@ -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 -} \ No newline at end of file diff --git a/erpnext/loan_management/doctype/salary_slip_loan/salary_slip_loan.py b/erpnext/loan_management/doctype/salary_slip_loan/salary_slip_loan.py deleted file mode 100644 index 91267b80ba1..00000000000 --- a/erpnext/loan_management/doctype/salary_slip_loan/salary_slip_loan.py +++ /dev/null @@ -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 diff --git a/erpnext/setup/utils.py b/erpnext/setup/utils.py index b3ff439d748..54bd8c355d6 100644 --- a/erpnext/setup/utils.py +++ b/erpnext/setup/utils.py @@ -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()