Skip to Content
Menu
This question has been flagged
2 Replies
1152 Views

Hello ,

I working on payroll constraint that If the net salary less than zero,get all the employees that meet that condition in list.

here's is my code:


@api.constrains("salary_rule_id", 'amount')
def hide_some_loans(self):
for rec in self:
if rec.salary_rule_id.name == "Net Salary" and rec.amount < 0 and rec.employee_id.name:
neg=[]
neg.append(rec.employee_id.name)
print(neg)
raise ValidationError(_("Please Forward the Dedication for %s to the Next Months.") %(neg))

The Problem is I get only the first employee.


Avatar
Discard
Best Answer

Hi Jenan Soliman,

Please try this code.

@api.constrains("salary_rule_id", 'amount')
def hide_some_loans(self):
neg=[]
for rec in self:
if rec.salary_rule_id.name == "Net Salary" and rec.amount < 0 and rec.employee_id.name:
neg.append(rec.employee_id.name)
print(neg)
if neg:
raise ValidationError(_("Please Forward the Dedication for %s to the Next Months.") %((",".join(counterpart))))

I am not aware about the flow of your code, but try to use the "code" field of salary rule model if exist for the if condition. like 
        if rec.salary_rule_id.code == "NET" and rec.amount < 0 and rec.employee_id.name:

Hope it will help you.
Please vote up.


Avatar
Discard
Best Answer

Hi,

Please try with this code:

@api.constrains("salary_rule_id", 'amount')
def hide_some_loans(self):
records = self.search([])
for rec in records:
neg = []
if rec.salary_rule_id.name == "Net Salary" and rec.amount < 0 and rec.employee_id.name:
neg.append(rec.employee_id.name)
raise ValidationError(_("Please Forward the Dedication for %s to the Next Months.") % (neg))


Thanks

Avatar
Discard
Author

Thank you, I tried it I get an empty list

Related Posts Replies Views Activity
3
Oct 23
5979
1
Sep 23
1968
1
May 23
1004
2
Apr 23
1378
1
Mar 23
996