From d5685382638cadfca007f4bd6f38e648bfec3267 Mon Sep 17 00:00:00 2001 From: Pablo Date: Mon, 16 Sep 2019 12:15:48 +0200 Subject: [PATCH] [REF] attribute and methods order guidelines Business fields and methods arranged by importance --- hotel/models/hotel_room.py | 2 +- hotel/models/hotel_room_type.py | 3 +- hotel_calendar/models/bus_hotel_calendar.py | 1 + hotel_calendar/models/hotel_calendar.py | 10 +- .../models/hotel_calendar_management.py | 125 +++++++++--------- .../models/inherited_hotel_folio.py | 7 +- .../models/inherited_hotel_reservation.py | 123 ++++++++--------- ...erited_hotel_room_type_restriction_item.py | 1 + .../inherited_product_pricelist_item.py | 1 + .../models/inherited_res_company.py | 3 +- .../models/ir_actions_act_window_view.py | 1 + hotel_calendar/models/ir_ui_view.py | 1 + 12 files changed, 147 insertions(+), 131 deletions(-) diff --git a/hotel/models/hotel_room.py b/hotel/models/hotel_room.py index e4e2c2230..b04363491 100644 --- a/hotel/models/hotel_room.py +++ b/hotel/models/hotel_room.py @@ -14,8 +14,8 @@ class HotelRoom(models.Model): _description = 'Hotel Room' _order = "sequence, room_type_id, name" + # Fields declaration name = fields.Char('Room Name', required=True) - # Relationship between models hotel_id = fields.Many2one('hotel.property', store=True, readonly=True, related='room_type_id.hotel_id') room_type_id = fields.Many2one('hotel.room.type', 'Hotel Room Type', diff --git a/hotel/models/hotel_room_type.py b/hotel/models/hotel_room_type.py index f03549726..ae4dcc293 100644 --- a/hotel/models/hotel_room_type.py +++ b/hotel/models/hotel_room_type.py @@ -15,11 +15,12 @@ class HotelRoomType(models.Model): _inherits = {'product.product': 'product_id'} _order = "sequence, code_type, name" + # Default methods @api.model def _get_default_hotel(self): return self.env.user.hotel_id - # Relationship between models + # Fields declaration product_id = fields.Many2one('product.product', 'Product Room Type', required=True, delegate=True, ondelete='cascade') diff --git a/hotel_calendar/models/bus_hotel_calendar.py b/hotel_calendar/models/bus_hotel_calendar.py index f46b13598..c0bffeef3 100644 --- a/hotel_calendar/models/bus_hotel_calendar.py +++ b/hotel_calendar/models/bus_hotel_calendar.py @@ -20,6 +20,7 @@ class BusHotelCalendar(models.TransientModel): - warn : Show a warning notification - noshow : Don't show any notification ''' + # Business methods @api.model def _generate_reservation_notif(self, vals): user_id = self.env['res.users'].browse(self.env.uid) diff --git a/hotel_calendar/models/hotel_calendar.py b/hotel_calendar/models/hotel_calendar.py index b2932ee77..072fc3456 100644 --- a/hotel_calendar/models/hotel_calendar.py +++ b/hotel_calendar/models/hotel_calendar.py @@ -6,16 +6,20 @@ from odoo.exceptions import ValidationError class HotelCalendar(models.Model): + """ Used to show and filter rooms and reservations in the PMS Calendar. """ _name = 'hotel.calendar' + # Default methods @api.model def _get_default_hotel(self): return self.env.user.hotel_id + # Fields declaration name = fields.Char('Name', required=True) + hotel_id = fields.Many2one('hotel.property', 'Hotel', required=True, ondelete='restrict', + default=_get_default_hotel) + room_type_ids = fields.Many2many('hotel.room.type', string='Room Type') segmentation_ids = fields.Many2many('hotel.room.type.class', string='Segmentation') location_ids = fields.Many2many('hotel.floor', string='Location') amenity_ids = fields.Many2many('hotel.amenity', string='Amenity') - room_type_ids = fields.Many2many('hotel.room.type', string='Room Type') - hotel_id = fields.Many2one('hotel.property', 'Hotel', required=True, ondelete='restrict', - default=_get_default_hotel,) + diff --git a/hotel_calendar/models/hotel_calendar_management.py b/hotel_calendar/models/hotel_calendar_management.py index 670fc346d..7d4379a81 100644 --- a/hotel_calendar/models/hotel_calendar_management.py +++ b/hotel_calendar/models/hotel_calendar_management.py @@ -13,6 +13,17 @@ _logger = logging.getLogger(__name__) class HotelCalendarManagement(models.TransientModel): _name = 'hotel.calendar.management' + # Business methods + @api.multi + def get_hcalendar_settings(self): + return { + 'eday_week': self.env.user.hotel_id.pms_end_day_week, + 'eday_week_offset': self.env.user.hotel_id.pms_end_day_week_offset, + 'days': self.env.user.hotel_id.pms_default_num_days, + 'show_notifications': self.env.user.pms_show_notifications, + 'show_num_rooms': self.env.user.hotel_id.pms_show_num_rooms, + } + @api.model def _get_prices_values(self, price): vals = { @@ -33,59 +44,6 @@ class HotelCalendarManagement(models.TransientModel): } return vals - @api.model - def save_changes(self, pricelist_id, restriction_id, pricelist, - restrictions, availability=False): - room_type_obj = self.env['hotel.room.type'] - product_pricelist_item_obj = self.env['product.pricelist.item'] - room_type_rest_item_obj = self.env['hotel.room.type.restriction.item'] - - # Save Pricelist - for k_price in pricelist.keys(): - room_type_id = room_type_obj.browse([int(k_price)]) - room_type_prod_tmpl_id = room_type_id.product_id.product_tmpl_id - for price in pricelist[k_price]: - price_id = product_pricelist_item_obj.search([ - ('date_start', '>=', price['date']), - ('date_end', '<=', price['date']), - ('pricelist_id', '=', int(pricelist_id)), - ('applied_on', '=', '1_product'), - ('compute_price', '=', 'fixed'), - ('product_tmpl_id', '=', room_type_prod_tmpl_id.id), - ], limit=1) - vals = self._get_prices_values(price) - if not price_id: - vals.update({ - 'date_start': price['date'], - 'date_end': price['date'], - 'pricelist_id': int(pricelist_id), - 'applied_on': '1_product', - 'compute_price': 'fixed', - 'product_tmpl_id': room_type_prod_tmpl_id.id, - }) - price_id = product_pricelist_item_obj.create(vals) - else: - price_id.write(vals) - - # Save Restrictions - for k_res in restrictions.keys(): - for restriction in restrictions[k_res]: - res_id = room_type_rest_item_obj.search([ - ('date', '=', restriction['date']), - ('restriction_id', '=', int(restriction_id)), - ('room_type_id', '=', int(k_res)), - ], limit=1) - vals = self._get_restrictions_values(restriction) - if not res_id: - vals.update({ - 'date': restriction['date'], - 'restriction_id': int(restriction_id), - 'room_type_id': int(k_res), - }) - res_id = room_type_rest_item_obj.create(vals) - else: - res_id.write(vals) - @api.model def _hcalendar_room_json_data(self, rooms): json_data = [] @@ -265,12 +223,55 @@ class HotelCalendarManagement(models.TransientModel): return vals - @api.multi - def get_hcalendar_settings(self): - return { - 'eday_week': self.env.user.hotel_id.pms_end_day_week, - 'eday_week_offset': self.env.user.hotel_id.pms_end_day_week_offset, - 'days': self.env.user.hotel_id.pms_default_num_days, - 'show_notifications': self.env.user.pms_show_notifications, - 'show_num_rooms': self.env.user.hotel_id.pms_show_num_rooms, - } + @api.model + def save_changes(self, pricelist_id, restriction_id, pricelist, + restrictions, availability=False): + room_type_obj = self.env['hotel.room.type'] + product_pricelist_item_obj = self.env['product.pricelist.item'] + room_type_rest_item_obj = self.env['hotel.room.type.restriction.item'] + + # Save Pricelist + for k_price in pricelist.keys(): + room_type_id = room_type_obj.browse([int(k_price)]) + room_type_prod_tmpl_id = room_type_id.product_id.product_tmpl_id + for price in pricelist[k_price]: + price_id = product_pricelist_item_obj.search([ + ('date_start', '>=', price['date']), + ('date_end', '<=', price['date']), + ('pricelist_id', '=', int(pricelist_id)), + ('applied_on', '=', '1_product'), + ('compute_price', '=', 'fixed'), + ('product_tmpl_id', '=', room_type_prod_tmpl_id.id), + ], limit=1) + vals = self._get_prices_values(price) + if not price_id: + vals.update({ + 'date_start': price['date'], + 'date_end': price['date'], + 'pricelist_id': int(pricelist_id), + 'applied_on': '1_product', + 'compute_price': 'fixed', + 'product_tmpl_id': room_type_prod_tmpl_id.id, + }) + price_id = product_pricelist_item_obj.create(vals) + else: + price_id.write(vals) + + # Save Restrictions + for k_res in restrictions.keys(): + for restriction in restrictions[k_res]: + res_id = room_type_rest_item_obj.search([ + ('date', '=', restriction['date']), + ('restriction_id', '=', int(restriction_id)), + ('room_type_id', '=', int(k_res)), + ], limit=1) + vals = self._get_restrictions_values(restriction) + if not res_id: + vals.update({ + 'date': restriction['date'], + 'restriction_id': int(restriction_id), + 'room_type_id': int(k_res), + }) + res_id = room_type_rest_item_obj.create(vals) + else: + res_id.write(vals) diff --git a/hotel_calendar/models/inherited_hotel_folio.py b/hotel_calendar/models/inherited_hotel_folio.py index e5aee878b..69a5165e5 100644 --- a/hotel_calendar/models/inherited_hotel_folio.py +++ b/hotel_calendar/models/inherited_hotel_folio.py @@ -6,6 +6,7 @@ from odoo import models, api, _ class HotelFolio(models.Model): _inherit = 'hotel.folio' + # CRUD methods @api.multi def write(self, vals): ret = super(HotelFolio, self).write(vals) @@ -19,11 +20,11 @@ class HotelFolio(models.Model): @api.multi def unlink(self): for record in self: - record.room_lines.send_bus_notification('unlink', - 'warn', - _("Folio Deleted")) + record.room_lines.send_bus_notification('unlink', 'warn', + _("Folio Deleted")) return super(HotelFolio, self).unlink() + # Business methods @api.multi def compute_amount(self): ret = super(HotelFolio, self).compute_amount() diff --git a/hotel_calendar/models/inherited_hotel_reservation.py b/hotel_calendar/models/inherited_hotel_reservation.py index 124d98294..ed3416e23 100644 --- a/hotel_calendar/models/inherited_hotel_reservation.py +++ b/hotel_calendar/models/inherited_hotel_reservation.py @@ -12,11 +12,13 @@ _logger = logging.getLogger(__name__) class HotelReservation(models.Model): _inherit = 'hotel.reservation' + # Fields declaration reserve_color = fields.Char(compute='_compute_color', string='Color', store=True) reserve_color_text = fields.Char(compute='_compute_color', string='Color', store=True) + # Business methods @api.multi def _generate_color(self): self.ensure_one() @@ -65,6 +67,47 @@ class HotelReservation(models.Model): 'reserve_color_text': colors[1], }) + @api.model + def get_hcalendar_settings(self): + type_move = self.env.user.hotel_id.pms_type_move + return { + 'divide_rooms_by_capacity': self.env.user.hotel_id.pms_divide_rooms_by_capacity, + 'eday_week': self.env.user.hotel_id.pms_end_day_week, + 'eday_week_offset': self.env.user.hotel_id.pms_end_day_week_offset, + 'days': self.env.user.hotel_id.pms_default_num_days, + 'allow_invalid_actions': type_move == 'allow_invalid', + 'assisted_movement': type_move == 'assisted', + 'default_arrival_hour': self.env.user.hotel_id.default_arrival_hour, + 'default_departure_hour': self.env.user.hotel_id.default_departure_hour, + 'show_notifications': self.env.user.pms_show_notifications, + 'show_pricelist': self.env.user.pms_show_pricelist, + 'show_availability': self.env.user.pms_show_availability, + 'show_num_rooms': self.env.user.hotel_id.pms_show_num_rooms, + } + + @api.model + def _hcalendar_room_data(self, rooms): + _logger.warning('_found [%s] rooms for hotel [%s]', len(rooms), self.env.user.hotel_id.id) + # TODO: refactoring res.config.settings', 'default_pricelist_id' by the current hotel.property.pricelist_id + pricelist_id = self.env.user.hotel_id.default_pricelist_id.id + json_rooms = [ + { + 'id': room.id, + 'name': room.name, + 'capacity': room.capacity, + 'class_name': room.room_type_id.class_id.name, + 'class_id': room.room_type_id.class_id.id, + 'shared_id': room.shared_room_id, + 'price': room.room_type_id + and ['pricelist', room.room_type_id.id, pricelist_id, + room.room_type_id.name] or 0, + 'room_type_name': room.room_type_id.name, + 'room_type_id': room.room_type_id.id, + 'floor_id': room.floor_id.id, + 'amentity_ids': room.room_type_id.room_amenity_ids.ids, + } for room in rooms] + return json_rooms + @api.model def _hcalendar_reservation_data(self, reservations): _logger.warning('_found [%s] reservations for hotel [%s]', len(reservations), self.env.user.hotel_id.id) @@ -126,43 +169,7 @@ class HotelReservation(models.Model): 'services': reserv['services'], } }) - return (json_reservations, json_reservation_tooltips) - - @api.model - def _hcalendar_room_data(self, rooms): - _logger.warning('_found [%s] rooms for hotel [%s]', len(rooms), self.env.user.hotel_id.id) - # TODO: refactoring res.config.settings', 'default_pricelist_id' by the current hotel.property.pricelist_id - pricelist_id = self.env.user.hotel_id.default_pricelist_id.id - json_rooms = [ - { - 'id': room.id, - 'name': room.name, - 'capacity': room.capacity, - 'class_name': room.room_type_id.class_id.name, - 'class_id': room.room_type_id.class_id.id, - 'shared_id': room.shared_room_id, - 'price': room.room_type_id - and ['pricelist', room.room_type_id.id, pricelist_id, - room.room_type_id.name] or 0, - 'room_type_name': room.room_type_id.name, - 'room_type_id': room.room_type_id.id, - 'floor_id': room.floor_id.id, - 'amentity_ids': room.room_type_id.room_amenity_ids.ids, - } for room in rooms] - return json_rooms - - @api.model - def _hcalendar_calendar_data(self, calendars): - _logger.warning('_found [%s] calendars for hotel [%s]', len(calendars), self.env.user.hotel_id.id) - return [ - { - 'id': calendar.id, - 'name': calendar.name, - 'segmentation_ids': calendar.segmentation_ids.ids, - 'location_ids': calendar.location_ids.ids, - 'amenity_ids': calendar.amenity_ids.ids, - 'room_type_ids': calendar.room_type_ids.ids, - } for calendar in calendars] + return json_reservations, json_reservation_tooltips @api.model def _hcalendar_event_data(self, events): @@ -177,13 +184,17 @@ class HotelReservation(models.Model): return json_events @api.model - def get_hcalendar_calendar_data(self): - hotel_id = self.env.user.hotel_id.id - calendars = self.env['hotel.calendar'].search([ - ('hotel_id', '=', hotel_id) - ]) - res = self._hcalendar_calendar_data(calendars) - return res + def _hcalendar_calendar_data(self, calendars): + _logger.warning('_found [%s] calendars for hotel [%s]', len(calendars), self.env.user.hotel_id.id) + return [ + { + 'id': calendar.id, + 'name': calendar.name, + 'segmentation_ids': calendar.segmentation_ids.ids, + 'location_ids': calendar.location_ids.ids, + 'amenity_ids': calendar.amenity_ids.ids, + 'room_type_ids': calendar.room_type_ids.ids, + } for calendar in calendars] @api.model def get_hcalendar_reservations_data(self, dfrom_dt, dto_dt, rooms): @@ -350,22 +361,13 @@ class HotelReservation(models.Model): return self._hcalendar_event_data(events_raw) @api.model - def get_hcalendar_settings(self): - type_move = self.env.user.hotel_id.pms_type_move - return { - 'divide_rooms_by_capacity': self.env.user.hotel_id.pms_divide_rooms_by_capacity, - 'eday_week': self.env.user.hotel_id.pms_end_day_week, - 'eday_week_offset': self.env.user.hotel_id.pms_end_day_week_offset, - 'days': self.env.user.hotel_id.pms_default_num_days, - 'allow_invalid_actions': type_move == 'allow_invalid', - 'assisted_movement': type_move == 'assisted', - 'default_arrival_hour': self.env.user.hotel_id.default_arrival_hour, - 'default_departure_hour': self.env.user.hotel_id.default_departure_hour, - 'show_notifications': self.env.user.pms_show_notifications, - 'show_pricelist': self.env.user.pms_show_pricelist, - 'show_availability': self.env.user.pms_show_availability, - 'show_num_rooms': self.env.user.hotel_id.pms_show_num_rooms, - } + def get_hcalendar_calendar_data(self): + hotel_id = self.env.user.hotel_id.id + calendars = self.env['hotel.calendar'].search([ + ('hotel_id', '=', hotel_id) + ]) + res = self._hcalendar_calendar_data(calendars) + return res @api.model def get_hcalendar_all_data(self, dfrom, dto, withRooms=True): @@ -493,6 +495,7 @@ class HotelReservation(models.Model): return True + # CRUD methods @api.model def create(self, vals): reservation_id = super(HotelReservation, self).create(vals) diff --git a/hotel_calendar/models/inherited_hotel_room_type_restriction_item.py b/hotel_calendar/models/inherited_hotel_room_type_restriction_item.py index b48807638..fa3afa6b2 100644 --- a/hotel_calendar/models/inherited_hotel_room_type_restriction_item.py +++ b/hotel_calendar/models/inherited_hotel_room_type_restriction_item.py @@ -8,6 +8,7 @@ _logger = logging.getLogger(__name__) class HotelRoomTypeResrtrictionItem(models.Model): _inherit = 'hotel.room.type.restriction.item' + # CRUD methods @api.model def create(self, vals): res = super(HotelRoomTypeResrtrictionItem, self).create(vals) diff --git a/hotel_calendar/models/inherited_product_pricelist_item.py b/hotel_calendar/models/inherited_product_pricelist_item.py index 896769ee8..f3c93ab1d 100644 --- a/hotel_calendar/models/inherited_product_pricelist_item.py +++ b/hotel_calendar/models/inherited_product_pricelist_item.py @@ -6,6 +6,7 @@ from odoo import models, api class ProductPricelistItem(models.Model): _inherit = 'product.pricelist.item' + # CRUD methods @api.model def create(self, vals): res = super(ProductPricelistItem, self).create(vals) diff --git a/hotel_calendar/models/inherited_res_company.py b/hotel_calendar/models/inherited_res_company.py index 21a933569..63465f40c 100644 --- a/hotel_calendar/models/inherited_res_company.py +++ b/hotel_calendar/models/inherited_res_company.py @@ -7,6 +7,7 @@ from odoo.exceptions import ValidationError class ResCompany(models.Model): _inherit = 'res.company' + # background reservation colors color_pre_reservation = fields.Char('Pre-reservation', default='#A24680') color_reservation = fields.Char('Confirmed Reservation ', default='#7C7BAD') color_reservation_pay = fields.Char('Paid Reservation', default='#584D76') @@ -17,7 +18,7 @@ class ResCompany(models.Model): color_staff = fields.Char('Staff', default='#C08686') color_to_assign = fields.Char('Ota Reservation to Assign', default='#ED722E') color_payment_pending = fields.Char('Payment Pending', default='#A24689') - + # foreground reservation colors color_letter_pre_reservation = fields.Char('Letter Pre-reservation', default='#FFFFFF') color_letter_reservation = fields.Char('Letter Confirmed Reservation ', default='#FFFFFF') color_letter_reservation_pay = fields.Char('Letter Paid Reservation', default='#FFFFFF') diff --git a/hotel_calendar/models/ir_actions_act_window_view.py b/hotel_calendar/models/ir_actions_act_window_view.py index 4a622268e..e72648595 100644 --- a/hotel_calendar/models/ir_actions_act_window_view.py +++ b/hotel_calendar/models/ir_actions_act_window_view.py @@ -2,6 +2,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import models, fields + class ActWindowView(models.Model): _inherit = 'ir.actions.act_window.view' diff --git a/hotel_calendar/models/ir_ui_view.py b/hotel_calendar/models/ir_ui_view.py index e5e526341..d32601531 100644 --- a/hotel_calendar/models/ir_ui_view.py +++ b/hotel_calendar/models/ir_ui_view.py @@ -2,6 +2,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import models, fields + class View(models.Model): _inherit = 'ir.ui.view'