콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다

Hello everybody, I'm having a problem with a function in Odoo, in my module You reserve a specifics rooms in a many2many (with checkbox widget) field, and a begin/end date in a one2many field (this one2many is for an auxiliar table that store only dates and the rooms), my function checks if you reserve the same room in the same date inside that another record in the database table and throw a error.

This is my function:


@api.model

def create(self, values):

flag = False

solicitudes = self.env['hr.infraestructuras.fech'].search([]) #The module table where I search the existed records

fmt = '%Y-%m-%d'

aux = datetime.datetime.strptime(values['x_fecha_inicio'], fmt) #Begin date that you choose

aux2 = datetime.datetime.strptime(values['x_fecha_fin'], fmt) #End date that you choose

for soli in solicitudes:

d1 = datetime.datetime.strptime(soli.x_fecha_inicio, fmt) #Begin date of each record of the table

d2 = datetime.datetime.strptime(soli.x_fecha_fin, fmt) #End date of each record of the table

dates_btwn = d1

self.env.cr.execute(

""" SELECT

hr_infraestructuras_instalaciones_id AS insta

FROM

hr_infraestructuras_fech_hr_infraestructuras_instalaciones_rel relacion

WHERE

hr_infraestructuras_fech_id = %s """, (soli.id,))

result = self.env.cr.dictfetchall()

while dates_btwn <= d2:

if aux == dates_btwn or aux2 == dates_btwn:

for instalacion_seleccionada in self.x_instalaciones_usadas:

for r in result:

if r == instalacion_seleccionada.id:

flag = True

cadena = str(dates_btwn)

raise UserError("El día "+cadena+" ya se han reservado las siguientes salas")

else:

dates_btwn = dates_btwn + relativedelta(days=1)

if flag == False:

return super(Hrinfraestructuras_fech, self).create(values)




This function searchs the rooms that are used by a record in a range of dates, but when I create the record my odoo is stuck like charging the page and I don't know what i'm doing bad

Could someone help me? Thanks!

아바타
취소

it is not odoo, it is your code.. whats the error log?

작성자

In my log there isn't a error about this, but the page is stuck charging like 30 minutes and nothing happens

관련 게시물 답글 화면 활동
0
10월 22
3174
0
2월 19
3317
2
4월 15
5149
0
5월 24
1149
0
11월 23
1198