mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[WIP][ADD] rate room_type and localizator reservation
This commit is contained in:
@@ -3,6 +3,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).
|
||||||
import time
|
import time
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
import readline
|
||||||
from odoo.exceptions import UserError, ValidationError
|
from odoo.exceptions import UserError, ValidationError
|
||||||
from odoo.tools import (
|
from odoo.tools import (
|
||||||
float_is_zero,
|
float_is_zero,
|
||||||
@@ -155,6 +156,17 @@ class HotelReservation(models.Model):
|
|||||||
fields.Date.from_string(res.checkout) - fields.Date.from_string(res.checkin)
|
fields.Date.from_string(res.checkout) - fields.Date.from_string(res.checkin)
|
||||||
).days
|
).days
|
||||||
|
|
||||||
|
@api.depends('folio_id', 'checkin', 'checkout')
|
||||||
|
def _compute_localizator(self):
|
||||||
|
for record in self:
|
||||||
|
localizator = str(record.folio_id.name)
|
||||||
|
checkout = int(re.sub("\D", "", record.checkout))
|
||||||
|
checkin = int(re.sub("\D", "", record.checkin))
|
||||||
|
localizator += '-' + (checkin + checkout) % 777
|
||||||
|
record.localizator = localizator
|
||||||
|
|
||||||
|
localizator = fields.Char('Localizator', compute='_compute_localizator',
|
||||||
|
strore=True)
|
||||||
name = fields.Text('Reservation Description', required=True)
|
name = fields.Text('Reservation Description', required=True)
|
||||||
sequence = fields.Integer(string='Sequence', default=10)
|
sequence = fields.Integer(string='Sequence', default=10)
|
||||||
|
|
||||||
|
|||||||
@@ -22,10 +22,10 @@ class HotelRoomType(models.Model):
|
|||||||
board_service_room_type_ids = fields.One2many(
|
board_service_room_type_ids = fields.One2many(
|
||||||
'hotel.board.service.room.type', 'hotel_room_type_id', string='Board Services')
|
'hotel.board.service.room.type', 'hotel_room_type_id', string='Board Services')
|
||||||
room_amenity_ids = fields.Many2many('hotel.amenity',
|
room_amenity_ids = fields.Many2many('hotel.amenity',
|
||||||
'hotel_room_type_aminity_rel',
|
'hotel_room_type_aminity_rel',
|
||||||
'room_type_ids', 'amenity_ids',
|
'room_type_ids', 'amenity_ids',
|
||||||
string='Room Type Amenities',
|
string='Room Type Amenities',
|
||||||
help='List of Amenities.')
|
help='List of Amenities.')
|
||||||
|
|
||||||
# TODO Hierarchical relationship for parent-child tree ?
|
# TODO Hierarchical relationship for parent-child tree ?
|
||||||
# parent_id = fields.Many2one ...
|
# parent_id = fields.Many2one ...
|
||||||
@@ -37,7 +37,7 @@ class HotelRoomType(models.Model):
|
|||||||
# Used for ordering
|
# Used for ordering
|
||||||
sequence = fields.Integer('Sequence', default=0)
|
sequence = fields.Integer('Sequence', default=0)
|
||||||
|
|
||||||
code_type = fields.Char('Code')
|
code_type = fields.Char('Code', required=True, )
|
||||||
|
|
||||||
_order = "sequence, code_type, name"
|
_order = "sequence, code_type, name"
|
||||||
|
|
||||||
@@ -46,6 +46,9 @@ class HotelRoomType(models.Model):
|
|||||||
# total number of rooms in this type
|
# total number of rooms in this type
|
||||||
total_rooms_count = fields.Integer(compute='_compute_total_rooms', store=True)
|
total_rooms_count = fields.Integer(compute='_compute_total_rooms', store=True)
|
||||||
|
|
||||||
|
_sql_constraints = [
|
||||||
|
('code_unique', 'unique(code_type)', 'Room Type Code must be unique!')]
|
||||||
|
|
||||||
@api.depends('room_ids')
|
@api.depends('room_ids')
|
||||||
def _compute_total_rooms(self):
|
def _compute_total_rooms(self):
|
||||||
for record in self:
|
for record in self:
|
||||||
@@ -111,3 +114,54 @@ class HotelRoomType(models.Model):
|
|||||||
for record in self:
|
for record in self:
|
||||||
record.product_id.unlink()
|
record.product_id.unlink()
|
||||||
return super().unlink()
|
return super().unlink()
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def get_rate_room_types(self, **kwargs):
|
||||||
|
"""
|
||||||
|
room_type_ids: Ids from room types to get rate, optional, if you
|
||||||
|
not use this param, the method return all room_types
|
||||||
|
from: Date from, mandatory
|
||||||
|
days: Number of days, mandatory
|
||||||
|
pricelist_id: Pricselist to use, optional
|
||||||
|
partner_id: Partner, optional
|
||||||
|
Return Dict Code Room Types: subdict with day, discount, price
|
||||||
|
"""
|
||||||
|
vals = {}
|
||||||
|
room_type_ids = kwargs.get('room_type_ids', False)
|
||||||
|
room_types = self.env['hotel.room.type'].browse(room_type_ids) if \
|
||||||
|
room_type_ids else self.env['hotel.room.type'].search([])
|
||||||
|
date_from = kwargs.get('date_from', False)
|
||||||
|
days = kwargs.get('days', False)
|
||||||
|
discount = kwargs.get('discount', False)
|
||||||
|
if not date_from or not days:
|
||||||
|
raise ValidationError(_('Date From and days are mandatory'))
|
||||||
|
partner_id = kwargs.get('partner_id', False)
|
||||||
|
partner = self.env['res.partner'].browse(partner_id)
|
||||||
|
pricelist_id = partner.property_product_pricelist.id if partner else \
|
||||||
|
self.env['ir.default'].sudo().get(
|
||||||
|
'res.config.settings',
|
||||||
|
'default_pricelist_id')
|
||||||
|
pricelist_id = kwargs.get('pricelist_id',
|
||||||
|
partner.property_product_pricelist.id and
|
||||||
|
partner.property_product_pricelist.id or
|
||||||
|
self.env['ir.default'].sudo().get(
|
||||||
|
'res.config.settings',
|
||||||
|
'default_pricelist_id'))
|
||||||
|
vals.update({
|
||||||
|
'partner_id': partner_id if partner_id else False,
|
||||||
|
'discount': discount,
|
||||||
|
})
|
||||||
|
rate_vals = {}
|
||||||
|
for room_type in room_types:
|
||||||
|
vals.update({'room_type_id': room_type.id})
|
||||||
|
room_vals = self.env['hotel.reservation'].prepare_reservation_lines(
|
||||||
|
date_from,
|
||||||
|
days,
|
||||||
|
pricelist_id=pricelist_id,
|
||||||
|
vals=vals,
|
||||||
|
update_old_prices=False)
|
||||||
|
rate_vals.update({
|
||||||
|
room_type.code_type: [item[2] for item in \
|
||||||
|
room_vals['reservation_line_ids'] if item[2]]
|
||||||
|
})
|
||||||
|
return rate_vals
|
||||||
|
|||||||
@@ -143,6 +143,7 @@
|
|||||||
<span class="label label-danger" attrs="{'invisible': [('state', 'not in', ('cancelled'))]}">Cancelled Reservation!</span>
|
<span class="label label-danger" attrs="{'invisible': [('state', 'not in', ('cancelled'))]}">Cancelled Reservation!</span>
|
||||||
<span class="label label-warning" attrs="{'invisible': [('overbooking', '=', False)]}">OverBooking!</span>
|
<span class="label label-warning" attrs="{'invisible': [('overbooking', '=', False)]}">OverBooking!</span>
|
||||||
<h1>
|
<h1>
|
||||||
|
<field name="localizator" />
|
||||||
<field name="room_id" select="1"
|
<field name="room_id" select="1"
|
||||||
nolabel="1" options="{'no_create': True,'no_open': True}" placeholder="Room"
|
nolabel="1" options="{'no_create': True,'no_open': True}" placeholder="Room"
|
||||||
style="margin-right: 30px;" required='1'/>
|
style="margin-right: 30px;" required='1'/>
|
||||||
|
|||||||
Reference in New Issue
Block a user