Payroll entry error on create salary slip "Name error: name 'b' is not defined"

On clicking “create salary slip” on paroll entry i get this error as follows:

“Name error: name ‘b’ is not defined”

See screenshot below:

The error is not descriptive enough so i went to pae inspect and got this traceback errors once i click on “create salary slip”:

jquery.min.js:4 POST http://192.168.100.88/api/method/frappe.desk.form.save.savedocs 417 (EXPECTATION FAILED)
send @ jquery.min.js:4
ajax @ jquery.min.js:4
frappe.request.call @ request.js:219
frappe.call @ request.js:91
u @ save.js:198
frappe.ui.form.save @ save.js:25
(anonymous) @ form.js:588
Promise.then (async)
(anonymous) @ dom.js:261
frappe.run_serially @ dom.js:259
validate_and_save @ form.js:579
(anonymous) @ form.js:526
setTimeout (async)
(anonymous) @ form.js:525
save @ form.js:519
eval @ VM522:38
(anonymous) @ page.js:171
dispatch @ jquery.min.js:3
r.handle @ jquery.min.js:3
request.js:355 Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/save.py”, line 19, in savedocs
doc.submit()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 859, in submit
self._submit()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 848, in _submit
self.save()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 272, in save
return self._save(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 325, in _save
self.run_post_save_methods()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 922, in run_post_save_methods
self.run_method(“on_submit”)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 787, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1058, in composer
return composed(self, method, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1041, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 781, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/hr/doctype/payroll_entry/payroll_entry.py”, line 25, in on_submit
self.create_salary_slips()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/hr/doctype/payroll_entry/payroll_entry.py”, line 130, in create_salary_slips
create_salary_slips_for_employees(emp_list, args, publish_progress=False)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/hr/doctype/payroll_entry/payroll_entry.py”, line 510, in create_salary_slips_for_employees
ss.insert()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 229, in insert
self.run_before_save_methods()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 888, in run_before_save_methods
self.run_method(“validate”)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 787, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1058, in composer
return composed(self, method, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1041, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 781, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/hr/doctype/salary_slip/salary_slip.py”, line 46, in validate
self.get_emp_and_leave_details()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/hr/doctype/salary_slip/salary_slip.py”, line 132, in get_emp_and_leave_details
self.pull_sal_struct()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/hr/doctype/salary_slip/salary_slip.py”, line 182, in pull_sal_struct
make_salary_slip(self.salary_structure_doc.name, self)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/hr/doctype/salary_structure/salary_structure.py”, line 160, in make_salary_slip
}, target_doc, postprocess, ignore_child_tables=True)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/mapper.py”, line 116, in get_mapped_doc
postprocess(source_doc, target_doc)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/hr/doctype/salary_structure/salary_structure.py”, line 150, in postprocess
target.run_method(‘process_salary_structure’, for_preview=for_preview)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 787, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1058, in composer
return composed(self, method, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1041, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 781, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/hr/doctype/salary_slip/salary_slip.py”, line 831, in process_salary_structure
self.calculate_net_pay()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/hr/doctype/salary_slip/salary_slip.py”, line 295, in calculate_net_pay
self.calculate_component_amounts()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/hr/doctype/salary_slip/salary_slip.py”, line 311, in calculate_component_amounts
self.add_structure_components()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/hr/doctype/salary_slip/salary_slip.py”, line 321, in add_structure_components
amount = self.eval_condition_and_formula(struct_row, data)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/hr/doctype/salary_slip/salary_slip.py”, line 363, in eval_condition_and_formula
frappe.throw(
(“Name error: {0}”.format(err)))
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 364, in throw
msgprint(msg, raise_exception=exc, title=title, indicator=‘red’)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 350, in msgprint
_raise_exception()
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 316, in _raise_exception
raise raise_exception(msg)
ValidationError: Name error: name ‘b’ is not defined

request.js:355 Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/app.py”, line 60, in application
response = frappe.api.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/api.py”, line 55, in handle
return frappe.handler.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 22, in handle
data = execute_cmd(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 61, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 1042, in call
return fn(*args, **newargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/save.py”, line 19, in savedocs
doc.submit()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 859, in submit
self._submit()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 848, in _submit
self.save()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 272, in save
return self._save(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 325, in _save
self.run_post_save_methods()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 922, in run_post_save_methods
self.run_method(“on_submit”)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 787, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1058, in composer
return composed(self, method, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1041, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 781, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/hr/doctype/payroll_entry/payroll_entry.py”, line 25, in on_submit
self.create_salary_slips()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/hr/doctype/payroll_entry/payroll_entry.py”, line 130, in create_salary_slips
create_salary_slips_for_employees(emp_list, args, publish_progress=False)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/hr/doctype/payroll_entry/payroll_entry.py”, line 510, in create_salary_slips_for_employees
ss.insert()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 229, in insert
self.run_before_save_methods()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 888, in run_before_save_methods
self.run_method(“validate”)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 787, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1058, in composer
return composed(self, method, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1041, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 781, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/hr/doctype/salary_slip/salary_slip.py”, line 46, in validate
self.get_emp_and_leave_details()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/hr/doctype/salary_slip/salary_slip.py”, line 132, in get_emp_and_leave_details
self.pull_sal_struct()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/hr/doctype/salary_slip/salary_slip.py”, line 182, in pull_sal_struct
make_salary_slip(self.salary_structure_doc.name, self)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/hr/doctype/salary_structure/salary_structure.py”, line 160, in make_salary_slip
}, target_doc, postprocess, ignore_child_tables=True)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/mapper.py”, line 116, in get_mapped_doc
postprocess(source_doc, target_doc)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/hr/doctype/salary_structure/salary_structure.py”, line 150, in postprocess
target.run_method(‘process_salary_structure’, for_preview=for_preview)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 787, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1058, in composer
return composed(self, method, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1041, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 781, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/hr/doctype/salary_slip/salary_slip.py”, line 831, in process_salary_structure
self.calculate_net_pay()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/hr/doctype/salary_slip/salary_slip.py”, line 295, in calculate_net_pay
self.calculate_component_amounts()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/hr/doctype/salary_slip/salary_slip.py”, line 311, in calculate_component_amounts
self.add_structure_components()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/hr/doctype/salary_slip/salary_slip.py”, line 321, in add_structure_components
amount = self.eval_condition_and_formula(struct_row, data)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/hr/doctype/salary_slip/salary_slip.py”, line 363, in eval_condition_and_formula
frappe.throw(
(“Name error: {0}”.format(err)))
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 364, in throw
msgprint(msg, raise_exception=exc, title=title, indicator=‘red’)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 350, in msgprint
_raise_exception()
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 316, in _raise_exception
raise raise_exception(msg)
ValidationError: Name error: name ‘b’ is not defined

Any assistance will be greatly appreciated.

@ben

Hi,

Have you used any formula to create salary structure? If yes, then it may have occurred due to that.

Regards,
Reema

@Reema_Mehta

Thanks for your feedback. Your answer is correct, the formula is what was causing issues. I have rectified the formulas and now it is okay. Thanks alot for your support.I highly appreciate.

@Reema_Mehta, hi can one use the && operation in the formula section to break down your conditions? eg if ifor my house allowance i would want a calculation as follows:

House allowance Group A: base<=2,000 && base>=1,000
House allowance Group B: base<=2,001 && base>=3,000
House allowance Group C: base<=3,001 && base>=4,000
House allowance Group D: base<=4,001 && base>=5,000

Let me know if this can be used. Thanks in advance

@ben

Not sure whether && function works but you can try out the ‘if else’ formula. that should help you.

Regards,
Reema

Please, kindly post the correction for us

@Benjamin_Ayisi i got it to work with this:

base * 0.04 if (base >= 300001 and base <= 400000) else base * 0.03 if (base >= 200001 and base <= 300000) else base * 0.02 if (base >= 100001 and base <= 200000) else base * 0.01 if (base >= 1 and base <= 100000) else 0

Thank you very much. its clear now