Salary Structure Condition Month

Hi,
I had on conditions this start_date.month == 11 which now on version v10.1.23 and is returning this error

Error in formula or condition: ‘unicode’ object has no attribute ‘month’

when using frappe.utils.getdate(start_date).month == 11 returns error
Name error: name ‘frappe’ is not defined

Did you import frappe at the beginning of your file?

i cannot because is coming from hr/doctype/salary_slip/salary_slip.py", line 97, in eval_condition_and_formula

@shreya115 hi,
Any solution for this?

The full traceback of your error would make it easier to establish your problem

Thanks for your support.
Unfortunately now I can’t but as I said this is happening on salary structure under conditions of you add start_date.month == 11 to check if on November … This is working on version 8/9 but now on version 10.1.23

My temporary solution was this and it works… Inside salary_slip.py on Def eval condition and formula
Under if condition != None:
Added
If ‘.month’ in condition:
valuemonth = frappe.utils.datetime.datetime.strptime(eval(“self.”+ condition [0: condition.find(“.month”)]),“%Y-%m-%d”).month
Condition= condition.replace(condition [0: condition.find(“.month”)+6],str(valuemonth))

Hi,
Has this been tested on v11??

Good question v11 continues to be tested -

To find or report your case here Issues · frappe/erpnext · GitHub

would improve the likelihood of it being fixed and tested

reported again on Issues

Hi all,
I see that adding conditions with (.month/.year) still not solved on v12.
Any suggestions?
Currently we have to change the salary slip.py to add this, which means every erpnext update we need to review the source code to add… :pensive:

“Any suggestions?”

Thanks for your persistence - maybe post here the revised function?

Here’s the current version:

	def eval_condition_and_formula(self, d, data):
		try:
			condition = d.condition.strip().replace("\n", " ") if d.condition else None
			if condition:
				if not frappe.safe_eval(condition, self.whitelisted_globals, data):
					return None
			amount = d.amount
			if d.amount_based_on_formula:
				formula = d.formula.strip().replace("\n", " ") if d.formula else None
				if formula:
					amount = flt(frappe.safe_eval(formula, self.whitelisted_globals, data), d.precision("amount"))
			if amount:
				data[d.abbr] = amount

			return amount

		except NameError as err:
			frappe.throw(_("Name error: {0}").format(err))
		except SyntaxError as err:
			frappe.throw(_("Syntax error in formula or condition: {0}").format(err))
		except Exception as e:
			frappe.throw(_("Error in formula or condition: {0}").format(e))
			raise

Then users can vet and test for themselves the change you propose .

The final step is to submit a PR - a pull request - but that may require an accompanying test?

https://github.com/frappe/erpnext/blob/develop/erpnext/hr/doctype/salary_slip/test_salary_slip.py

https://github.com/frappe/erpnext/blob/develop/erpnext/hr/doctype/salary_slip/salary_slip.py#L434

Will do so when fork the V12 and update the github issue (Issue: Salary Structure with start_date Month returns Error) raised.