Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
3256 Vizualizări

I need to check that within my 'appointment' model does not coincide the time, the doctor and the day. That is, the 'appointments' do not coincide. I have done this but it does not work for me. Would someone know how to do it?

class centromedico_appointments(models.Model):

    _name = 'centromedico.appointments'


    datea = fields.Date(string="Fecha consulta", required=True)

   timea = fields.Float(string="Hora consulta", required=True)

   doctora = fields.Many2one('centromedico.medicos', string="Doctor/a", required=True, ondelete="cascade")


    @api.depends('fconsulta', 'hconsulta', 'cdoctores')

    def _uniqueappointment(self):

        for C in self:

            if C.datea  == centromedico.datea and C.timea == centromedico.timea and C.doctora == centromedico.doctora: 

                raise exceptions.ValidationError("This doctor already has an appointment at that time that day")


Imagine profil
Abandonează
Cel mai bun răspuns

The comparison with date field you have done is absolutely wrong. The odoo DB stores the date or datetime field as a string. So you have to parse the date fields before comparison. If you are not parsing the string to date object then the system compares str() == str() and always returns True. I can give you examples fo parsing a string to date or datetime object.

EG:

str_to_date = fields.Date.from_string(field_name) # '12/02/2019'  --> Date(12, 02, 2019)
str_to_datetime = fields.Datetime.from_string(field_name) # '12/02/2019 08:50:00' --> Datetime(12, 02, 2019, 08, 50, 00)
Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
2
iun. 19
3971
0
iun. 20
3959
1
mai 19
3635
2
iul. 24
14098
1
iul. 21
8289