Skip to content

Commit

Permalink
fix: Sales Invoice generation via disbursement
Browse files Browse the repository at this point in the history
  • Loading branch information
deepeshgarg007 committed Dec 25, 2023
1 parent f1c91ab commit e00f64b
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 10 deletions.
11 changes: 10 additions & 1 deletion lending/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@
"options": "Loan",
"insert_after": "customer",
"print_hide": 1,
}
},
{
"fieldname": "loan_disbursement",
"label": "Loan Disbursement",
"fieldtype": "Link",
"options": "Loan Disbursement",
"insert_after": "Loan",
"read_only": 1,
"print_hide": 1,
},
],
"Company": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,16 +436,25 @@ def get_values_on_submit(self, loan_details):
new_utilized_limit_amount,
)

def add_gl_entry(self, gl_entries, account, against_account, amount, remarks=None):
def add_gl_entry(
self,
gl_entries,
account,
against_account,
amount,
remarks=None,
against_voucher_type=None,
against_voucher=None,
):
gl_entries.append(
self.get_gl_dict(
{
"account": account,
"against": against_account,
"debit": amount,
"debit_in_account_currency": amount,
"against_voucher_type": "Loan",
"against_voucher": self.against_loan,
"against_voucher_type": against_voucher_type or "Loan",
"against_voucher": against_voucher or self.against_loan,
"remarks": remarks,
"cost_center": self.cost_center,
"party_type": self.applicant_type,
Expand Down Expand Up @@ -505,12 +514,65 @@ def make_gl_entries(self, cancel=0, adv_adj=0):
)

for charge in self.get("loan_disbursement_charges"):
self.add_gl_entry(gle_map, charge.account, self.disbursement_account, charge.amount, remarks)
sales_invoice = make_sales_invoice_for_charge(
self.against_loan,
self.name,
self.disbursement_date,
self.company,
charge.charge,
charge.amount,
)

self.add_gl_entry(
gle_map,
charge.account,
self.disbursement_account,
-1 * sales_invoice.grand_total,
remarks,
"Sales Invoice",
sales_invoice.name,
)

if gle_map:
make_gl_entries(gle_map, cancel=cancel, adv_adj=adv_adj)


def make_sales_invoice_for_charge(
loan, loan_disbursement, disbursement_date, company, charge, amount
):
si = frappe.get_doc(
{
"doctype": "Sales Invoice",
"loan": loan,
"loan_disbursement": loan_disbursement,
"posting_date": disbursement_date,
"company": company,
"conversion_rate": 1,
}
)

loan_product = frappe.db.get_value("Loan", loan, "loan_product")
account = frappe.db.get_value(
"Loan Charges", {"parent": loan_product, "charge_type": charge}, "income_account"
)
receivable_account = frappe.db.get_value(
"Loan Charges", {"parent": loan_product, "charge_type": charge}, "receivable_account"
)

if not account:
account = frappe.db.get_value(
"Item Default", {"parent": charge, "company": company}, "income_account"
)

si.append("items", {"item_code": charge, "rate": amount, "qty": 1, "income_account": account})

si.debit_to = receivable_account
si.save()
si.submit()

return si


def get_total_pledged_security_value(loan):
update_time = get_datetime()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-11-29 19:33:39.463380",
"modified": "2023-12-25 19:33:39.463380",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Loan Product",
Expand Down
2 changes: 1 addition & 1 deletion lending/overrides/sales_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def generate_demand(self, method=None):
if self.get("loan"):
if self.get("loan") and not self.get("loan_disbursement"):
create_loan_demand(
self.loan, self.posting_date, "Charges", "Charges", self.grand_total, sales_invoice=self.name
)
Expand Down
2 changes: 1 addition & 1 deletion lending/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ lending.patches.v15_0.rename_loan_type_to_loan_product
[post_model_sync]
# Patches added in this section will be executed after doctypes are migrated
lending.patches.v15_0.update_loan_types
lending.patches.v15_0.create_custom_fields #13
lending.patches.v15_0.create_custom_fields #14
lending.patches.v15_0.create_custom_field_for_irac_provisioning_configuration
lending.patches.v15_0.update_loan_asset_classification_ranges
lending.patches.v15_0.generate_loan_classifications_from_loan_asset_classification_ranges
Expand Down
4 changes: 2 additions & 2 deletions lending/patches/v15_0/create_custom_fields.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from lending.install import after_install
from lending.install import LOAN_CUSTOM_FIELDS, create_custom_fields


def execute():
after_install()
create_custom_fields(LOAN_CUSTOM_FIELDS, ignore_validate=True)

0 comments on commit e00f64b

Please sign in to comment.