Mercurial > hgweb > health
changeset 4847:e3ebcf694ab0
task #16043: Migration to GNU Health 4.0: migration of health_calendar
| author | Luis Falcon <falcon@gnuhealth.org> |
|---|---|
| date | Wed, 12 Jan 2022 14:03:49 +0000 |
| parents | f763345104d5 |
| children | 07e74f1d3174 |
| files | tryton/health_calendar/data/messages/messages.xml tryton/health_calendar/exceptions.py tryton/health_calendar/health_calendar.py tryton/health_calendar/tryton.cfg tryton/health_calendar/wizard/wizard_health_calendar.py |
| diffstat | 5 files changed, 84 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/tryton/health_calendar/data/messages/messages.xml @@ -0,0 +1,16 @@ +<?xml version="1.0"?> +<!-- This file is part of GNU Health. The COPYRIGHT file at the top level of +this repository contains the full copyright notices and license terms. --> +<tryton> + <data grouped="1"> + <record model="ir.message" id="msg_no_company_timezone"> + <field name="text">You need to define a timezone for this company before creating a work schedule</field> + </record> + <record model="ir.message" id="msg_end_before_start"> + <field name="text">End date before start</field> + </record> + <record model="ir.message" id="msg_period_too_long"> + <field name="text">The schedule period should be less than 31 days</field> + </record> + </data> +</tryton>
new file mode 100644 --- /dev/null +++ b/tryton/health_calendar/exceptions.py @@ -0,0 +1,16 @@ +# This file is part of GNU Health. The COPYRIGHT file at the top level of +# this repository contains the full copyright notices and license terms. +from trytond.exceptions import UserError, UserWarning +from trytond.model.exceptions import ValidationError + + +class NoCompanyTimezone(ValidationError): + pass + + +class EndDateBeforeStart(ValidationError): + pass + + +class PeriodTooLong(ValidationError): + pass
--- a/tryton/health_calendar/health_calendar.py +++ b/tryton/health_calendar/health_calendar.py @@ -2,11 +2,10 @@ ############################################################################## # # GNU Health: The Free Health and Hospital Information System -# # CALENDAR PACKAGE # -# Copyright (C) 2008-2018 Luis Falcon <lfalcon@gnusolidario.org> -# Copyright (C) 2011-2018 GNU Solidario <health@gnusolidario.org> +# Copyright (C) 2008-2022 Luis Falcon <lfalcon@gnusolidario.org> +# Copyright (C) 2011-2022 GNU Solidario <health@gnusolidario.org> # Copyright (C) 2011-2014 Sebastián Marró <smarro@thymbra.com> # # This program is free software: you can redistribute it and/or modify @@ -35,7 +34,8 @@ __name__ = "res.user" use_caldav = fields.Boolean('CalDAV', help="The user has a CalDav account") - calendar = fields.Many2One('calendar.calendar', 'Calendar', + calendar = fields.Many2One( + 'calendar.calendar', 'Calendar', states={ 'invisible': Not(Bool(Eval('use_caldav'))), 'required': Bool(Eval('use_caldav')), @@ -95,7 +95,7 @@ Healthprof = pool.get('gnuhealth.healthprofessional') for appointment in appointments: - #Update caldav event + # Update caldav event if appointment.event and ('healthprof' not in values): if 'appointment_date' in values: Event.write([appointment.event], { @@ -116,13 +116,13 @@ }) else: - #Move the event to the new health professional + # Move the event to the new health professional if appointment.event and ('healthprof' in values): current_event = [appointment.event] if appointment.healthprof.name.internal_user: healthprof = Healthprof(values['healthprof']) if healthprof.name.internal_user.calendar: - #Health professional has calendar + # Health professional has calendar patient = appointment.patient.name.rec_name comments = '' if 'comments' in values: @@ -134,9 +134,11 @@ else: appointment_date = appointment.appointment_date if 'appointment_date_end' in values: - appointment_date_end = values['appointment_date_end'] + appointment_date_end = \ + values['appointment_date_end'] else: - appointment_date_end = appointment.appointment_date_end + appointment_date_end = \ + appointment.appointment_date_end events = Event.create([{ 'dtstart': appointment_date, 'dtend': appointment_date_end,
--- a/tryton/health_calendar/tryton.cfg +++ b/tryton/health_calendar/tryton.cfg @@ -1,8 +1,9 @@ [tryton] -version=3.8.0 +version=3.9.0 depends: health - calendar + health_caldav xml: health_calendar_view.xml + data/messages/messages.xml wizard/health_calendar_wizard.xml
--- a/tryton/health_calendar/wizard/wizard_health_calendar.py +++ b/tryton/health_calendar/wizard/wizard_health_calendar.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- ############################################################################## # # GNU Health: The Free Health and Hospital Information System @@ -26,19 +25,29 @@ from trytond.pyson import PYSONEncoder from trytond.pool import Pool from trytond.transaction import Transaction +from trytond.i18n import gettext __all__ = ['CreateAppointmentStart', 'CreateAppointment'] +from ..exceptions import ( + NoCompanyTimezone, + EndDateBeforeStart, + PeriodTooLong + ) + class CreateAppointmentStart(ModelView): 'Create Appointments Start' __name__ = 'gnuhealth.calendar.create.appointment.start' - healthprof = fields.Many2One('gnuhealth.healthprofessional', 'Health Prof', + healthprof = fields.Many2One( + 'gnuhealth.healthprofessional', 'Health Prof', required=True) - specialty = fields.Many2One('gnuhealth.specialty', 'Specialty', + specialty = fields.Many2One( + 'gnuhealth.specialty', 'Specialty', required=True) - institution = fields.Many2One('gnuhealth.institution', 'Institution', + institution = fields.Many2One( + 'gnuhealth.institution', 'Institution', required=True) date_start = fields.Date('Start Date', required=True) date_end = fields.Date('End Date', required=True) @@ -71,7 +80,8 @@ 'Create Appointment' __name__ = 'gnuhealth.calendar.create.appointment' - start = StateView('gnuhealth.calendar.create.appointment.start', + start = StateView( + 'gnuhealth.calendar.create.appointment.start', 'health_calendar.create_appointment_start_view_form', [ Button('Cancel', 'end', 'tryton-cancel'), Button('Create', 'create_', 'tryton-ok', default=True), @@ -79,18 +89,6 @@ create_ = StateTransition() open_ = StateAction('health.action_gnuhealth_appointment_view') - @classmethod - def __setup__(cls): - super(CreateAppointment, cls).__setup__() - cls._error_messages.update({ - 'no_company_timezone': - 'You need to define a timezone for this company' - ' before creating a work schedule.\n\n' - 'Party > Configuration > Companies', - 'end_before_start': 'End date before start', - 'period_too_long': 'The schedule period should be < 31 days', - }) - def transition_create_(self): pool = Pool() Appointment = pool.get('gnuhealth.appointment') @@ -103,39 +101,46 @@ if company.timezone: timezone = pytz.timezone(company.timezone) else: - self.raise_user_error('no_company_timezone') + raise NoCompanyTimezone( + gettext('health_calendar.no_company_timezone') + ) appointments = [] # Iterate over days day_count = (self.start.date_end - self.start.date_start).days + 1 - + # Validate dates if (self.start.date_start and self.start.date_end): if (self.start.date_end < self.start.date_start): - self.raise_user_error('end_before_start') + raise EndDateBeforeStart( + gettext('health_calendar.msg_end_before_start') + ) if (day_count > 31): - self.raise_user_error('period_too_long') - - for single_date in (self.start.date_start + timedelta(n) - for n in range(day_count)): + raise PeriodTooLong( + gettext('health_calendar.msg_period_too_long') + ) + + for single_date in ( + self.start.date_start + timedelta(n) + for n in range(day_count)): if ((single_date.weekday() == 0 and self.start.monday) - or (single_date.weekday() == 1 and self.start.tuesday) - or (single_date.weekday() == 2 and self.start.wednesday) - or (single_date.weekday() == 3 and self.start.thursday) - or (single_date.weekday() == 4 and self.start.friday) - or (single_date.weekday() == 5 and self.start.saturday) - or (single_date.weekday() == 6 and self.start.sunday)): + or (single_date.weekday() == 1 and self.start.tuesday) + or (single_date.weekday() == 2 and self.start.wednesday) + or (single_date.weekday() == 3 and self.start.thursday) + or (single_date.weekday() == 4 and self.start.friday) + or (single_date.weekday() == 5 and self.start.saturday) + or (single_date.weekday() == 6 and self.start.sunday)): # Iterate over time dt = datetime.combine( single_date, self.start.time_start) dt = timezone.localize(dt) - dt = dt.astimezone(pytz.utc) + dt = dt.astimezone(pytz.utc) dt_end = datetime.combine( single_date, self.start.time_end) dt_end = timezone.localize(dt_end) - dt_end = dt_end.astimezone(pytz.utc) + dt_end = dt_end.astimezone(pytz.utc) while dt < dt_end: appointment = { 'healthprof': self.start.healthprof.id, @@ -143,7 +148,7 @@ 'institution': self.start.institution.id, 'appointment_date': dt, 'appointment_date_end': dt + - timedelta(minutes=self.start.appointment_minutes), + timedelta(minutes=self.start.appointment_minutes), 'state': 'free', } appointments.append(appointment)
