fix: Added Company filters for Loan (#26294)

* fix: loan validations

* fix: added company filter while fetching loans

* fix: tests
This commit is contained in:
Jannat Patel
2021-07-12 13:01:31 +05:30
committed by GitHub
parent 10473b1195
commit 38994bd494
5 changed files with 38 additions and 25 deletions

View File

@@ -28,7 +28,8 @@ frappe.ui.form.on('Loan', {
frm.set_query("loan_type", function () { frm.set_query("loan_type", function () {
return { return {
"filters": { "filters": {
"docstatus": 1 "docstatus": 1,
"company": frm.doc.company
} }
}; };
}); });

View File

@@ -14,6 +14,13 @@ frappe.ui.form.on('Loan Application', {
refresh: function(frm) { refresh: function(frm) {
frm.trigger("toggle_fields"); frm.trigger("toggle_fields");
frm.trigger("add_toolbar_buttons"); frm.trigger("add_toolbar_buttons");
frm.set_query('loan_type', () => {
return {
filters: {
company: frm.doc.company
}
};
});
}, },
repayment_method: function(frm) { repayment_method: function(frm) {
frm.doc.repayment_amount = frm.doc.repayment_periods = "" frm.doc.repayment_amount = frm.doc.repayment_periods = ""

View File

@@ -1091,6 +1091,7 @@ class SalarySlip(TransactionBase):
"applicant": self.employee, "applicant": self.employee,
"docstatus": 1, "docstatus": 1,
"repay_from_salary": 1, "repay_from_salary": 1,
"company": self.company
}) })
def make_loan_repayment_entry(self): def make_loan_repayment_entry(self):

View File

@@ -482,14 +482,19 @@ def make_employee_salary_slip(user, payroll_frequency, salary_structure=None):
salary_structure = payroll_frequency + " Salary Structure Test for Salary Slip" salary_structure = payroll_frequency + " Salary Structure Test for Salary Slip"
employee = frappe.db.get_value("Employee", {"user_id": user}) employee = frappe.db.get_value("Employee",
salary_structure_doc = make_salary_structure(salary_structure, payroll_frequency, employee=employee) {
"user_id": user
},
["name", "company", "employee_name"],
as_dict=True)
salary_structure_doc = make_salary_structure(salary_structure, payroll_frequency, employee=employee.name, company=employee.company)
salary_slip_name = frappe.db.get_value("Salary Slip", {"employee": frappe.db.get_value("Employee", {"user_id": user})}) salary_slip_name = frappe.db.get_value("Salary Slip", {"employee": frappe.db.get_value("Employee", {"user_id": user})})
if not salary_slip_name: if not salary_slip_name:
salary_slip = make_salary_slip(salary_structure_doc.name, employee = employee) salary_slip = make_salary_slip(salary_structure_doc.name, employee = employee.name)
salary_slip.employee_name = frappe.get_value("Employee", salary_slip.employee_name = employee.employee_name
{"name":frappe.db.get_value("Employee", {"user_id": user})}, "employee_name")
salary_slip.payroll_frequency = payroll_frequency salary_slip.payroll_frequency = payroll_frequency
salary_slip.posting_date = nowdate() salary_slip.posting_date = nowdate()
salary_slip.insert() salary_slip.insert()

View File

@@ -119,26 +119,25 @@ def make_salary_structure(salary_structure, payroll_frequency, employee=None,
if test_tax: if test_tax:
frappe.db.sql("""delete from `tabSalary Structure` where name=%s""",(salary_structure)) frappe.db.sql("""delete from `tabSalary Structure` where name=%s""",(salary_structure))
if not frappe.db.exists('Salary Structure', salary_structure): if frappe.db.exists("Salary Structure", salary_structure):
details = { frappe.db.delete("Salary Structure", salary_structure)
"doctype": "Salary Structure",
"name": salary_structure,
"company": company or erpnext.get_default_company(),
"earnings": make_earning_salary_component(setup=True, test_tax=test_tax, company_list=["_Test Company"]),
"deductions": make_deduction_salary_component(setup=True, test_tax=test_tax, company_list=["_Test Company"]),
"payroll_frequency": payroll_frequency,
"payment_account": get_random("Account", filters={'account_currency': currency}),
"currency": currency
}
if other_details and isinstance(other_details, dict):
details.update(other_details)
salary_structure_doc = frappe.get_doc(details)
salary_structure_doc.insert()
if not dont_submit:
salary_structure_doc.submit()
else: details = {
salary_structure_doc = frappe.get_doc("Salary Structure", salary_structure) "doctype": "Salary Structure",
"name": salary_structure,
"company": company or erpnext.get_default_company(),
"earnings": make_earning_salary_component(setup=True, test_tax=test_tax, company_list=["_Test Company"]),
"deductions": make_deduction_salary_component(setup=True, test_tax=test_tax, company_list=["_Test Company"]),
"payroll_frequency": payroll_frequency,
"payment_account": get_random("Account", filters={'account_currency': currency}),
"currency": currency
}
if other_details and isinstance(other_details, dict):
details.update(other_details)
salary_structure_doc = frappe.get_doc(details)
salary_structure_doc.insert()
if not dont_submit:
salary_structure_doc.submit()
filters = {'employee':employee, 'docstatus': 1} filters = {'employee':employee, 'docstatus': 1}
if not from_date and payroll_period: if not from_date and payroll_period: