diff --git a/__init__.py b/__init__.py index 812c5ca..7609c0a 100644 --- a/__init__.py +++ b/__init__.py @@ -1,20 +1,20 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. from trytond.pool import Pool -import location -import configuration -import room -import booking -import operation -import housekeeping -import company -import city -import party -import channel -import product -import sale -import service -import policy +from . import location +from . import configuration +from . import room +from . import booking +from . import operation +from . import housekeeping +from . import company +from . import city +from . import party +from . import channel +from . import product +from . import sale +from . import service +from . import policy def register(): diff --git a/booking.py b/booking.py index 64d449d..4209459 100644 --- a/booking.py +++ b/booking.py @@ -10,15 +10,8 @@ from trytond.report import Report from trytond.pyson import Eval, If, In, Get, Not, Or, Equal, Bool from trytond.transaction import Transaction from trytond.pool import Pool - - -__all__ = [ - 'Booking', 'BookingLine', 'BookingReport', 'SelectRooms', 'SelectRoomsAsk', - 'BookingVoucher', 'RoomsOccupancy', 'RoomsOccupancyStart', - 'RoomsOccupancyReport', 'GuestsListReport', 'GuestsListStart', - 'RegistrationCardReport', 'BookingForecastReport', 'GuestsList', - 'Guest', 'BookingDailyStart', 'BookingDaily', 'BookingDailyReport' -] +from trytond.model.exceptions import AccessError +from trytond.i18n import gettext STATE = [ (None, ''), @@ -283,19 +276,6 @@ class Booking(Workflow, ModelSQL, ModelView): 'invisible': Eval('state') != 'confirmed' }, }) - cls._error_messages.update({ - 'invalid_number_principal_guest': ('Must exist one principal guest'), - 'payterm_missing': ('The payment term is missing!'), - 'check_time_not_configured': ('The check out time is not configured!'), - 'invalid_arrival_date': ('You cannot check in before the reserved date!'), - 'missing_main_guest': ('Missing main guest in lines!'), - 'missing_select_room': ('Missing select room!'), - 'missing_default_configuration': ('Missing default configuration sequence!'), - 'payterm_missing': ('The payment term is missing!'), - 'room_no_clean': ('The room %s is not clean!'), - 'missing_sequence_registration': ('Missing the configuration of \ - registration card sequence!'), - }) @classmethod def trigger_create(cls, records): @@ -483,14 +463,13 @@ class Booking(Workflow, ModelSQL, ModelView): Fill the number field with the booking sequence """ pool = Pool() - Sequence = pool.get('ir.sequence') Config = pool.get('hotel.configuration') config = Config.get_configuration() for booking in bookings: if booking.number or not config.booking_sequence: continue - number = Sequence.get_id(config.booking_sequence.id) + number = config.booking_sequence.get() cls.write([booking], {'number': number}) def cancel_occupancy(self): @@ -505,7 +484,6 @@ class Booking(Workflow, ModelSQL, ModelView): Fill the number field for registration card with sequence """ pool = Pool() - Sequence = pool.get('ir.sequence') Config = pool.get('hotel.configuration') config = Config.get_configuration() @@ -513,8 +491,8 @@ class Booking(Workflow, ModelSQL, ModelView): if booking.registration_card: continue if not config.registration_card_sequence: - cls.raise_user_error('missing_sequence_registration') - number = Sequence.get_id(config.registration_card_sequence.id) + raise AccessError(gettext('hotel.msg_missing_sequence_registration')) + number = config.registration_card_sequence.get() cls.write([booking], {'registration_card': number}) def delete_occupancy(self): @@ -530,7 +508,7 @@ class Booking(Workflow, ModelSQL, ModelView): config = Config.get_configuration() if config.check_out_time is None or config.check_in_time is None: - self.raise_user_error('check_time_not_configured') + raise AccessError(gettext('hotel.msg_check_time_not_configured')) if self.invoice_method == 'by_booking': to_create = [(self.party, l, l.product.id, l.unit_price) for l in self.lines] @@ -558,7 +536,7 @@ class Booking(Workflow, ModelSQL, ModelView): ]) for hk in housekeepings: if hk.room.id in rooms_ids: - self.raise_user_error('room_no_clean', hk.room.name) + raise AccessError(gettext('hotel.msg_room_no_clean', s=hk.room.name)) def get_context_price(self, product): context = {} @@ -697,7 +675,7 @@ class Booking(Workflow, ModelSQL, ModelView): self.get_message('El usuario no tiene un correo asociado.') def get_message(self, message): - self.raise_user_error(message) + raise AccessError(gettext('hotel.msg_error', s=message)) class BookingLine(ModelSQL, ModelView): @@ -755,17 +733,6 @@ class BookingLine(ModelSQL, ModelView): 'nationality', 'origin_country', 'target_country', 'registration_state', 'guests' ], - cls._error_messages.update({ - 'invalid_number_guests': ('Invalid number of guests for ' - 'the room %s.'), - 'accommodation_not_defined': ('The room %s has not accommodation'), - 'invalid_date': ('Departure date must be greater \ - that arrival date'), - 'occupied_room': ('The room is occupied in the date %s'), - 'restring_room': ('The room %s is in restring access for quarantine protocolo!'), - 'missing_confirm_booking': ('Missing Confirm Booking'), - 'reservation_checkin': ('The reservation already has check_in or check_out'), - }) cls._buttons.update({ 'check_in': { 'invisible': Eval('state') == 'confirmed' and @@ -835,11 +802,11 @@ class BookingLine(ModelSQL, ModelView): Booking.set_registration_card_number([record]) line = records[0] if line.state == 'offer': - line.raise_user_error('missing_confirm_booking') + raise AccessError(gettext('hotel.msg_missing_confirm_booking')) if line.main_guest is None: - Booking.raise_user_error('missing_main_guest') + raise AccessError(gettext('hotel.msg_missing_main_guest')) if line.room is None: - Booking.raise_user_error('missing_select_room') + raise AccessError(gettext('hotel.msg_missing_select_room')) record.check_rooms() cls.write([records[0]], {'registration_state': 'check_in'}) record.update_occupancy(state='open',records=records,check=check) @@ -953,11 +920,11 @@ class BookingLine(ModelSQL, ModelView): """ Date = Pool().get('ir.date') if self.registration_state in (['check_in', 'check_out']): - self.raise_user_error('reservation_checkin') + raise AccessError(gettext('hotel.msg_reservation_checkin')) if self.arrival_date < Date.today(): - self.raise_user_error('invalid_arrival_date') + raise AccessError(gettext('hotel.msg_invalid_arrival_date')) if self.arrival_date >= self.departure_date: - self.raise_user_error('invalid_date') + raise AccessError(gettext('hotel.msg_invalid_date')) Operation = Pool().get('hotel.operation') operations = Operation.search([ ('room', '=', self.room.id), @@ -973,7 +940,7 @@ class BookingLine(ModelSQL, ModelView): ]) print(operations) if operations: - self.raise_user_error('occupied_room', self.departure_date) + raise AccessError(gettext('hotel.msg_occupied_room', s=self.departure_date)) config = Pool().get('hotel.configuration')(1) quarantine_days = config.quarantine_rooms room_id = self.room.id @@ -992,7 +959,7 @@ class BookingLine(ModelSQL, ModelView): ]]]]) print(operations) if operations: - self.raise_user_error('restring_room', self.room.name) + raise AccessError(gettext('hotel.msg_restring_room', s=self.room.name)) def get_state(self, name): if self.booking: @@ -1044,8 +1011,8 @@ class BookingReport(Report): __name__ = 'hotel.booking' @classmethod - def get_context(cls, records, data): - report_context = super(BookingReport, cls).get_context(records, data) + def get_context(cls, records, header, data): + report_context = super().get_context(records, header, data) user = Pool().get('res.user')(Transaction().user) report_context['company'] = user.company return report_context @@ -1378,8 +1345,8 @@ class BookingForecastReport(Report): __name__ = 'hotel.booking_forecast.report' @classmethod - def get_context(cls, records, data): - report_context = super(BookingForecastReport, cls).get_context(records, data) + def get_context(cls, records, header, data): + report_context = super().get_context(records, header, data) MAX_DAYS = 30 pool = Pool() Company = pool.get('company.company') @@ -1444,8 +1411,8 @@ class RegistrationCardReport(Report): __name__ = 'hotel.occupancy.registration_card' @classmethod - def get_context(cls, records, data): - report_context = super(RegistrationCardReport, cls).get_context(records, data) + def get_context(cls, records, header, data): + report_context = super().get_context(records, header, data) user = Pool().get('res.user')(Transaction().user) report_context['company'] = user.company return report_context @@ -1493,8 +1460,8 @@ class GuestsListReport(Report): __name__ = 'hotel.guests_list.report' @classmethod - def get_context(cls, records, data): - report_context = super(GuestsListReport, cls).get_context(records, data) + def get_context(cls, records, header, data): + report_context = super().get_context(records, header, data) pool = Pool() Company = pool.get('company.company') Operation = pool.get('hotel.operation') @@ -1574,8 +1541,8 @@ class RoomsOccupancyReport(Report): __name__ = 'hotel.rooms_occupancy.report' @classmethod - def get_context(cls, records, data): - report_context = super(RoomsOccupancyReport, cls).get_context(records, data) + def get_context(cls, records, header, data): + report_context = super().get_context(records, header, data) pool = Pool() Company = pool.get('company.company') Room = pool.get('hotel.room') @@ -1677,8 +1644,8 @@ class BookingDailyReport(Report): __name__ = 'hotel.booking_daily.report' @classmethod - def get_context(cls, records, data): - report_context = super(BookingDailyReport, cls).get_context(records, data) + def get_context(cls, records, header, data): + report_context = super().get_context(records, header, data) pool = Pool() Company = pool.get('company.company') records = BookingLine.search([ diff --git a/company.py b/company.py index 4fc7e9e..2a894f4 100644 --- a/company.py +++ b/company.py @@ -3,8 +3,6 @@ from trytond.model import fields from trytond.pool import PoolMeta -__all__ = ['Company'] - class Company(metaclass=PoolMeta): __name__ = 'company.company' diff --git a/configuration.py b/configuration.py index fc47c38..7f93541 100644 --- a/configuration.py +++ b/configuration.py @@ -3,8 +3,8 @@ from trytond.model import ModelView, ModelSQL, fields from trytond.pyson import Eval, If from trytond.transaction import Transaction - -__all__ = ['Configuration', 'ConfigurationProduct'] +from trytond.model.exceptions import AccessError +from trytond.i18n import gettext class Configuration(ModelSQL, ModelView): @@ -61,9 +61,6 @@ class Configuration(ModelSQL, ModelView): @classmethod def __setup__(cls): super(Configuration, cls).__setup__() - cls._error_messages.update({ - 'missing_default_configuration': ('Missing default configuration sequence!'), - }) @staticmethod def default_company(): @@ -77,7 +74,7 @@ class Configuration(ModelSQL, ModelView): ('company', '=', company_id) ]) if not config or not config.booking_sequence: - cls.raise_user_error('missing_default_configuration') + raise AccessError(gettext('hotel.missing_default_configuration')) return config diff --git a/exceptions.py b/exceptions.py new file mode 100644 index 0000000..20f4831 --- /dev/null +++ b/exceptions.py @@ -0,0 +1,9 @@ +# This file is part of Tryton. 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 BadOperationError(UserError): + pass diff --git a/housekeeping.py b/housekeeping.py index 073e80d..a462f81 100644 --- a/housekeeping.py +++ b/housekeeping.py @@ -8,12 +8,6 @@ from trytond.transaction import Transaction from datetime import datetime from trytond.pool import Pool -__all__ = [ - 'Housekeeping', 'HotelTask', 'HotelHousekeepingTask', - 'HousekeepingServiceReport', 'HousekeepingService', - 'HousekeepingServiceStart', 'HousekeepingCleaningType' -] - STATES = {'invisible': (Eval('type') != 'service')} @@ -231,8 +225,8 @@ class HousekeepingServiceReport(Report): __name__ = 'hotel.print_housekeeping_service.report' @classmethod - def get_context(cls, records, data): - report_context = super(HousekeepingServiceReport, cls).get_context(records, data) + def get_context(cls, records, header, data): + report_context = super().get_context(records, header, data) pool = Pool() Company = pool.get('company.company') Housekeeping = pool.get('hotel.housekeeping') diff --git a/location.py b/location.py index 92d0050..3c22524 100644 --- a/location.py +++ b/location.py @@ -2,8 +2,6 @@ # this repository contains the full copyright notices and license terms. from trytond.model import ModelView, ModelSQL, fields -__all__ = ['HotelLocation'] - class HotelLocation(ModelSQL, ModelView): "Hotel Location" diff --git a/message.xml b/message.xml new file mode 100644 index 0000000..1eb1384 --- /dev/null +++ b/message.xml @@ -0,0 +1,88 @@ + + + + + + You can not add charges to a sale is closed %s + + + The room %s selected is not occupied + + + Must exist one principal guest + + + The payment term is missing! + + + The check out time is not configured! + + + You cannot check in before the reserved date! + + + Missing main guest in lines! + + + Missing select room! + + + Missing default configuration sequence! + + + The payment term is missing! + + + The room %s is not clean! + + + Missing the configuration of registration card sequence! + + + Invalid number of guests for the room %s. + + + The room %s has not accommodation + + + Departure date must be greater that arrival date + + + The room is occupied in the date %s + + + The room %s is in restring access for quarantine protocolo! + + + Missing Confirm Booking + + + The reservation already has check_in or check_out + + + Error "\n" %s + + + Missing default configuration sequence! + + + The operation for the room %s + + + The operation for the room %s overlaps with another operation! + + + The start date is greater than end date + + + Missing default configuration for check-in time or check-out time! + + + The room is occupied %s + + + Error, Can not select current operation + + + diff --git a/operation.py b/operation.py index 68a736c..48bd921 100644 --- a/operation.py +++ b/operation.py @@ -9,16 +9,8 @@ from trytond.pool import Pool from trytond.report import Report from trytond.wizard import Wizard, StateView, StateAction, Button, StateTransition from trytond.transaction import Transaction - -__all__ = [ - 'Operation', 'OperationLine', 'OperationMaintenance', 'Migration', - 'OpenMigration', 'OpenMigrationStart', 'OperationGuest', 'OperationReport', - 'CheckOutOperation', 'CheckOutOperationFailed', 'ChangeRoomStart', - 'ChangeRoom', 'TransferOperationStart', 'TransferOperation', - 'TransferChargeStart', 'TransferCharge', 'OperationByConsumerReport', - 'OperationBill', 'OperationVoucher', 'StatisticsByMonthStart', - 'StatisticsByMonth', 'StatisticsByMonthReport' -] +from trytond.model.exceptions import AccessError +from trytond.i18n import gettext STATES_OP = { 'readonly': Eval('state').in_(['check_out', 'done', 'cancelled']) @@ -140,14 +132,6 @@ class Operation(Workflow, ModelSQL, ModelView): @classmethod def __setup__(cls): super(Operation, cls).__setup__() - cls._error_messages.update({ - 'overlap_operation_line': ('The operation for the room %s ' - 'overlaps with another operation!'), - 'invalid_date_range': ('The start date is greater than end date'), - 'missing_default_configuration': ('Missing default configuration for check-in ' - 'time or check-out time!'), - 'occupied_room': ('The room is occupied %s') - }) cls._transitions |= set(( ('draft', 'open'), ('draft', 'cancelled'), @@ -195,7 +179,7 @@ class Operation(Workflow, ModelSQL, ModelView): ] ]]]) if operations: - cls.raise_user_error('occupied_room', r.room.name) + raise AccessError(gettext('hotel.msg_occupied_room', s=r.room.name)) @classmethod def occupancy_rate(cls, start, end): @@ -367,7 +351,7 @@ class Operation(Workflow, ModelSQL, ModelView): config = Configuration.get_configuration() if not config.cleaning_check_in or not config.cleaning_check_out \ or not config.cleaning_occupied: - self.raise_user_error('missing_cleaning_configuration') + raise AccessError(gettext('hotel.msg_missing_cleaning_configuration')) if state == 'check_in': values = { 'availability': 'occupied', @@ -384,7 +368,7 @@ class Operation(Workflow, ModelSQL, ModelView): ('room', '=', self.room.id) ]) if not housekeepings: - self.raise_user_error('missing_configuration_housekeeping_rooms') + raise AccessError(gettext('hotel.msg_missing_configuration_housekeeping_rooms')) Housekeeping.write(housekeepings, values) # def get_sale(self, name=None): @@ -491,7 +475,7 @@ class Operation(Workflow, ModelSQL, ModelView): """ if start_date >= end_date: - cls.raise_user_error('invalid_date_range') + raise AccessError(gettext('hotel.msg_invalid_date_range')) # define the domain of the operations that find a # room to be available @@ -529,7 +513,7 @@ class Operation(Workflow, ModelSQL, ModelView): start_date, end_date, rooms_ids, operation ) if room.id not in available_rooms: - cls.raise_user_error('overlap_operation_line', (room.name,)) + raise AccessError(gettext('hotel.overlap_operation_line', s=room.name)) def get_nights_quantity(self, name=None): """ @@ -1051,8 +1035,8 @@ class Migration(Report): __name__ = 'hotel.migration' @classmethod - def get_context(cls, records, data): - report_context = super(Migration, cls).get_context(records, data) + def get_context(cls, records, header, data): + report_context = super().get_context(records, header, data) Line = Pool().get('hotel.booking.line') start = data['start_date'] end = data['end_date'] @@ -1067,8 +1051,8 @@ class OperationReport(Report): __name__ = 'hotel.operation' @classmethod - def get_context(cls, records, data): - report_context = super(OperationReport, cls).get_context(records, data) + def get_context(cls, records, header, data): + report_context = super().get_context(records, header, data) user = Pool().get('res.user')(Transaction().user) report_context['company'] = user.company return report_context @@ -1237,9 +1221,6 @@ class TransferOperation(Wizard): @classmethod def __setup__(cls): super(TransferOperation, cls).__setup__() - cls._error_messages.update({ - 'operation_current': ('Error, Can not select current operation'), - }) def transition_transfer(self): pool = Pool() @@ -1248,7 +1229,7 @@ class TransferOperation(Wizard): current_op = Operation(Transaction().context.get('active_id')) target_op = self.start.operation if target_op.id == current_op.id: - self.raise_user_error('operation_current') + raise AccessError(gettext('hotel.msg_operation_current')) lines_to_transfer = [] if self.start.tranfer_charges: @@ -1303,8 +1284,8 @@ class OperationByConsumerReport(Report): __name__ = 'hotel.operation.line' @classmethod - def get_context(cls, records, data): - report_context = super(OperationByConsumerReport, cls).get_context(records, data) + def get_context(cls, records, header, data): + report_context = super().get_context(records, header, data) pool = Pool() Operation = pool.get('hotel.operation') user = pool.get('res.user')(Transaction().user) @@ -1395,8 +1376,8 @@ class StatisticsByMonthReport(Report): __name__ = 'hotel.statistics_by_month.report' @classmethod - def get_context(cls, records, data): - report_context = super(StatisticsByMonthReport, cls).get_context(records, data) + def get_context(cls, records, header, data): + report_context = super().get_context(records, header, data) Operation = Pool().get('hotel.operation') Period = Pool().get('account.period') Company = Pool().get('company.company') diff --git a/party.py b/party.py index 0c9cd0c..5ab9422 100644 --- a/party.py +++ b/party.py @@ -3,12 +3,10 @@ #and license terms. from trytond.pool import PoolMeta, Pool from trytond.model import fields, ModelView -from trytond.wizard import Wizard, StateView, Button, StateTransition, StateReport +from trytond.wizard import Wizard, StateView, Button, StateTransition from trytond.transaction import Transaction - - -__all__ = ['Party', 'CreateGuest', 'CreateGuestStart'] - +from trytond.model.exceptions import AccessError +from trytond.i18n import gettext TYPE = [ ('', ''), @@ -169,4 +167,4 @@ class CreateGuest(Wizard): return 'end' def get_message(self, message): - self.raise_user_error(message) + raise AccessError(gettext('hotel.msg_error', s=message)) diff --git a/policy.py b/policy.py index 66e3705..e695bbf 100644 --- a/policy.py +++ b/policy.py @@ -2,8 +2,6 @@ # this repository contains the full copyright notices and license terms. from trytond.model import ModelView, ModelSQL, fields -__all__ = ['HotelPolicyCancellation'] - class HotelPolicyCancellation(ModelSQL, ModelView): 'Hotel Policy Cancellation' diff --git a/product.py b/product.py index f4d1110..fbc2dc0 100755 --- a/product.py +++ b/product.py @@ -5,8 +5,6 @@ from trytond.model import fields from trytond.pool import PoolMeta from trytond.pyson import Eval -__all__ = ['Template'] - KIND = [ ('', ''), diff --git a/room.py b/room.py index a672b75..a11f85b 100644 --- a/room.py +++ b/room.py @@ -3,7 +3,6 @@ from trytond.model import ModelView, ModelSQL, fields from trytond.pyson import Eval -__all__ = ['Room', 'Amenities', 'RoomClassification', 'RoomAmenities', 'RoomTemplate'] STATES = {'readonly': (Eval('state') != 'draft')} diff --git a/sale.py b/sale.py index d94e541..6189c77 100644 --- a/sale.py +++ b/sale.py @@ -8,9 +8,6 @@ from trytond.report import Report from trytond.model import ModelView, fields from trytond.transaction import Transaction -__all__ = ['InvoiceIncomeDaily', 'InvoiceIncomeDailyStart', - 'InvoiceIncomeDailyReport', 'InvoiceSimplifiedReport'] - _ZERO = Decimal(0) @@ -61,8 +58,8 @@ class InvoiceIncomeDailyReport(Report): __name__ = 'hotel.invoice_income_daily_report' @classmethod - def get_context(cls, records, data): - report_context = super(InvoiceIncomeDailyReport, cls).get_context(records, data) + def get_context(cls, records, header, data): + report_context = super().get_context(records, header, data) pool = Pool() Invoice = pool.get('account.invoice') Company = pool.get('company.company') @@ -197,8 +194,8 @@ class InvoiceSimplifiedReport(Report): __name__ = 'account.invoice_simplified' @classmethod - def get_context(cls, records, data): - report_context = super(InvoiceSimplifiedReport, cls).get_context(records, data) + def get_context(cls, records, header, data): + report_context = super().get_context(records, header, data) Company = Pool().get('company.company') categories = {} diff --git a/service.py b/service.py index 9a8132e..18378f0 100644 --- a/service.py +++ b/service.py @@ -7,9 +7,8 @@ from trytond.pyson import Eval from trytond.modules.company import CompanyReport from trytond.wizard import Wizard, StateView, Button, StateTransition from trytond.transaction import Transaction - -__all__ = ['Service', 'ServiceLine', 'ServiceReport', 'ServiceKind', - 'CreateDailyServices', 'CreateDailyServicesStart'] +from trytond.model.exceptions import AccessError +from trytond.i18n import gettext STATES = { 'readonly': Eval('state') == 'checked' @@ -18,6 +17,7 @@ STATES_LINE = { 'readonly': Eval('state') == 'loaded' } + class ServiceKind(ModelSQL, ModelView): 'Service Kind' __name__ = 'hotel.service.kind' @@ -184,10 +184,6 @@ class ServiceLine(Workflow, ModelSQL, ModelView): 'invisible': Eval('state') != 'draft', }, }) - cls._error_messages.update({ - 'sale_closed': ('You can not add charges to a sale is closed %s'), - 'room_not_occupied': ('The room %s selected is not occupied'), - }) @staticmethod def default_quantity(): @@ -288,8 +284,8 @@ class ServiceReport(CompanyReport): __name__ = 'hotel.service' @classmethod - def get_context(cls, records, data): - report_context = super(ServiceReport, cls).get_context(records, data) + def get_context(cls, records, header, data): + report_context = super().get_context(records, header, data) return report_context diff --git a/tryton.cfg b/tryton.cfg index 8fe01f4..3d78746 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -1,5 +1,5 @@ [tryton] -version=5.0.4 +version=6.0.0 depends: party company