Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
12690 Lượt xem

iam trying to add scheduled action to add leave allocation for each employee who dose not  have running leave 


i make the below script 


class scheduler_demo(models.Model):
_name =
'scheduler.demo'


def _daily_leaves(self):

test =
self.env['hr.employee'].sudo().search([])
for t in test.ids:
holidays =
self.env['hr.employee'].sudo().search([
(
'id', '=', t),
('current_leave_id', '=', '1')
])
for line in holidays.ids:
leave =
self.env['hr.holidays'].create({
'employee_id': line,
'holiday_status_id': '1',
'type': 'add',
'holiday_type': 'employee',
'number_of_days_temp': '8'
})
leave.action_approve()
if leave.double_validation:
leave.action_validate()
i received the below error

2019-01-19 09:26:31,848 26852 ERROR test4q odoo.osv.expression: Non-stored field hr.employee.current_leave_id cannot be searched. 2019-01-19 09:26:31,957 26852 ERROR test4q odoo.osv.expression: Non-stored field hr.employee.current_leave_id cannot be searched. 2019-01-19 09:26:32,081 26852 ERROR test4q odoo.osv.expression: Non-stored field hr.employee.current_leave_id cannot be searched. 2019-01-19 09:26:32,193 26852 ERROR test4q odoo.osv.expression: Non-stored field hr.employee.current_leave_id cannot be searched. 2019-01-19 09:26:32,302 26852 ERROR test4q odoo.osv.expression: Non-stored field hr.employee.current_leave_id cannot be searched. 2019-01-19 09:26:32,440 26852 ERROR test4q odoo.osv.expression: Non-stored field hr.employee.current_leave_id cannot be searched. 2019-01-19 09:26:32,549 26852 ERROR test4q odoo.osv.expression: Non-stored field hr.employee.current_leave_id cannot be searched. 2019-01-19 09:26:32,665 26852 ERROR test4q odoo.osv.expression: Non-stored field hr.employee.current_leave_id cannot be searched. 2019-01-19 09:26:32,835 26852 INFO test4q werkzeug: 127.0.0.1 - - [19/Jan/2019 09:26:32] "POST /web/dataset/call_button HTTP/1.1" 200 - 2019-01-19 09:26:32,865 26852 INFO test4q werkzeug: 127.0.0.1 - - [19/Jan/2019 09:26:32] "POST /web/dataset/call_kw/ir.cron/search_read HTTP/1.1" 200 - 2019-01-19 09:26:33,163 26852 INFO test4q werkzeug: 127.0.0.1 - - [19/Jan/2019 09:26:33] "POST /web/menu/load_needaction HTTP/1.1" 200 - 2019-01-19 09:26:33,184 26852 INFO test4q werkzeug: 127.0.0.1 - - [19/Jan/2019 09:26:33] "POST /web/dataset/search_read HTTP/1.1" 200 - 2019-01-19 09:26:35,098 26852 INFO ? odoo.addons.bus.models.bus: Bus.loop listen imbus on db postgres

Ảnh đại diện
Huỷ bỏ

Hello Bassam Alsibai,

I m encountering same issue can you help me out in same ? Because my field has to be non storede

Câu trả lời hay nhất

Hi, 

Yes, you cannot use non-stored fields in search domain, so if you need to use this code, you need to make a current_leave_id to be stored one - just inherit hr.employee and add store=True in the current_leave_id field declaration.

PS: if you like the answer - please upvote it! Thanks! :)

Ảnh đại diện
Huỷ bỏ
Tác giả

Thanks Volodymyr ,

your answer was right abut it didn't work form me because this field has to be non-stored field ,

i solved this issue in diffrent way

Câu trả lời hay nhất

How did you solve it?


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 9 21
18623
2
thg 1 19
14936
1
thg 6 18
7613
1
thg 3 22
2185
1
thg 8 24
5930