Code review (#62)

* [REF] pms: refactor amenity type

* [REF] pms: refactor amenity

* [REF]Refactor amenity views and demo data

* [WIP] master model 2nd day

* [WIP] Master model refactor

* [WIP] Refactor in tests

* [WIP] Add mandatory sequence in pms_property at tests and fix create in folio, reservation and checkin

* [WIP] Test refactor

* [WIP]Refactor pms_room, pms_room_clousure_reason and pms_room_type

* [WIP]review of guidelines in master models

* [WIP]test refactor

* [WIP]review guidelines in master models 2

* [WIP] fixed fields in pms_l10n_es

* [WIP]Refactor product_product, product_template, res_company, res_partner and res_user

* [IMP] Add common.py for tests

* [WIP] Refactor fields in pms.folio and pms.reservation

* [WIP] Review guidelines in pms.reservation, pms.reservation.line and rename availability models

* [WIP] Rename availability models

* [WIP] Refactor availability models

* [WIP] Refactor availity models 2

* [WIP] Pms: add sequences creation in pms_property create

* [WIP] Fix sequence creation in pmp.property

* [REF] Refactor fields in res_partner and rename date_overnight

* [REF] Refactoring master models tests

* [FIX] Fix sequence create in pms.reservation

* [REF] Refactor helps in master and availability models

* [IMP] Extend test coverage in test_pms_reservation

* [REF] Refactor fields in pms_reservation

* [REF] Refactor fields in pms_reservation 2

* [REF] Refactor fields in service flow

* [REF] Refactor pms_reservation

* [REF] Refactor pms_reservation 2

* [REF] draft button removed from view

* [REF] change no_show to arrival_delayed in field state of pms_reservation

* [REF] Add compute_preferred_room_id in pms_reservation

* [REF] Fix cache problem in test_reservation_action_checkout

Co-authored-by: braisab <braisterbutalino@gmail.com>
Co-authored-by: Sara Lago <saralago126@gmail.com>
Co-authored-by: Brais Abeijón <>
This commit is contained in:
Miguel Padin
2021-04-15 01:01:11 +02:00
committed by GitHub
parent eace7de663
commit 0d03152402
79 changed files with 3920 additions and 2480 deletions

View File

@@ -0,0 +1,95 @@
# Copyright 2017 Alexandre Díaz
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
class PmsAvailability(models.Model):
_name = "pms.availability"
_description = "Room type availability per day"
room_type_id = fields.Many2one(
string="Room Type",
help="Room type for which availability is indicated",
readonly=True,
required=True,
comodel_name="pms.room.type",
ondelete="cascade",
)
date = fields.Date(
string="Date",
help="Date for which availability applies",
readonly=True,
required=True,
)
pms_property_id = fields.Many2one(
string="Property",
help="Property to which the availability is directed",
readonly=True,
required=True,
comodel_name="pms.property",
ondelete="restrict",
)
reservation_line_ids = fields.One2many(
string="Reservation Lines",
help="They are the lines of the reservation into a reservation,"
"they corresponds to the nights",
readonly=True,
comodel_name="pms.reservation.line",
inverse_name="avail_id",
)
real_avail = fields.Integer(
string="Real Avail",
help="",
store=True,
readonly=True,
compute="_compute_real_avail",
)
_sql_constraints = [
(
"room_type_registry_unique",
"unique(room_type_id, date, pms_property_id)",
"Only can exists one availability in the same \
day for the same room type!",
)
]
@api.depends("reservation_line_ids", "reservation_line_ids.occupies_availability")
def _compute_real_avail(self):
for record in self:
Rooms = self.env["pms.room"]
RoomLines = self.env["pms.reservation.line"]
total_rooms = Rooms.search_count(
[
("room_type_id", "=", record.room_type_id.id),
("pms_property_id", "=", record.pms_property_id.id),
]
)
room_ids = record.room_type_id.mapped("room_ids.id")
rooms_not_avail = RoomLines.search_count(
[
("date", "=", record.date),
("room_id", "in", room_ids),
("pms_property_id", "=", record.pms_property_id.id),
("occupies_availability", "=", True),
# ("id", "not in", current_lines if current_lines else []),
]
)
record.real_avail = total_rooms - rooms_not_avail
@api.constrains(
"room_type_id",
"pms_property_id",
)
def _check_property_integrity(self):
for rec in self:
if rec.pms_property_id and rec.room_type_id:
if (
rec.room_type_id.pms_property_ids.ids
and rec.pms_property_id.id
not in rec.room_type_id.pms_property_ids.ids
):
raise ValidationError(
_("Property not allowed on availability day compute")
)