mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[WIP] Refactoring Code - hotel_room_clousure_reason
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
# Copyright 2017 Dario Lodeiros
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from openerp import models, fields, api, _
|
||||
|
||||
from odoo import models, fields
|
||||
|
||||
class RoomClosureReason(models.Model):
|
||||
_name = "room.closure.reason"
|
||||
|
||||
@@ -1,25 +1,17 @@
|
||||
# Copyright 2017 Alexandre Díaz
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
import logging
|
||||
from odoo import models, fields, api, _
|
||||
from odoo.exceptions import ValidationError
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class HotelRoomTypeAvailability(models.Model):
|
||||
_inherit = 'mail.thread'
|
||||
_name = 'hotel.room.type.availability'
|
||||
_inherit = 'mail.thread'
|
||||
|
||||
# room_type_id = fields.Many2one('hotel.virtual.room', 'Virtual Room',
|
||||
# required=True, track_visibility='always',
|
||||
# ondelete='cascade')
|
||||
room_type_id = fields.Many2one('hotel.room.type', 'Room Type',
|
||||
required=True, track_visibility='always',
|
||||
ondelete='cascade')
|
||||
avail = fields.Integer('Avail', default=0, track_visibility='always')
|
||||
no_ota = fields.Boolean('No OTA', default=False, track_visibility='always')
|
||||
booked = fields.Boolean('Booked', default=False, readonly=True,
|
||||
track_visibility='always')
|
||||
date = fields.Date('Date', required=True, track_visibility='always')
|
||||
|
||||
_sql_constraints = [
|
||||
@@ -30,25 +22,15 @@ class HotelRoomTypeAvailability(models.Model):
|
||||
|
||||
@api.constrains('avail')
|
||||
def _check_avail(self):
|
||||
if self.avail < 0:
|
||||
self.avail = 0
|
||||
|
||||
room_type_obj = self.env['hotel.room.type']
|
||||
cavail = len(room_type_obj.check_availability_room(
|
||||
self.date,
|
||||
self.date,
|
||||
room_type_id=self.room_type_id.id))
|
||||
max_avail = min(cavail,
|
||||
self.room_type_id.total_rooms_count)
|
||||
if self.avail > max_avail:
|
||||
self.avail = max_avail
|
||||
|
||||
@api.constrains('date', 'room_type_id')
|
||||
def _check_date_room_type_id(self):
|
||||
count = self.search_count([
|
||||
('date', '=', self.date),
|
||||
('room_type_id', '=', self.room_type_id.id)
|
||||
])
|
||||
if count > 1:
|
||||
raise ValidationError(_("can't assign the same date to more than \
|
||||
one room type"))
|
||||
for record in self:
|
||||
if record.avail < 0:
|
||||
record.avail = 0
|
||||
else:
|
||||
room_type_obj = self.env['hotel.room.type']
|
||||
cavail = len(room_type_obj.check_availability_room(
|
||||
record.date,
|
||||
record.date,
|
||||
room_type_id=record.room_type_id.id))
|
||||
max_avail = min(cavail, record.room_type_id.total_rooms_count)
|
||||
if record.avail > max_avail:
|
||||
record.avail = max_avail
|
||||
|
||||
Reference in New Issue
Block a user