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

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

Avatar
Discard

Hello Bassam Alsibai,

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

Best Answer

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! :)

Avatar
Discard
Author

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

Best Answer

How did you solve it?


Avatar
Discard
Related Posts Replies Views Activity
1
Sep 21
16551
2
Jan 19
13204
1
Jun 18
6532
1
Mar 22
1377
1
Aug 24
4287