[REF] attribute and methods order guidelines

Business fields and methods arranged by importance
This commit is contained in:
Pablo
2019-09-16 12:15:48 +02:00
parent 18b9de789f
commit d568538263
12 changed files with 147 additions and 131 deletions

View File

@@ -14,8 +14,8 @@ class HotelRoom(models.Model):
_description = 'Hotel Room' _description = 'Hotel Room'
_order = "sequence, room_type_id, name" _order = "sequence, room_type_id, name"
# Fields declaration
name = fields.Char('Room Name', required=True) name = fields.Char('Room Name', required=True)
# Relationship between models
hotel_id = fields.Many2one('hotel.property', store=True, readonly=True, hotel_id = fields.Many2one('hotel.property', store=True, readonly=True,
related='room_type_id.hotel_id') related='room_type_id.hotel_id')
room_type_id = fields.Many2one('hotel.room.type', 'Hotel Room Type', room_type_id = fields.Many2one('hotel.room.type', 'Hotel Room Type',

View File

@@ -15,11 +15,12 @@ class HotelRoomType(models.Model):
_inherits = {'product.product': 'product_id'} _inherits = {'product.product': 'product_id'}
_order = "sequence, code_type, name" _order = "sequence, code_type, name"
# Default methods
@api.model @api.model
def _get_default_hotel(self): def _get_default_hotel(self):
return self.env.user.hotel_id return self.env.user.hotel_id
# Relationship between models # Fields declaration
product_id = fields.Many2one('product.product', 'Product Room Type', product_id = fields.Many2one('product.product', 'Product Room Type',
required=True, delegate=True, required=True, delegate=True,
ondelete='cascade') ondelete='cascade')

View File

@@ -20,6 +20,7 @@ class BusHotelCalendar(models.TransientModel):
- warn : Show a warning notification - warn : Show a warning notification
- noshow : Don't show any notification - noshow : Don't show any notification
''' '''
# Business methods
@api.model @api.model
def _generate_reservation_notif(self, vals): def _generate_reservation_notif(self, vals):
user_id = self.env['res.users'].browse(self.env.uid) user_id = self.env['res.users'].browse(self.env.uid)

View File

@@ -6,16 +6,20 @@ from odoo.exceptions import ValidationError
class HotelCalendar(models.Model): class HotelCalendar(models.Model):
""" Used to show and filter rooms and reservations in the PMS Calendar. """
_name = 'hotel.calendar' _name = 'hotel.calendar'
# Default methods
@api.model @api.model
def _get_default_hotel(self): def _get_default_hotel(self):
return self.env.user.hotel_id return self.env.user.hotel_id
# Fields declaration
name = fields.Char('Name', required=True) 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') segmentation_ids = fields.Many2many('hotel.room.type.class', string='Segmentation')
location_ids = fields.Many2many('hotel.floor', string='Location') location_ids = fields.Many2many('hotel.floor', string='Location')
amenity_ids = fields.Many2many('hotel.amenity', string='Amenity') 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,)

View File

@@ -13,6 +13,17 @@ _logger = logging.getLogger(__name__)
class HotelCalendarManagement(models.TransientModel): class HotelCalendarManagement(models.TransientModel):
_name = 'hotel.calendar.management' _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 @api.model
def _get_prices_values(self, price): def _get_prices_values(self, price):
vals = { vals = {
@@ -33,59 +44,6 @@ class HotelCalendarManagement(models.TransientModel):
} }
return vals 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 @api.model
def _hcalendar_room_json_data(self, rooms): def _hcalendar_room_json_data(self, rooms):
json_data = [] json_data = []
@@ -265,12 +223,55 @@ class HotelCalendarManagement(models.TransientModel):
return vals return vals
@api.multi @api.model
def get_hcalendar_settings(self): def save_changes(self, pricelist_id, restriction_id, pricelist,
return { restrictions, availability=False):
'eday_week': self.env.user.hotel_id.pms_end_day_week, room_type_obj = self.env['hotel.room.type']
'eday_week_offset': self.env.user.hotel_id.pms_end_day_week_offset, product_pricelist_item_obj = self.env['product.pricelist.item']
'days': self.env.user.hotel_id.pms_default_num_days, room_type_rest_item_obj = self.env['hotel.room.type.restriction.item']
'show_notifications': self.env.user.pms_show_notifications,
'show_num_rooms': self.env.user.hotel_id.pms_show_num_rooms, # 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)

View File

@@ -6,6 +6,7 @@ from odoo import models, api, _
class HotelFolio(models.Model): class HotelFolio(models.Model):
_inherit = 'hotel.folio' _inherit = 'hotel.folio'
# CRUD methods
@api.multi @api.multi
def write(self, vals): def write(self, vals):
ret = super(HotelFolio, self).write(vals) ret = super(HotelFolio, self).write(vals)
@@ -19,11 +20,11 @@ class HotelFolio(models.Model):
@api.multi @api.multi
def unlink(self): def unlink(self):
for record in self: for record in self:
record.room_lines.send_bus_notification('unlink', record.room_lines.send_bus_notification('unlink', 'warn',
'warn', _("Folio Deleted"))
_("Folio Deleted"))
return super(HotelFolio, self).unlink() return super(HotelFolio, self).unlink()
# Business methods
@api.multi @api.multi
def compute_amount(self): def compute_amount(self):
ret = super(HotelFolio, self).compute_amount() ret = super(HotelFolio, self).compute_amount()

View File

@@ -12,11 +12,13 @@ _logger = logging.getLogger(__name__)
class HotelReservation(models.Model): class HotelReservation(models.Model):
_inherit = 'hotel.reservation' _inherit = 'hotel.reservation'
# Fields declaration
reserve_color = fields.Char(compute='_compute_color', string='Color', reserve_color = fields.Char(compute='_compute_color', string='Color',
store=True) store=True)
reserve_color_text = fields.Char(compute='_compute_color', string='Color', reserve_color_text = fields.Char(compute='_compute_color', string='Color',
store=True) store=True)
# Business methods
@api.multi @api.multi
def _generate_color(self): def _generate_color(self):
self.ensure_one() self.ensure_one()
@@ -65,6 +67,47 @@ class HotelReservation(models.Model):
'reserve_color_text': colors[1], '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 @api.model
def _hcalendar_reservation_data(self, reservations): def _hcalendar_reservation_data(self, reservations):
_logger.warning('_found [%s] reservations for hotel [%s]', len(reservations), self.env.user.hotel_id.id) _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'], 'services': reserv['services'],
} }
}) })
return (json_reservations, json_reservation_tooltips) 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]
@api.model @api.model
def _hcalendar_event_data(self, events): def _hcalendar_event_data(self, events):
@@ -177,13 +184,17 @@ class HotelReservation(models.Model):
return json_events return json_events
@api.model @api.model
def get_hcalendar_calendar_data(self): def _hcalendar_calendar_data(self, calendars):
hotel_id = self.env.user.hotel_id.id _logger.warning('_found [%s] calendars for hotel [%s]', len(calendars), self.env.user.hotel_id.id)
calendars = self.env['hotel.calendar'].search([ return [
('hotel_id', '=', hotel_id) {
]) 'id': calendar.id,
res = self._hcalendar_calendar_data(calendars) 'name': calendar.name,
return res '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 @api.model
def get_hcalendar_reservations_data(self, dfrom_dt, dto_dt, rooms): 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) return self._hcalendar_event_data(events_raw)
@api.model @api.model
def get_hcalendar_settings(self): def get_hcalendar_calendar_data(self):
type_move = self.env.user.hotel_id.pms_type_move hotel_id = self.env.user.hotel_id.id
return { calendars = self.env['hotel.calendar'].search([
'divide_rooms_by_capacity': self.env.user.hotel_id.pms_divide_rooms_by_capacity, ('hotel_id', '=', hotel_id)
'eday_week': self.env.user.hotel_id.pms_end_day_week, ])
'eday_week_offset': self.env.user.hotel_id.pms_end_day_week_offset, res = self._hcalendar_calendar_data(calendars)
'days': self.env.user.hotel_id.pms_default_num_days, return res
'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 @api.model
def get_hcalendar_all_data(self, dfrom, dto, withRooms=True): def get_hcalendar_all_data(self, dfrom, dto, withRooms=True):
@@ -493,6 +495,7 @@ class HotelReservation(models.Model):
return True return True
# CRUD methods
@api.model @api.model
def create(self, vals): def create(self, vals):
reservation_id = super(HotelReservation, self).create(vals) reservation_id = super(HotelReservation, self).create(vals)

View File

@@ -8,6 +8,7 @@ _logger = logging.getLogger(__name__)
class HotelRoomTypeResrtrictionItem(models.Model): class HotelRoomTypeResrtrictionItem(models.Model):
_inherit = 'hotel.room.type.restriction.item' _inherit = 'hotel.room.type.restriction.item'
# CRUD methods
@api.model @api.model
def create(self, vals): def create(self, vals):
res = super(HotelRoomTypeResrtrictionItem, self).create(vals) res = super(HotelRoomTypeResrtrictionItem, self).create(vals)

View File

@@ -6,6 +6,7 @@ from odoo import models, api
class ProductPricelistItem(models.Model): class ProductPricelistItem(models.Model):
_inherit = 'product.pricelist.item' _inherit = 'product.pricelist.item'
# CRUD methods
@api.model @api.model
def create(self, vals): def create(self, vals):
res = super(ProductPricelistItem, self).create(vals) res = super(ProductPricelistItem, self).create(vals)

View File

@@ -7,6 +7,7 @@ from odoo.exceptions import ValidationError
class ResCompany(models.Model): class ResCompany(models.Model):
_inherit = 'res.company' _inherit = 'res.company'
# background reservation colors
color_pre_reservation = fields.Char('Pre-reservation', default='#A24680') color_pre_reservation = fields.Char('Pre-reservation', default='#A24680')
color_reservation = fields.Char('Confirmed Reservation ', default='#7C7BAD') color_reservation = fields.Char('Confirmed Reservation ', default='#7C7BAD')
color_reservation_pay = fields.Char('Paid Reservation', default='#584D76') 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_staff = fields.Char('Staff', default='#C08686')
color_to_assign = fields.Char('Ota Reservation to Assign', default='#ED722E') color_to_assign = fields.Char('Ota Reservation to Assign', default='#ED722E')
color_payment_pending = fields.Char('Payment Pending', default='#A24689') 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_pre_reservation = fields.Char('Letter Pre-reservation', default='#FFFFFF')
color_letter_reservation = fields.Char('Letter Confirmed Reservation ', default='#FFFFFF') color_letter_reservation = fields.Char('Letter Confirmed Reservation ', default='#FFFFFF')
color_letter_reservation_pay = fields.Char('Letter Paid Reservation', default='#FFFFFF') color_letter_reservation_pay = fields.Char('Letter Paid Reservation', default='#FFFFFF')

View File

@@ -2,6 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, fields from odoo import models, fields
class ActWindowView(models.Model): class ActWindowView(models.Model):
_inherit = 'ir.actions.act_window.view' _inherit = 'ir.actions.act_window.view'

View File

@@ -2,6 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, fields from odoo import models, fields
class View(models.Model): class View(models.Model):
_inherit = 'ir.ui.view' _inherit = 'ir.ui.view'