mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[FIX] list current lines
This commit is contained in:
@@ -234,11 +234,7 @@ class PmsReservation(models.Model):
|
||||
reservation_type = fields.Selection(
|
||||
related="folio_id.reservation_type", default=lambda *a: "normal"
|
||||
)
|
||||
splitted = fields.Boolean(
|
||||
"Splitted",
|
||||
compute="_compute_splitted",
|
||||
store=True,
|
||||
)
|
||||
splitted = fields.Boolean("Splitted", compute="_compute_splitted", store=True,)
|
||||
invoice_count = fields.Integer(related="folio_id.invoice_count")
|
||||
credit_card_details = fields.Text(related="folio_id.credit_card_details")
|
||||
cancelled_reason = fields.Selection(
|
||||
@@ -293,10 +289,7 @@ class PmsReservation(models.Model):
|
||||
reselling = fields.Boolean("Is Reselling", default=False)
|
||||
nights = fields.Integer("Nights", compute="_computed_nights", store=True)
|
||||
channel_type = fields.Selection(
|
||||
[
|
||||
("direct", "Direct"),
|
||||
("agency", "Agency"),
|
||||
],
|
||||
[("direct", "Direct"), ("agency", "Agency"),],
|
||||
string="Sales Channel",
|
||||
default="direct",
|
||||
)
|
||||
@@ -419,20 +412,17 @@ class PmsReservation(models.Model):
|
||||
else:
|
||||
reservation.name = "/"
|
||||
|
||||
@api.depends("reservation_line_ids","reservation_line_ids.room_id")
|
||||
@api.depends("reservation_line_ids", "reservation_line_ids.room_id")
|
||||
def _compute_room_id(self):
|
||||
_logger.info("COMPUTE_ROOM_ID")
|
||||
for reservation in self:
|
||||
_logger.info("room_id: ")
|
||||
reservation.room_id = reservation.reservation_line_ids[0].room_id
|
||||
_logger.info(reservation.room_id)
|
||||
|
||||
@api.depends("room_id")
|
||||
def _compute_room_type_id(self):
|
||||
for reservation in self:
|
||||
if reservation.room_id and not reservation.room_type_id:
|
||||
reservation.room_type_id = reservation.room_id.room_type_id.id
|
||||
else:
|
||||
elif not reservation.room_type_id:
|
||||
reservation.room_type_id = False
|
||||
|
||||
@api.depends("reservation_line_ids.date", "overbooking", "state", "room_id")
|
||||
@@ -444,13 +434,13 @@ class PmsReservation(models.Model):
|
||||
[("active", "=", True)]
|
||||
)
|
||||
return
|
||||
rooms_available = (
|
||||
self.env["pms.room.type.availability"].rooms_available(
|
||||
checkin=reservation.checkin,
|
||||
checkout=reservation.checkout,
|
||||
room_type_id=False, # Allow chosen any available room
|
||||
current_lines=reservation.reservation_line_ids.ids,
|
||||
)
|
||||
rooms_available = self.env[
|
||||
"pms.room.type.availability"
|
||||
].rooms_available(
|
||||
checkin=reservation.checkin,
|
||||
checkout=reservation.checkout,
|
||||
room_type_id=False, # Allow chosen any available room
|
||||
current_lines=reservation.reservation_line_ids.ids,
|
||||
)
|
||||
reservation.allowed_room_ids = rooms_available
|
||||
|
||||
@@ -500,7 +490,7 @@ class PmsReservation(models.Model):
|
||||
board_services = []
|
||||
old_board_lines = reservation.service_ids.filtered_domain(
|
||||
[("is_board_service", "=", True),]
|
||||
)
|
||||
)
|
||||
if reservation.board_service_room_id:
|
||||
board = self.env["pms.board.service.room.type"].browse(
|
||||
reservation.board_service_room_id.id
|
||||
@@ -533,16 +523,14 @@ class PmsReservation(models.Model):
|
||||
|
||||
@api.depends("room_id")
|
||||
def _compute_adults(self):
|
||||
_logger.info("COMPUTE_ADULTS")
|
||||
for reservation in self:
|
||||
_logger.info("adults")
|
||||
if reservation.room_id:
|
||||
if reservation.adults == 0:
|
||||
reservation.adults = reservation.room_id.capacity
|
||||
else:
|
||||
elif reservation.adults == False:
|
||||
reservation.adults = 0
|
||||
_logger.info(reservation.room_id)
|
||||
_logger.info(reservation.adults)
|
||||
|
||||
# REVIEW: Adult not computed with room_type set
|
||||
|
||||
@api.depends("checkin", "checkout", "state")
|
||||
def _compute_to_send(self):
|
||||
@@ -688,11 +676,7 @@ class PmsReservation(models.Model):
|
||||
)
|
||||
else:
|
||||
record.update(
|
||||
{
|
||||
"price_tax": 0,
|
||||
"price_total": 0,
|
||||
"price_subtotal": 0,
|
||||
}
|
||||
{"price_tax": 0, "price_total": 0, "price_subtotal": 0,}
|
||||
)
|
||||
|
||||
# TODO: Use default values on checkin /checkout is empty
|
||||
@@ -878,7 +862,7 @@ class PmsReservation(models.Model):
|
||||
if rooms_available:
|
||||
room_chosen = rooms_available[0]
|
||||
else:
|
||||
#We can split reserve night on multi rooms
|
||||
# We can split reserve night on multi rooms
|
||||
room_chosen = False
|
||||
return room_chosen
|
||||
|
||||
@@ -1001,8 +985,7 @@ class PmsReservation(models.Model):
|
||||
tz_property = self.env.user.pms_property_id.tz
|
||||
today = fields.Date.context_today(self.with_context(tz=tz_property))
|
||||
days_diff = (
|
||||
fields.Date.from_string(self.checkin)
|
||||
- fields.Date.from_string(today)
|
||||
fields.Date.from_string(self.checkin) - fields.Date.from_string(today)
|
||||
).days
|
||||
if days_diff < 0:
|
||||
return "noshow"
|
||||
@@ -1112,7 +1095,7 @@ class PmsReservation(models.Model):
|
||||
return action
|
||||
|
||||
def unify(self):
|
||||
#TODO
|
||||
# TODO
|
||||
return True
|
||||
|
||||
def send_reservation_mail(self):
|
||||
|
||||
@@ -2,16 +2,16 @@
|
||||
# Copyright 2017 Dario Lodeiros
|
||||
# Copyright 2018 Pablo Quesada
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
from datetime import timedelta
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class PmsRoomTypeAvailability(models.Model):
|
||||
_name = "pms.room.type.availability"
|
||||
_description = "Availability"
|
||||
_inherit = 'mail.thread'
|
||||
_inherit = "mail.thread"
|
||||
|
||||
@api.model
|
||||
def _default_max_avail(self):
|
||||
@@ -22,20 +22,30 @@ class PmsRoomTypeAvailability(models.Model):
|
||||
return self.room_type_id.default_quota
|
||||
|
||||
# Fields declaration
|
||||
room_type_id = fields.Many2one('pms.room.type', 'Room Type',
|
||||
required=True,
|
||||
ondelete='cascade')
|
||||
date = fields.Date('Date', required=True, track_visibility='always')
|
||||
quota = fields.Integer("Quota", default=_default_quota,
|
||||
track_visibility='always',
|
||||
help="Generic Quota assigned.")
|
||||
max_avail = fields.Integer("Max. Availability", default=-1, readonly=True,
|
||||
track_visibility='always',
|
||||
help="Maximum simultaneous availability on own Booking Engine.")
|
||||
no_web = fields.Boolean('No Web', default=False,
|
||||
track_visibility='onchange',
|
||||
help="Set zero availability to the own Booking Engine "
|
||||
"even when the availability is positive,")
|
||||
room_type_id = fields.Many2one(
|
||||
"pms.room.type", "Room Type", required=True, ondelete="cascade"
|
||||
)
|
||||
date = fields.Date("Date", required=True, track_visibility="always")
|
||||
quota = fields.Integer(
|
||||
"Quota",
|
||||
default=_default_quota,
|
||||
track_visibility="always",
|
||||
help="Generic Quota assigned.",
|
||||
)
|
||||
max_avail = fields.Integer(
|
||||
"Max. Availability",
|
||||
default=-1,
|
||||
readonly=True,
|
||||
track_visibility="always",
|
||||
help="Maximum simultaneous availability on own Booking Engine.",
|
||||
)
|
||||
no_web = fields.Boolean(
|
||||
"No Web",
|
||||
default=False,
|
||||
track_visibility="onchange",
|
||||
help="Set zero availability to the own Booking Engine "
|
||||
"even when the availability is positive,",
|
||||
)
|
||||
|
||||
_sql_constraints = [
|
||||
(
|
||||
@@ -48,17 +58,15 @@ class PmsRoomTypeAvailability(models.Model):
|
||||
|
||||
# Business Methods
|
||||
@api.model
|
||||
def rooms_available(self, checkin, checkout, room_type_id=False, current_lines=False):
|
||||
def rooms_available(
|
||||
self, checkin, checkout, room_type_id=False, current_lines=False
|
||||
):
|
||||
domain = self._get_domain_reservations_occupation(
|
||||
dfrom=checkin,
|
||||
dto=checkout - timedelta(1),
|
||||
current_lines=current_lines,
|
||||
dfrom=checkin, dto=checkout - timedelta(1), current_lines=current_lines,
|
||||
)
|
||||
reservation_lines = self.env['pms.reservation.line'].search(domain)
|
||||
reservation_lines = self.env["pms.reservation.line"].search(domain)
|
||||
reservations_rooms = reservation_lines.mapped("room_id.id")
|
||||
free_rooms = self.env["pms.room"].search(
|
||||
[("id", "not in", reservations_rooms)]
|
||||
)
|
||||
free_rooms = self.env["pms.room"].search([("id", "not in", reservations_rooms)])
|
||||
if room_type_id:
|
||||
rooms_linked = (
|
||||
self.env["pms.room.type"].search([("id", "=", room_type_id)]).room_ids
|
||||
@@ -68,10 +76,12 @@ class PmsRoomTypeAvailability(models.Model):
|
||||
|
||||
@api.model
|
||||
def _get_domain_reservations_occupation(self, dfrom, dto, current_lines=False):
|
||||
if current_lines and not isinstance(current_lines, list):
|
||||
current_lines = [current_lines]
|
||||
domain = [
|
||||
("date", ">=", dfrom),
|
||||
("date", "<=", dto),
|
||||
("occupies_availability", "=", True),
|
||||
("id","not in", current_lines),
|
||||
("id", "not in", current_lines),
|
||||
]
|
||||
return domain
|
||||
|
||||
Reference in New Issue
Block a user