This question has been flagged

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!

Avatar
Discard

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

Author

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