fix indent and imports
diff --git a/erpnext/loan_management/doctype/loan_balance_adjustment/loan_balance_adjustment.py b/erpnext/loan_management/doctype/loan_balance_adjustment/loan_balance_adjustment.py
index 92e9b6a..e714545 100644
--- a/erpnext/loan_management/doctype/loan_balance_adjustment/loan_balance_adjustment.py
+++ b/erpnext/loan_management/doctype/loan_balance_adjustment/loan_balance_adjustment.py
@@ -2,14 +2,15 @@
# For license information, please see license.txt
import frappe
-import erpnext
from frappe import _
-from frappe.utils import nowdate, add_days
+from frappe.utils import add_days, nowdate
+
+import erpnext
+from erpnext.accounts.general_ledger import make_gl_entries
from erpnext.controllers.accounts_controller import AccountsController
from erpnext.loan_management.doctype.process_loan_interest_accrual.process_loan_interest_accrual import (
- process_loan_interest_accrual_for_demand_loans,
+ process_loan_interest_accrual_for_demand_loans,
)
-from erpnext.accounts.general_ledger import make_gl_entries
class LoanBalanceAdjustment(AccountsController):
@@ -19,9 +20,9 @@
def validate(self):
if self.amount == 0:
- frappe.throw(_("Amount cannot be zero"))
+ frappe.throw(_("Amount cannot be zero"))
if self.amount < 0:
- frappe.throw(_("Amount cannot be negative"))
+ frappe.throw(_("Amount cannot be negative"))
self.set_missing_values()
def on_submit(self):
@@ -35,113 +36,106 @@
def set_missing_values(self):
if not self.posting_date:
- self.posting_date = nowdate()
+ self.posting_date = nowdate()
if not self.cost_center:
- self.cost_center = erpnext.get_default_cost_center(self.company)
+ self.cost_center = erpnext.get_default_cost_center(self.company)
def set_status_and_amounts(self, cancel=0):
loan_details = frappe.get_all(
- "Loan",
- fields=[
- "loan_amount",
- "adjustment_amount",
- "total_payment",
- "total_principal_paid",
- "total_interest_payable",
- "status",
- "is_term_loan",
- "is_secured_loan",
- ],
- filters={"name": self.loan},
+ "Loan",
+ fields=[
+ "loan_amount",
+ "adjustment_amount",
+ "total_payment",
+ "total_principal_paid",
+ "total_interest_payable",
+ "status",
+ "is_term_loan",
+ "is_secured_loan",
+ ],
+ filters={"name": self.loan},
)[0]
if cancel:
- adjustment_amount = self.get_values_on_cancel(loan_details)
+ adjustment_amount = self.get_values_on_cancel(loan_details)
else:
- adjustment_amount = self.get_values_on_submit(loan_details)
+ adjustment_amount = self.get_values_on_submit(loan_details)
if self.adjustment_type == "Credit Adjustment":
- adj_field = "credit_adjustment_amount"
+ adj_field = "credit_adjustment_amount"
elif self.adjustment_type == "Debit Adjustment":
- adj_field = "debit_adjustment_amount"
+ adj_field = "debit_adjustment_amount"
- frappe.db.set_value(
- "Loan", self.loan, {adj_field: adjustment_amount}
- )
+ frappe.db.set_value("Loan", self.loan, {adj_field: adjustment_amount})
def get_values_on_cancel(self, loan_details):
if self.adjustment_type == "Credit Adjustment":
- adjustment_amount = loan_details.credit_adjustment_amount - self.amount
+ adjustment_amount = loan_details.credit_adjustment_amount - self.amount
elif self.adjustment_type == "Debit Adjustment":
- adjustment_amount = loan_details.debit_adjustment_amount - self.amount
+ adjustment_amount = loan_details.debit_adjustment_amount - self.amount
return adjustment_amount
def get_values_on_submit(self, loan_details):
if self.adjustment_type == "Credit Adjustment":
- adjustment_amount = loan_details.credit_adjustment_amount + self.amount
+ adjustment_amount = loan_details.credit_adjustment_amount + self.amount
elif self.adjustment_type == "Debit Adjustment":
- adjustment_amount = loan_details.debit_adjustment_amount + self.amount
+ adjustment_amount = loan_details.debit_adjustment_amount + self.amount
- if (
- loan_details.status in ("Disbursed", "Partially Disbursed")
- and not loan_details.is_term_loan
- ):
- process_loan_interest_accrual_for_demand_loans(
- posting_date=add_days(self.posting_date, -1),
- loan=self.loan,
- accrual_type=self.adjustment_type,
- )
+ if loan_details.status in ("Disbursed", "Partially Disbursed") and not loan_details.is_term_loan:
+ process_loan_interest_accrual_for_demand_loans(
+ posting_date=add_days(self.posting_date, -1),
+ loan=self.loan,
+ accrual_type=self.adjustment_type,
+ )
return adjustment_amount
def make_gl_entries(self, cancel=0, adv_adj=0):
gle_map = []
loan_account = frappe.db.get_value("Loan", self.loan, "loan_account")
- remarks = "{} against loan {}".format(
- self.adjustment_type.capitalize(), self.loan
- )
+ remarks = "{} against loan {}".format(self.adjustment_type.capitalize(), self.loan)
if self.reference_number:
remarks += "with reference no. {}".format(self.reference_number)
loan_entry = {
- "account": loan_account,
- "against": self.adjustment_account,
- "against_voucher_type": "Loan",
- "against_voucher": self.loan,
- "remarks": _(remarks),
- "cost_center": self.cost_center,
- "party_type": self.applicant_type,
- "party": self.applicant,
- "posting_date": self.posting_date,
+ "account": loan_account,
+ "against": self.adjustment_account,
+ "against_voucher_type": "Loan",
+ "against_voucher": self.loan,
+ "remarks": _(remarks),
+ "cost_center": self.cost_center,
+ "party_type": self.applicant_type,
+ "party": self.applicant,
+ "posting_date": self.posting_date,
}
company_entry = {
- "account": self.adjustment_account,
- "against": loan_account,
- "against_voucher_type": "Loan",
- "against_voucher": self.loan,
- "remarks": _(remarks),
- "cost_center": self.cost_center,
- "posting_date": self.posting_date,
+ "account": self.adjustment_account,
+ "against": loan_account,
+ "against_voucher_type": "Loan",
+ "against_voucher": self.loan,
+ "remarks": _(remarks),
+ "cost_center": self.cost_center,
+ "posting_date": self.posting_date,
}
if self.adjustment_type == "Credit Adjustment":
- loan_entry["credit"] = self.amount
- loan_entry["credit_in_account_currency"] = self.amount
+ loan_entry["credit"] = self.amount
+ loan_entry["credit_in_account_currency"] = self.amount
- company_entry["debit"] = self.amount
- company_entry["debit_in_account_currency"] = self.amount
+ company_entry["debit"] = self.amount
+ company_entry["debit_in_account_currency"] = self.amount
elif self.adjustment_type == "Debit Adjustment":
- loan_entry["debit"] = self.amount
- loan_entry["debit_in_account_currency"] = self.amount
+ loan_entry["debit"] = self.amount
+ loan_entry["debit_in_account_currency"] = self.amount
- company_entry["credit"] = self.amount
- company_entry["credit_in_account_currency"] = self.amount
+ company_entry["credit"] = self.amount
+ company_entry["credit_in_account_currency"] = self.amount
gle_map.append(self.get_gl_dict(loan_entry))
gle_map.append(self.get_gl_dict(company_entry))
if gle_map:
- make_gl_entries(gle_map, cancel=cancel, adv_adj=adv_adj, merge_entries=False)
+ make_gl_entries(gle_map, cancel=cancel, adv_adj=adv_adj, merge_entries=False)
diff --git a/erpnext/loan_management/doctype/loan_refund/loan_refund.py b/erpnext/loan_management/doctype/loan_refund/loan_refund.py
index 2a7f478..f63cb27 100644
--- a/erpnext/loan_management/doctype/loan_refund/loan_refund.py
+++ b/erpnext/loan_management/doctype/loan_refund/loan_refund.py
@@ -1,13 +1,20 @@
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
-# import frappe
+import frappe
+from frappe import _
from frappe.model.document import Document
+from frappe.utils import cint, flt, getdate
+
+import erpnext
+from erpnext.accounts.general_ledger import make_gl_entries
+
class LoanRefund(Document):
"""
Add refund if total repayment is more than that is owed.
"""
+
def validate(self):
self.set_missing_values()
self.validate_refund_amount()
@@ -30,10 +37,7 @@
)
if self.refund_amount > excess_amount:
- frappe.throw(_(
- "Refund amount cannot be greater than excess amount {}".format(
- excess_amount
- )))
+ frappe.throw(_("Refund amount cannot be greater than excess amount {}".format(excess_amount)))
def on_submit(self):
self.update_outstanding_amount()