Skip to Content
Menu
This question has been flagged
1 Reply
1999 Views

Hello all,

I have added a field for salary structure in my form and added line level for salary rules.. i want that when i select a particular salary structure then all attached rules of this structure should be listed in line level...

Here is my code:

@api.onchange('salary_structure')
def _get_structure_head(self):
self.settlement_detail_ids = [(5, _, _)]
if self.salary_structure:
object1 = self.env['hr.payroll.structure'].search([('id', '=', self.salary_structure.id)])
self.settlement_detail_ids.unlink()
for r1 in object1:
object2 = self.env['hr.salary.rule'].search([('structure_id', '=', r1.id)])
for r2 in object2:
self.settlement_detail_ids |= self.settlement_detail_ids.new({
'head': r2.id
})
Avatar
Discard
Best Answer

Hi Yaseen,
I hope your level field is a Many2many field, then you can rewrite the function as below.

@api.onchange('salary_structure')
def _get_structure_head(self):
self.settlement_detail_ids = [(5, 0, 0)]
if self.salary_structure:
  rule_ids = self.env['hr.salary.rule'].search(
  [('struct_id', '=', self.salary_structure.id)])
self.settlement_detail_ids = rule_ids

Regards

Avatar
Discard