Skip to Content
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
20 Lượt xem

Hello, i'm trying to make a work entry through a server action, code is the next:

for rec in record:

    inicio = rec.date_start

    fin = inicio + datetime.timedelta(days=20)


    fechas = []

    while inicio <= fin:

        if inicio.weekday() in [5, 6]:

            fechas.append(inicio)

        inicio += datetime.timedelta(days=1)

        

    #raise UserError(fechas)

    forms = []

    for fecha in fechas:

        form = {

            'name': 'Entrada',

            'employee_id': rec.x_studio_empleado,

            'work_entry_type_id': 1,

            'date_start': fecha,

            'date_stop': (fecha + datetime.timedelta(minutes=120))

        }

        forms.append(form)

        

    for formi in forms:

        record.env['hr.work.entry'].create(formi)

my intention is to create work entry for new employee so i can take in account weekends for payroll


I'm getting the next error:

ValueError: <class 'psycopg2.ProgrammingError'>: "can't adapt type 'hr.employee'" while evaluating

Do you know o have any idea how can i fix this.

appreciate the help in advance, ty

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

for rec in record:

    inicio = rec.date_start

    fin = inicio + datetime.timedelta(days=20)

    fechas = []

    while inicio <= fin:

        if inicio.weekday() in [5, 6]:  # 5 and 6 represent Saturday and Sunday

            fechas.append(inicio)

        inicio += datetime.timedelta(days=1)

    forms = []

    for fecha in fechas:

        form = {

            'name': 'Entrada',

            'employee_id': rec.x_studio_empleado.id,  # Pass the employee ID

            'work_entry_type_id': 1,

            'date_start': fecha,

            'date_stop': (fecha + datetime.timedelta(minutes=120))

        }

        forms.append(form)

    for formi in forms:

        record.env['hr.work.entry'].create(formi)



Update the employee_id field in your code to use .id

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

thank you! I actually had to use id but i got another error solved with making date to datetime
for rec in record:
inicio = rec.date_start
fin = inicio + datetime.timedelta(days=366)

fechas = []
while inicio <= fin:
if inicio.weekday() in [0, 6]:
fechas.append(inicio)
inicio += datetime.timedelta(days=1)

#raise UserError(fechas)
forms = []
for fecha in fechas:
newFecha = datetime.datetime.combine(fecha, datetime.time())
form = {
'name': 'Entrada',
'employee_id': rec.x_studio_empleado.id,
'work_entry_type_id': 1,
'date_start': (newFecha - datetime.timedelta(hours=10)),
'date_stop': newFecha
}
forms.append(form)

for formi in forms:
record.env['hr.work.entry'].create(formi)

thats my code if its any use for anyone

Related Posts Replies Views Activity
1
thg 2 22
2042
1
thg 7 24
5701
0
thg 11 15
2790
0
thg 3 15
3396
1
thg 3 15
2510