Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
4692 มุมมอง

Hi,

My domain is conditional. How do i join them base on criteria below:

The function is to get ids from a table.

@api.onchange('month','year','department_ids','job_ids', 'date_from', 'date_to')

 def onchange_data_criteria(self):

        print('-----start processing payslip id from criteria-------')

        slip_ids = []

        domain = []


        if self.month and self.year:

            domain = domain + [('year', '=', self.year),('month', '=', self.month)]


        if self.job_ids:

            domain = domain + [('job_id', 'in', self.job_ids)]

        

        if self.date_from and self.date_to:

            domain = domain + [('date_from', '>=', self.date_from), ('date_from', '<=', self.date_to)]


        payslip = self.env['hr.payslip'].search(domain).id


I got the following error:

  File "/opt/odoo12/odoo/odoo/models.py", line 5308, in process
    if res.get('value'):
AttributeError: 'hr.payslip' object has no attribute 'get'


    

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi, Gain

Instead of searching you need to return domain with this method like below,

@api.onchange('month','year','department_ids','job_ids''date_from''date_to')
def onchange_data_criteria(self):
print('-----start processing payslip id from criteria-------')
  slip_ids = []
  domain = []
if self.month and self.year:
  domain = domain + [('year''='self.year),('month''='self.month)]
if self.job_ids:
  domain = domain + [('job_id''in'self.job_ids)]
if self.date_from and self.date_to:
  domain = domain + [('date_from''>='self.date_from), ('date_from''<='self.date_to)]
  res = {}
if domain:
  res['domain'] = domain
return res
Feel free to ask in case you still have the same query.

Thanks,
Ashish Singh (Team Lead)
Webkul Software Private Limited
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Try to append like this


@api.onchange('month','year','department_ids','job_ids', 'date_from', 'date_to')

 def onchange_data_criteria(self):

        print('-----start processing payslip id from criteria-------')

        slip_ids = []

        domain = []


        if self.month and self.year:

            domain.append(('year', '=', self.year))

            domain.append(('month', '=', self.month))


        if self.job_ids:

            domain.append(('job_id', 'in', self.job_ids))

        

        if self.date_from and self.date_to:

            domain.append(('date_from', '>=', self.date_from)

            domain.append(('date_from', '<=', self.date_to))


        payslip = self.env['hr.payslip'].search(domain).id

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
เม.ย. 25
4274
1
พ.ค. 24
3130
0
มี.ค. 24
1789
1
พ.ย. 22
5641
0
ต.ค. 22
2966