Skip to content

Commit

Permalink
fix: Add cost center in loan document
Browse files Browse the repository at this point in the history
(cherry picked from commit 5d66cc4)

# Conflicts:
#	erpnext/loan_management/doctype/loan_interest_accrual/loan_interest_accrual.py
#	erpnext/patches.txt
  • Loading branch information
deepeshgarg007 authored and mergify[bot] committed Jun 7, 2022
1 parent 8cb85fa commit c19dfbe
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 2 deletions.
15 changes: 14 additions & 1 deletion erpnext/loan_management/doctype/loan/loan.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
"monthly_repayment_amount",
"repayment_start_date",
"is_term_loan",
"accounting_dimensions_section",
"cost_center",
"account_info",
"mode_of_payment",
"disbursement_account",
Expand Down Expand Up @@ -366,12 +368,23 @@
"options": "Account",
"read_only": 1,
"reqd": 1
},
{
"fieldname": "accounting_dimensions_section",
"fieldtype": "Section Break",
"label": "Accounting Dimensions"
},
{
"fieldname": "cost_center",
"fieldtype": "Link",
"label": "Cost Center",
"options": "Cost Center"
}
],
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2022-01-25 16:29:16.325501",
"modified": "2022-03-10 11:50:31.957360",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Loan",
Expand Down
8 changes: 8 additions & 0 deletions erpnext/loan_management/doctype/loan/loan.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def validate(self):
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()
Expand Down Expand Up @@ -59,6 +60,13 @@ def validate_accounts(self):
)
)

def validate_cost_center(self):
if not self.cost_center and self.rate_of_interest != 0:
self.cost_center = frappe.db.get_value('Company', self.company, 'cost_center')

if not self.cost_center:
frappe.throw(_('Cost center is mandatory for loans having rate of interest greater than 0'))

def on_submit(self):
self.link_loan_security_pledge()
# Interest accrual for backdated term loans
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from frappe import _
from frappe.utils import add_days, cint, date_diff, flt, get_datetime, getdate, nowdate

import erpnext
from erpnext.accounts.general_ledger import make_gl_entries
from erpnext.controllers.accounts_controller import AccountsController

Expand Down Expand Up @@ -41,8 +40,11 @@ def update_is_accrued(self):
def make_gl_entries(self, cancel=0, adv_adj=0):
gle_map = []

cost_center = frappe.db.get_value('Loan', self.loan, 'cost_center')

if self.interest_amount:
gle_map.append(
<<<<<<< HEAD
self.get_gl_dict(
{
"account": self.loan_account,
Expand Down Expand Up @@ -78,6 +80,37 @@ def make_gl_entries(self, cancel=0, adv_adj=0):
"posting_date": self.posting_date,
}
)
=======
self.get_gl_dict({
"account": self.loan_account,
"party_type": self.applicant_type,
"party": self.applicant,
"against": self.interest_income_account,
"debit": self.interest_amount,
"debit_in_account_currency": self.interest_amount,
"against_voucher_type": "Loan",
"against_voucher": self.loan,
"remarks": _("Interest accrued from {0} to {1} against loan: {2}").format(
self.last_accrual_date, self.posting_date, self.loan),
"cost_center": cost_center,
"posting_date": self.posting_date
})
)

gle_map.append(
self.get_gl_dict({
"account": self.interest_income_account,
"against": self.loan_account,
"credit": self.interest_amount,
"credit_in_account_currency": self.interest_amount,
"against_voucher_type": "Loan",
"against_voucher": self.loan,
"remarks": ("Interest accrued from {0} to {1} against loan: {2}").format(
self.last_accrual_date, self.posting_date, self.loan),
"cost_center": cost_center,
"posting_date": self.posting_date
})
>>>>>>> 5d66cc4c4a (fix: Add cost center in loan document)
)

if gle_map:
Expand Down
7 changes: 7 additions & 0 deletions erpnext/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ erpnext.patches.v13_0.amazon_mws_deprecation_warning
erpnext.patches.v13_0.datev_deprecation_warning
erpnext.patches.v13_0.set_work_order_qty_in_so_from_mr
erpnext.patches.v13_0.update_accounts_in_loan_docs
<<<<<<< HEAD
erpnext.patches.v13_0.remove_unknown_links_to_prod_plan_items # 24-03-2022
erpnext.patches.v13_0.rename_non_profit_fields
erpnext.patches.v13_0.enable_ksa_vat_docs #1
Expand All @@ -367,3 +368,9 @@ erpnext.patches.v13_0.create_accounting_dimensions_in_orders
erpnext.patches.v13_0.set_per_billed_in_return_delivery_note
erpnext.patches.v13_0.update_employee_advance_status
erpnext.patches.v13_0.job_card_status_on_hold
=======
erpnext.patches.v14_0.update_batch_valuation_flag
erpnext.patches.v14_0.delete_non_profit_doctypes
erpnext.patches.v14_0.update_employee_advance_status
erpnext.patches.v13_0.add_cost_center_in_loans
>>>>>>> 5d66cc4c4a (fix: Add cost center in loan document)
16 changes: 16 additions & 0 deletions erpnext/patches/v13_0/add_cost_center_in_loans.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import frappe


def execute():
frappe.reload_doc('loan_management', 'doctype', 'loan')
loan = frappe.qb.DocType('Loan')

for company in frappe.get_all('Company', pluck='name'):
default_cost_center = frappe.db.get_value('Company', company, 'cost_center')
frappe.qb.update(
loan
).set(
loan.cost_center, default_cost_center
).where(
loan.company == company
).run()

0 comments on commit c19dfbe

Please sign in to comment.