mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[REF] attribute and methods order guidelines
Business fields and methods arranged by importance
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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'
|
||||
|
||||
|
||||
@@ -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'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user