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

Hi i need to make module can go through all employee in employee module and create leave allocation record fro each of those employee by making scheduled action 

make the python as below  could any one explain from me how to do that or direct me to any references can help 


many thanks 

# -*- coding: utf-8 -*-
from odoo import models, fields, api
#Import logger
import logging
#Get the logger
_logger = logging.getLogger(__name__)

#External import
import datetime

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

def _daily_leaves(self):


vications = self.env['hr.employee'].search([])
emp=vications.mapped('emplyee_id')
for em in emp:
vd = 20
leave = self.env['hr.holidays'].create({
'employee_id': em,
'holiday_status_id': '1',
'type': 'add',
'holiday_type': 'employee',
'number_of_days_temp': vd
})
leave.action_approve()
if leave.double_validation:
leave.action_validate()


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi Bassam,

Seems you query is not so clear. But looking to your code.

1. vications = self.env['hr.employee'].search([]), This search will give you all employees objects like hr.employee(1,2,3) etc.

2. emp=vications.mapped('emplyee_id'),  There is no employee_id field, though you already got done search for all employee using above code, so this statement really not needed.

3.lopping  from emp instead use for emp in self.env['hr.employee'].search([]):

Thanks



Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

contract module does have employee_id field i changed the code 


vications = self.env['hr.contract'].search([])
emp=vications('emplyee_id')
for em in emp:
vd = 20
leave = self.env['hr.holidays'].create({
'employee_id': em,
'holiday_status_id': '1',
'type': 'add',
'holiday_type': 'employee',
'number_of_days_temp': vd
})
leave.action_approve()
if leave.double_validation:
leave.action_validate()

get this error TypeError: 'hr.contract' object is not callable
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 2 23
12628
1
thg 3 25
832
1
thg 6 18
7548
1
thg 9 21
18550
2
thg 3 24
1600