Skip to content

Commit

Permalink
fix: Add missing account filters.
Browse files Browse the repository at this point in the history
  • Loading branch information
bosue committed Oct 4, 2023
1 parent 6bb5139 commit 858c550
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions lending/loan_management/doctype/loan_product/loan_product.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,36 @@

frappe.ui.form.on('Loan Product', {
onload: function(frm) {
$.each(["penalty_income_account", "interest_income_account"], function (i, field) {
frm.set_query(field, function () {
return {
"filters": {
"company": frm.doc.company,
"root_type": "Income",
"is_group": 0
}
};
});
});
const fieldMap = {
"disbursement_account": "Asset",
"loan_account": "Asset",
"payment_account": "Asset",
"suspense_interest_receivable": "Asset",
"interest_receivable_account": "Asset",
"penalty_receivable_account": "Asset",
"charges_receivable_account": "Asset",
"security_deposit_account": "Liability",
"interest_income_account": "Income",
"penalty_income_account": "Income",
"suspense_interest_income": "Income",
"principal_waiver_account": "Expense",
"interest_waiver_account": "Expense",
"penalty_waiver_account": "Expense",
"charges_waiver_account": "Expense",
"suspense_collection_account": ""
}

const createFilters = (company, rootType) => {
const filters = { "company": company };
if (rootType) {
filters["root_type"] = rootType;
}
filters["is_group"] = 0;
return { "filters": filters };
};

$.each(["payment_account", "loan_account", "disbursement_account"], function (i, field) {
frm.set_query(field, function () {
return {
"filters": {
"company": frm.doc.company,
"root_type": "Asset",
"is_group": 0
}
};
});
Object.keys(fieldMap).forEach(field => {
frm.set_query(field, () => createFilters(frm.doc.company, fieldMap[field]));
});
}
});

0 comments on commit 858c550

Please sign in to comment.