fix indent and imports
This commit is contained in:
parent
8434ec09c3
commit
0ed6382ab6
@ -2,14 +2,15 @@
|
|||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
import erpnext
|
|
||||||
from frappe import _
|
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.controllers.accounts_controller import AccountsController
|
||||||
from erpnext.loan_management.doctype.process_loan_interest_accrual.process_loan_interest_accrual import (
|
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):
|
class LoanBalanceAdjustment(AccountsController):
|
||||||
@ -19,9 +20,9 @@ class LoanBalanceAdjustment(AccountsController):
|
|||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
if self.amount == 0:
|
if self.amount == 0:
|
||||||
frappe.throw(_("Amount cannot be zero"))
|
frappe.throw(_("Amount cannot be zero"))
|
||||||
if self.amount < 0:
|
if self.amount < 0:
|
||||||
frappe.throw(_("Amount cannot be negative"))
|
frappe.throw(_("Amount cannot be negative"))
|
||||||
self.set_missing_values()
|
self.set_missing_values()
|
||||||
|
|
||||||
def on_submit(self):
|
def on_submit(self):
|
||||||
@ -35,113 +36,106 @@ class LoanBalanceAdjustment(AccountsController):
|
|||||||
|
|
||||||
def set_missing_values(self):
|
def set_missing_values(self):
|
||||||
if not self.posting_date:
|
if not self.posting_date:
|
||||||
self.posting_date = nowdate()
|
self.posting_date = nowdate()
|
||||||
|
|
||||||
if not self.cost_center:
|
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):
|
def set_status_and_amounts(self, cancel=0):
|
||||||
loan_details = frappe.get_all(
|
loan_details = frappe.get_all(
|
||||||
"Loan",
|
"Loan",
|
||||||
fields=[
|
fields=[
|
||||||
"loan_amount",
|
"loan_amount",
|
||||||
"adjustment_amount",
|
"adjustment_amount",
|
||||||
"total_payment",
|
"total_payment",
|
||||||
"total_principal_paid",
|
"total_principal_paid",
|
||||||
"total_interest_payable",
|
"total_interest_payable",
|
||||||
"status",
|
"status",
|
||||||
"is_term_loan",
|
"is_term_loan",
|
||||||
"is_secured_loan",
|
"is_secured_loan",
|
||||||
],
|
],
|
||||||
filters={"name": self.loan},
|
filters={"name": self.loan},
|
||||||
)[0]
|
)[0]
|
||||||
|
|
||||||
if cancel:
|
if cancel:
|
||||||
adjustment_amount = self.get_values_on_cancel(loan_details)
|
adjustment_amount = self.get_values_on_cancel(loan_details)
|
||||||
else:
|
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":
|
if self.adjustment_type == "Credit Adjustment":
|
||||||
adj_field = "credit_adjustment_amount"
|
adj_field = "credit_adjustment_amount"
|
||||||
elif self.adjustment_type == "Debit Adjustment":
|
elif self.adjustment_type == "Debit Adjustment":
|
||||||
adj_field = "debit_adjustment_amount"
|
adj_field = "debit_adjustment_amount"
|
||||||
|
|
||||||
frappe.db.set_value(
|
frappe.db.set_value("Loan", self.loan, {adj_field: adjustment_amount})
|
||||||
"Loan", self.loan, {adj_field: adjustment_amount}
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_values_on_cancel(self, loan_details):
|
def get_values_on_cancel(self, loan_details):
|
||||||
if self.adjustment_type == "Credit Adjustment":
|
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":
|
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
|
return adjustment_amount
|
||||||
|
|
||||||
def get_values_on_submit(self, loan_details):
|
def get_values_on_submit(self, loan_details):
|
||||||
if self.adjustment_type == "Credit Adjustment":
|
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":
|
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 (
|
if loan_details.status in ("Disbursed", "Partially Disbursed") and not loan_details.is_term_loan:
|
||||||
loan_details.status in ("Disbursed", "Partially Disbursed")
|
process_loan_interest_accrual_for_demand_loans(
|
||||||
and not loan_details.is_term_loan
|
posting_date=add_days(self.posting_date, -1),
|
||||||
):
|
loan=self.loan,
|
||||||
process_loan_interest_accrual_for_demand_loans(
|
accrual_type=self.adjustment_type,
|
||||||
posting_date=add_days(self.posting_date, -1),
|
)
|
||||||
loan=self.loan,
|
|
||||||
accrual_type=self.adjustment_type,
|
|
||||||
)
|
|
||||||
|
|
||||||
return adjustment_amount
|
return adjustment_amount
|
||||||
|
|
||||||
def make_gl_entries(self, cancel=0, adv_adj=0):
|
def make_gl_entries(self, cancel=0, adv_adj=0):
|
||||||
gle_map = []
|
gle_map = []
|
||||||
loan_account = frappe.db.get_value("Loan", self.loan, "loan_account")
|
loan_account = frappe.db.get_value("Loan", self.loan, "loan_account")
|
||||||
remarks = "{} against loan {}".format(
|
remarks = "{} against loan {}".format(self.adjustment_type.capitalize(), self.loan)
|
||||||
self.adjustment_type.capitalize(), self.loan
|
|
||||||
)
|
|
||||||
if self.reference_number:
|
if self.reference_number:
|
||||||
remarks += "with reference no. {}".format(self.reference_number)
|
remarks += "with reference no. {}".format(self.reference_number)
|
||||||
|
|
||||||
loan_entry = {
|
loan_entry = {
|
||||||
"account": loan_account,
|
"account": loan_account,
|
||||||
"against": self.adjustment_account,
|
"against": self.adjustment_account,
|
||||||
"against_voucher_type": "Loan",
|
"against_voucher_type": "Loan",
|
||||||
"against_voucher": self.loan,
|
"against_voucher": self.loan,
|
||||||
"remarks": _(remarks),
|
"remarks": _(remarks),
|
||||||
"cost_center": self.cost_center,
|
"cost_center": self.cost_center,
|
||||||
"party_type": self.applicant_type,
|
"party_type": self.applicant_type,
|
||||||
"party": self.applicant,
|
"party": self.applicant,
|
||||||
"posting_date": self.posting_date,
|
"posting_date": self.posting_date,
|
||||||
}
|
}
|
||||||
company_entry = {
|
company_entry = {
|
||||||
"account": self.adjustment_account,
|
"account": self.adjustment_account,
|
||||||
"against": loan_account,
|
"against": loan_account,
|
||||||
"against_voucher_type": "Loan",
|
"against_voucher_type": "Loan",
|
||||||
"against_voucher": self.loan,
|
"against_voucher": self.loan,
|
||||||
"remarks": _(remarks),
|
"remarks": _(remarks),
|
||||||
"cost_center": self.cost_center,
|
"cost_center": self.cost_center,
|
||||||
"posting_date": self.posting_date,
|
"posting_date": self.posting_date,
|
||||||
}
|
}
|
||||||
if self.adjustment_type == "Credit Adjustment":
|
if self.adjustment_type == "Credit Adjustment":
|
||||||
loan_entry["credit"] = self.amount
|
loan_entry["credit"] = self.amount
|
||||||
loan_entry["credit_in_account_currency"] = self.amount
|
loan_entry["credit_in_account_currency"] = self.amount
|
||||||
|
|
||||||
company_entry["debit"] = self.amount
|
company_entry["debit"] = self.amount
|
||||||
company_entry["debit_in_account_currency"] = self.amount
|
company_entry["debit_in_account_currency"] = self.amount
|
||||||
|
|
||||||
elif self.adjustment_type == "Debit Adjustment":
|
elif self.adjustment_type == "Debit Adjustment":
|
||||||
loan_entry["debit"] = self.amount
|
loan_entry["debit"] = self.amount
|
||||||
loan_entry["debit_in_account_currency"] = self.amount
|
loan_entry["debit_in_account_currency"] = self.amount
|
||||||
|
|
||||||
company_entry["credit"] = self.amount
|
company_entry["credit"] = self.amount
|
||||||
company_entry["credit_in_account_currency"] = 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(loan_entry))
|
||||||
|
|
||||||
gle_map.append(self.get_gl_dict(company_entry))
|
gle_map.append(self.get_gl_dict(company_entry))
|
||||||
|
|
||||||
if gle_map:
|
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)
|
||||||
|
@ -1,13 +1,20 @@
|
|||||||
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
# import frappe
|
import frappe
|
||||||
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
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):
|
class LoanRefund(Document):
|
||||||
"""
|
"""
|
||||||
Add refund if total repayment is more than that is owed.
|
Add refund if total repayment is more than that is owed.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
self.set_missing_values()
|
self.set_missing_values()
|
||||||
self.validate_refund_amount()
|
self.validate_refund_amount()
|
||||||
@ -30,10 +37,7 @@ class LoanRefund(Document):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if self.refund_amount > excess_amount:
|
if self.refund_amount > excess_amount:
|
||||||
frappe.throw(_(
|
frappe.throw(_("Refund amount cannot be greater than excess amount {}".format(excess_amount)))
|
||||||
"Refund amount cannot be greater than excess amount {}".format(
|
|
||||||
excess_amount
|
|
||||||
)))
|
|
||||||
|
|
||||||
def on_submit(self):
|
def on_submit(self):
|
||||||
self.update_outstanding_amount()
|
self.update_outstanding_amount()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user