[ADD]multi_pms_properties (#66)

* [WIP]pms: models check_pms_property

* [WIP][IMP+REF] multi_pms_properties: refactor and added test skeleton

* [FIX] inherit create models

* [ADD] room multiproperty check

* [ADD] room multiproperty check

* [IMP] Multiproperty checks in pms models

* [IMP] Fix Multiproperty checks in pms models

* [IMP] Add multiproperty domain in multi_pms_properties module

* [IMP] Fix multiproperty checks in pms tests

* [IMP] Fix multiproperty checks logic

* [IMP] Auto Domains

* [IMP] availability property results, domain preferred_room_id

* [IMP] model domain properties

* [ADD] pms multiproperty depends

* [IMP] models and views multiproperty checks

* [FIX] Multiple rebase multiproperty fixes

* [ADD] Readme

* [ADD] Company - multiproperty checks

* [ADD] travis server wide modules multiproperty

* [FIX] travis conf load

* [FIX] travis conf load2

* [FIX] travis conf load2

Co-authored-by: Eric Antones <eantones@nuobit.com>
Co-authored-by: Sara Lago <saralago126@gmail.com>
This commit is contained in:
Darío Lodeiros
2021-04-27 20:01:42 +02:00
committed by GitHub
parent de786a375b
commit e7c0c3e5bd
76 changed files with 1471 additions and 759 deletions

View File

@@ -23,6 +23,7 @@
# "partner_firstname",
# "email_template_qweb",
"sale",
"multi_pms_properties",
],
"data": [
"security/pms_security.xml",

View File

@@ -5,3 +5,6 @@ class AccountBankStatement(models.Model):
_inherit = "account.bank.statement"
property_id = fields.Many2one("pms.property", string="Property", copy=False)
company_id = fields.Many2one(
check_pms_properties=True,
)

View File

@@ -1,21 +1,20 @@
from odoo import _, api, fields, models
from odoo.exceptions import UserError
from odoo import fields, models
class AccountJournal(models.Model):
_inherit = "account.journal"
pms_property_ids = fields.Many2many("pms.property", string="Property", copy=False)
@api.constrains("pms_property_ids", "company_id")
def _check_property_company_integrity(self):
for rec in self:
if rec.company_id and rec.pms_property_ids:
property_companies = rec.pms_property_ids.mapped("company_id")
if len(property_companies) > 1 or rec.company_id != property_companies:
raise UserError(
_(
"The company of the properties must match "
"the company on account journal"
)
)
pms_property_ids = fields.Many2many(
string="Properties",
help="Properties with access to the element;"
" if not set, all properties can access",
comodel_name="pms.property",
ondelete="restrict",
relation="account_journal_pms_property_rel",
column1="account_journal_id",
column2="pms_property_id",
check_pms_properties=True,
)
company_id = fields.Many2one(
check_pms_properties=True,
)

View File

@@ -557,6 +557,7 @@ class FolioSaleLine(models.Model):
store=True,
readonly=True,
index=True,
check_pms_properties=True,
)
folio_partner_id = fields.Many2one(
related="folio_id.partner_id", store=True, string="Customer", readonly=False

View File

@@ -11,6 +11,9 @@ class PaymentReturn(models.Model):
pms_property_id = fields.Many2one(
"pms.property", store=True, readonly=True, related="folio_id.pms_property_id"
)
company_id = fields.Many2one(
check_pms_properties=True,
)
# Business methods

View File

@@ -1,13 +1,13 @@
# Copyright 2017 Alexandre Díaz
# Copyright 2017 Dario Lodeiros
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
from odoo import fields, models
class PmsRoomAmenity(models.Model):
_name = "pms.amenity"
_description = "Room amenity"
_check_pms_properties_auto = True
active = fields.Boolean(
string="Active",
@@ -25,28 +25,18 @@ class PmsRoomAmenity(models.Model):
help="Properties with access to the element;"
" if not set, all properties can access",
comodel_name="pms.property",
ondelete="restrict",
relation="pms_amenity_pms_property_rel",
column1="amenity_type_id",
column2="pms_property_id",
check_pms_properties=True,
)
pms_amenity_type_id = fields.Many2one(
string="Amenity Category",
help="Segment the amenities by categories (multimedia, comfort, etc ...)",
comodel_name="pms.amenity.type",
domain="['|', ('pms_property_ids', '=', False),('pms_property_ids', 'in', "
"pms_property_ids)]",
check_pms_properties=True,
)
default_code = fields.Char(
string="Internal Reference", help="Internal unique identifier of the amenity"
)
@api.constrains(
"pms_amenity_type_id",
"pms_property_ids",
)
def _check_property_integrity(self):
for rec in self:
if rec.pms_amenity_type_id and rec.pms_amenity_type_id.pms_property_ids:
res = rec.pms_property_ids - rec.pms_amenity_type_id.pms_property_ids
if res:
raise ValidationError(_("Property not allowed"))

View File

@@ -1,13 +1,13 @@
# Copyright 2017 Alexandre Díaz
# Copyright 2017 Dario Lodeiros
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
from odoo import fields, models
class PmsRoomAmenityType(models.Model):
_name = "pms.amenity.type"
_description = "Amenity Type"
_check_pms_properties_auto = True
active = fields.Boolean(
string="Active",
@@ -25,24 +25,16 @@ class PmsRoomAmenityType(models.Model):
help="Properties with access to the element;"
" if not set, all properties can access",
comodel_name="pms.property",
ondelete="restrict",
relation="pms_amenity_type_pms_property_rel",
column1="amenity_type_id",
column2="pms_property_id",
check_pms_properties=True,
)
pms_amenity_ids = fields.One2many(
string="Amenities In This Category",
help="Amenities included in this type",
comodel_name="pms.amenity",
inverse_name="pms_amenity_type_id",
check_pms_properties=True,
)
@api.constrains(
"pms_property_ids",
"pms_amenity_ids",
)
def _check_property_integrity(self):
for rec in self:
if rec.pms_property_ids:
res = rec.pms_amenity_ids.pms_property_ids - rec.pms_property_ids
if res:
raise ValidationError(_("Property not allowed"))

View File

@@ -7,6 +7,7 @@ from odoo.exceptions import ValidationError
class PmsAvailability(models.Model):
_name = "pms.availability"
_description = "Room type availability per day"
_check_pms_properties_auto = True
room_type_id = fields.Many2one(
string="Room Type",
@@ -15,6 +16,7 @@ class PmsAvailability(models.Model):
required=True,
comodel_name="pms.room.type",
ondelete="cascade",
check_pms_properties=True,
)
date = fields.Date(
string="Date",
@@ -37,6 +39,7 @@ class PmsAvailability(models.Model):
readonly=True,
comodel_name="pms.reservation.line",
inverse_name="avail_id",
check_pms_properties=True,
)
real_avail = fields.Integer(
string="Real Avail",

View File

@@ -13,6 +13,7 @@ class PmsAvailabilityPlan(models.Model):
_name = "pms.availability.plan"
_description = "Reservation availability plan"
_check_pms_properties_auto = True
@api.model
def _get_default_pms_property(self):
@@ -26,15 +27,18 @@ class PmsAvailabilityPlan(models.Model):
help="Properties with access to the element;"
" if not set, all properties can access",
comodel_name="pms.property",
ondelete="restrict",
relation="pms_availability_plan_pms_property_rel",
column1="availability_plan_id",
column2="pms_property_id",
check_pms_properties=True,
)
pms_pricelist_ids = fields.One2many(
string="Pricelists",
help="Pricelists of the availability plan ",
comodel_name="product.pricelist",
inverse_name="availability_plan_id",
check_pms_properties=True,
)
rule_ids = fields.One2many(
@@ -42,6 +46,7 @@ class PmsAvailabilityPlan(models.Model):
help="Rules in a availability plan",
comodel_name="pms.availability.plan.rule",
inverse_name="availability_plan_id",
check_pms_properties=True,
)
active = fields.Boolean(
@@ -51,76 +56,6 @@ class PmsAvailabilityPlan(models.Model):
default=True,
)
@api.model
def get_count_rooms_available(
self,
checkin,
checkout,
room_type_id,
pms_property_id,
current_lines=False,
pricelist_id=False,
):
if current_lines and not isinstance(current_lines, list):
current_lines = [current_lines]
avail = self.get_count_real_free_rooms(
checkin, checkout, room_type_id, pms_property_id, current_lines
)
domain_rules = [
("date", ">=", checkin),
(
"date",
"<=",
checkout,
), # TODO: only closed_departure take account checkout date!
("room_type_id", "=", room_type_id),
("pms_property_id", "=", pms_property_id),
]
if pricelist_id:
pricelist = self.env["product.pricelist"].browse(pricelist_id)
if pricelist and pricelist.availability_plan_id:
domain_rules.append(
("availability_plan_id", "=", pricelist.availability_plan_id.id)
)
rule_items = self.env["pms.availability.plan.rule"].search(domain_rules)
if len(rule_items) > 0:
for item in rule_items:
if self.any_rule_applies(checkin, checkout, item):
return 0
avail = min(rule_items.mapped("plan_avail"))
return avail
def get_count_real_free_rooms(
self,
checkin,
checkout,
room_type_id,
pms_property_id,
current_lines=False,
):
Avail = self.env["pms.availability"]
count_free_rooms = len(self.env["pms.room.type"].browse(room_type_id).room_ids)
if isinstance(checkin, str):
checkin = datetime.datetime.strptime(
checkin, DEFAULT_SERVER_DATE_FORMAT
).date()
if isinstance(checkout, str):
checkout = datetime.datetime.strptime(
checkout, DEFAULT_SERVER_DATE_FORMAT
).date()
for avail in Avail.search(
[
("date", ">=", checkin),
("date", "<=", checkout - datetime.timedelta(1)),
("room_type_id", "=", room_type_id),
("pms_property_id", "=", pms_property_id),
]
):
if avail.real_avail < count_free_rooms:
count_free_rooms = avail.real_avail
return count_free_rooms
@classmethod
def any_rule_applies(cls, checkin, checkout, item):
reservation_len = (checkout - checkin).days
@@ -224,6 +159,80 @@ class PmsAvailabilityPlan(models.Model):
domain_rooms.append(("room_type_id", "=", room_type_id))
return self.env["pms.room"].search(domain_rooms)
@api.model
def get_count_rooms_available(
self,
checkin,
checkout,
room_type_id,
pms_property_id,
current_lines=False,
pricelist_id=False,
):
if current_lines and not isinstance(current_lines, list):
current_lines = [current_lines]
avail = self.get_count_real_free_rooms(
checkin, checkout, room_type_id, pms_property_id, current_lines
)
domain_rules = [
("date", ">=", checkin),
(
"date",
"<=",
checkout,
), # TODO: only closed_departure take account checkout date!
("room_type_id", "=", room_type_id),
("pms_property_id", "=", pms_property_id),
]
if pricelist_id:
pricelist = self.env["product.pricelist"].browse(pricelist_id)
if pricelist and pricelist.availability_plan_id:
domain_rules.append(
("availability_plan_id", "=", pricelist.availability_plan_id.id)
)
rule_items = self.env["pms.availability.plan.rule"].search(domain_rules)
if len(rule_items) > 0:
for item in rule_items:
if self.any_rule_applies(checkin, checkout, item):
return 0
avail = min(rule_items.mapped("plan_avail"))
return avail
def get_count_real_free_rooms(
self,
checkin,
checkout,
room_type_id,
pms_property_id,
current_lines=False,
):
Avail = self.env["pms.availability"]
count_free_rooms = len(
self.env["pms.room.type"]
.browse(room_type_id)
.room_ids.filtered(lambda r: r.pms_property_id.id == pms_property_id)
)
if isinstance(checkin, str):
checkin = datetime.datetime.strptime(
checkin, DEFAULT_SERVER_DATE_FORMAT
).date()
if isinstance(checkout, str):
checkout = datetime.datetime.strptime(
checkout, DEFAULT_SERVER_DATE_FORMAT
).date()
for avail in Avail.search(
[
("date", ">=", checkin),
("date", "<=", checkout - datetime.timedelta(1)),
("room_type_id", "=", room_type_id),
("pms_property_id", "=", pms_property_id),
]
):
if avail.real_avail < count_free_rooms:
count_free_rooms = avail.real_avail
return count_free_rooms
@api.model
def splitted_availability(
self,

View File

@@ -7,6 +7,7 @@ from odoo.exceptions import ValidationError
class PmsAvailabilityPlanRule(models.Model):
_name = "pms.availability.plan.rule"
_description = "Reservation rule by day"
_check_pms_properties_auto = True
availability_plan_id = fields.Many2one(
string="Availability Plan",
@@ -14,6 +15,7 @@ class PmsAvailabilityPlanRule(models.Model):
index=True,
comodel_name="pms.availability.plan",
ondelete="cascade",
check_pms_properties=True,
)
room_type_id = fields.Many2one(
string="Room Type",
@@ -21,6 +23,7 @@ class PmsAvailabilityPlanRule(models.Model):
required=True,
comodel_name="pms.room.type",
ondelete="cascade",
check_pms_properties=True,
)
date = fields.Date(
string="Date",
@@ -83,17 +86,6 @@ class PmsAvailabilityPlanRule(models.Model):
required=True,
comodel_name="pms.property",
)
allowed_property_ids = fields.Many2many(
string="Allowed Properties",
help="Allowed properties for user",
store=True,
readonly=True,
compute="_compute_allowed_property_ids",
comodel_name="pms.property",
relation="allowed_availability_move_rel",
column1="availability_plan_rule_id",
column2="property_id",
)
avail_id = fields.Many2one(
string="Avail record",
comodel_name="pms.availability",
@@ -101,6 +93,7 @@ class PmsAvailabilityPlanRule(models.Model):
store=True,
readonly=False,
ondelete="restrict",
check_pms_properties=True,
)
real_avail = fields.Integer(
string="Real availability",
@@ -171,59 +164,6 @@ class PmsAvailabilityPlanRule(models.Model):
if not record.max_avail:
record.max_avail = record.room_type_id.default_max_avail
@api.depends(
"availability_plan_id.pms_property_ids", "room_type_id.pms_property_ids"
)
def _compute_allowed_property_ids(self):
for rule in self:
properties = []
if not (
rule.availability_plan_id.pms_property_ids
or rule.room_type_id.pms_property_ids
):
rule.allowed_property_ids = False
else:
if rule.availability_plan_id.pms_property_ids:
if rule.room_type_id.pms_property_ids:
for prp in rule.availability_plan_id.pms_property_ids:
if prp in rule.room_type_id.pms_property_ids:
properties.append(prp)
rule.allowed_property_ids = [
(4, prop.id) for prop in properties
]
else:
rule.allowed_property_ids = (
rule.availability_plan_id.pms_property_ids
)
else:
rule.allowed_property_ids = rule.room_type_id.pms_property_ids
@api.constrains(
"allowed_property_ids",
"pms_property_id",
)
def _check_property_integrity(self):
for rec in self:
if rec.pms_property_id and rec.allowed_property_ids:
if rec.pms_property_id.id not in rec.allowed_property_ids.ids:
raise ValidationError(_("Property not allowed"))
# @api.constrains(
# "allowed_property_ids",
# "pms_property_ids",
# )
# def _check_property_integrity(self):
# for rule in self:
# for p in rule.pms_property_ids:
# allowed = list(
# set(rule.room_type_id.pms_property_ids.ids)
# &
# set(rule.availability_plan_id.pms_property_ids.ids))
# if p.id not in allowed:
# raise ValidationError(_("Property not allowed"))
@api.constrains("min_stay", "min_stay_arrival", "max_stay", "max_stay_arrival")
def _check_min_max_stay(self):
for record in self:

View File

@@ -7,6 +7,7 @@ from odoo.exceptions import ValidationError
class PmsBoardService(models.Model):
_name = "pms.board.service"
_description = "Board Services"
_check_pms_properties_auto = True
name = fields.Char(
string="Board Service Name",
@@ -32,10 +33,12 @@ class PmsBoardService(models.Model):
help="Properties with access to the element;"
" if not set, all properties can access",
required=False,
ondelete="restrict",
comodel_name="pms.property",
relation="pms_board_service_pms_property_rel",
column1="board_service_id",
column2="pms_property_id",
check_pms_properties=True,
)
pms_board_service_room_type_ids = fields.One2many(
string="Board Services Room Type",

View File

@@ -1,12 +1,12 @@
# Copyright 2017 Dario Lodeiros
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
from odoo import api, fields, models
class PmsBoardServiceLine(models.Model):
_name = "pms.board.service.line"
_description = "Services on Board Service included"
_check_pms_properties_auto = True
pms_board_service_id = fields.Many2one(
string="Board Service",
@@ -14,19 +14,25 @@ class PmsBoardServiceLine(models.Model):
required=True,
comodel_name="pms.board.service",
ondelete="cascade",
check_pms_properties=True,
)
product_id = fields.Many2one(
string="Product",
help="Product associated with this board service line",
required=True,
comodel_name="product.product",
check_pms_properties=True,
)
pms_property_ids = fields.Many2many(
string="Properties",
help="Properties with access to the element;"
" if not set, all properties can access",
comodel_name="pms.property",
related="pms_board_service_id.pms_property_ids",
relation="pms_board_service_line_pms_property_rel",
column1="pms_board_service_line_id",
column2="pms_property_id",
store=True,
check_pms_properties=True,
)
amount = fields.Float(
string="Amount",
@@ -44,10 +50,33 @@ class PmsBoardServiceLine(models.Model):
if self.product_id:
self.update({"amount": self.product_id.list_price})
@api.constrains("pms_property_ids", "product_id")
def _check_property_integrity(self):
for record in self:
if record.pms_property_ids and record.product_id.pms_property_ids:
for pms_property in record.pms_property_ids:
if pms_property not in record.product_id.pms_property_ids:
raise ValidationError(_("Property not allowed in product"))
@api.model
def create(self, vals):
properties = False
if "pms_board_service_id" in vals:
board_service = self.env["pms.board.service"].browse(
vals["pms_board_service_id"]
)
properties = board_service.pms_property_ids
if properties:
vals.update(
{
"pms_property_ids": properties,
}
)
return super(PmsBoardServiceLine, self).create(vals)
def write(self, vals):
properties = False
if "pms_board_service_id" in vals:
board_service = self.env["pms.board.service"].browse(
vals["pms_board_service_id"]
)
properties = board_service.pms_property_ids
if properties:
vals.update(
{
"pms_property_ids": properties,
}
)
return super(PmsBoardServiceLine, self).write(vals)

View File

@@ -10,6 +10,7 @@ class PmsBoardServiceRoomType(models.Model):
_rec_name = "pms_board_service_id"
_log_access = False
_description = "Board Service included in Room"
_check_pms_properties_auto = True
pms_board_service_id = fields.Many2one(
string="Board Service",
@@ -18,14 +19,19 @@ class PmsBoardServiceRoomType(models.Model):
index=True,
comodel_name="pms.board.service",
ondelete="cascade",
check_pms_properties=True,
)
pms_property_ids = fields.Many2many(
string="Properties",
help="Properties with access to the element; "
"if not set, all properties can access",
help="Properties with access to the element;"
" if not set, all properties can access",
required=False,
comodel_name="pms.property",
ondelete="restrict",
comodel_name="pms.property",
relation="pms_board_service_room_type_pms_property_rel",
column1="pms_board_service_room_type_id",
column2="pms_property_id",
check_pms_properties=True,
)
pms_room_type_id = fields.Many2one(
string="Room Type",
@@ -33,18 +39,15 @@ class PmsBoardServiceRoomType(models.Model):
required=True,
index=True,
comodel_name="pms.room.type",
domain=[
"|",
("pms_property_ids", "=", False),
("pms_property_ids", "in", pms_property_ids),
],
ondelete="cascade",
check_pms_properties=True,
)
board_service_line_ids = fields.One2many(
string="Board Service Lines",
help="Services included in this Board Service",
comodel_name="pms.board.service.room.type.line",
inverse_name="pms_board_service_room_type_id",
required=True,
)
amount = fields.Float(
string="Amount",
@@ -104,10 +107,28 @@ class PmsBoardServiceRoomType(models.Model):
@api.model
def create(self, vals):
properties = False
if "pms_board_service_id" in vals:
vals.update(
self.prepare_board_service_reservation_ids(vals["pms_board_service_id"])
)
board_service = self.env["pms.board.service"].browse(
vals["pms_board_service_id"]
)
properties = board_service.pms_property_ids
if "pms_room_type_id" in vals:
room_type = self.env["pms.room.type"].browse(vals["pms_room_type_id"])
properties = (
properties + room_type.pms_property_ids
if properties
else room_type.pms_property_ids
)
if properties:
vals.update(
{
"pms_property_ids": properties,
}
)
return super(PmsBoardServiceRoomType, self).create(vals)
def write(self, vals):

View File

@@ -1,12 +1,12 @@
# Copyright 2017 Dario Lodeiros
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
from odoo import api, fields, models
class PmsBoardServiceRoomTypeLine(models.Model):
_name = "pms.board.service.room.type.line"
_description = "Services on Board Service included in Room"
_check_pms_properties_auto = True
# Fields declaration
pms_board_service_room_type_id = fields.Many2one(
@@ -16,12 +16,22 @@ class PmsBoardServiceRoomTypeLine(models.Model):
comodel_name="pms.board.service.room.type",
ondelete="cascade",
)
pms_property_ids = fields.Many2many(
string="Properties",
help="Properties with access to the element;"
" if not set, all properties can access",
comodel_name="pms.property",
relation="pms_board_service_room_type_line_pms_property_rel",
column1="pms_board_service_room_type_id",
column2="pms_property_id",
check_pms_properties=True,
)
product_id = fields.Many2one(
string="Product",
help="Product associated with this board service room type line",
readonly=True,
required=True,
comodel_name="product.product",
readonly=True,
check_pms_properties=True,
)
# TODO def default_amount "amount of service"
amount = fields.Float(
@@ -31,15 +41,33 @@ class PmsBoardServiceRoomTypeLine(models.Model):
digits=("Product Price"),
)
@api.constrains("pms_board_service_room_type_id", "product_id")
def _check_property_integrity(self):
for record in self:
if (
record.pms_board_service_room_type_id.pms_property_ids
and record.product_id.pms_property_ids
):
for (
pms_property
) in record.pms_board_service_room_type_id.pms_property_ids:
if pms_property not in record.product_id.pms_property_ids:
raise ValidationError(_("Property not allowed"))
@api.model
def create(self, vals):
properties = False
if "pms_board_service_room_type_id" in vals:
board_service = self.env["pms.board.service.room.type"].browse(
vals["pms_board_service_room_type_id"]
)
properties = board_service.pms_property_ids
if properties:
vals.update(
{
"pms_property_ids": properties,
}
)
return super(PmsBoardServiceRoomTypeLine, self).create(vals)
def write(self, vals):
properties = False
if "pms_board_service_room_type_id" in vals:
board_service = self.env["pms.board.service.room.type"].browse(
vals["pms_board_service_room_type_id"]
)
properties = board_service.pms_property_ids
if properties:
vals.update(
{
"pms_property_ids": properties,
}
)
return super(PmsBoardServiceRoomTypeLine, self).write(vals)

View File

@@ -8,14 +8,27 @@ from odoo import fields, models
class PmsCancelationRule(models.Model):
_name = "pms.cancelation.rule"
_description = "Cancelation Rules"
_check_pms_properties_auto = True
# Fields declaration
name = fields.Char(string="Cancelation Rule", translate=True, required=True)
pricelist_ids = fields.One2many(
"product.pricelist", "cancelation_rule_id", "Pricelist that use this rule"
"product.pricelist",
"cancelation_rule_id",
"Pricelist that use this rule",
check_pms_properties=True,
)
pms_property_ids = fields.Many2many(
"pms.property", string="Properties", required=False, ondelete="restrict"
string="Properties",
help="Properties with access to the element;"
" if not set, all properties can access",
required=False,
ondelete="restrict",
comodel_name="pms.property",
relation="pms_cancelation_rule_pms_property_rel",
column1="pms_cancelation_rule_id",
column2="pms_property_id",
check_pms_properties=True,
)
active = fields.Boolean("Active", default=True)
days_intime = fields.Integer(
@@ -35,5 +48,3 @@ class PmsCancelationRule(models.Model):
default="all",
)
days_noshow = fields.Integer("NoShow first days", default="2")
# TODO: Constrain coherence pms_property_ids pricelist and cancelation_rules

View File

@@ -13,6 +13,7 @@ class PmsCheckinPartner(models.Model):
_name = "pms.checkin.partner"
_description = "Partner Checkins"
_rec_name = "identifier"
_check_pms_properties_auto = True
# Fields declaration
identifier = fields.Char(
@@ -22,11 +23,15 @@ class PmsCheckinPartner(models.Model):
"res.partner",
domain="[('is_company', '=', False)]",
)
reservation_id = fields.Many2one("pms.reservation")
reservation_id = fields.Many2one(
"pms.reservation",
check_pms_properties=True,
)
folio_id = fields.Many2one(
"pms.folio",
compute="_compute_folio_id",
store=True,
check_pms_properties=True,
)
pms_property_id = fields.Many2one(
"pms.property", store=True, readonly=True, related="folio_id.pms_property_id"

View File

@@ -18,6 +18,7 @@ class PmsFolio(models.Model):
_inherit = ["mail.thread", "mail.activity.mixin", "portal.mixin"]
_order = "date_order"
_check_company_auto = True
_check_pms_properties_auto = True
# Default Methods ang Gets
def name_get(self):
@@ -54,6 +55,7 @@ class PmsFolio(models.Model):
ondelete="restrict",
store=True,
readonly=False,
check_pms_properties=True,
)
reservation_ids = fields.One2many(
"pms.reservation",
@@ -62,6 +64,7 @@ class PmsFolio(models.Model):
states={"done": [("readonly", True)]},
help="Room reservation detail.",
check_company=True,
check_pms_properties=True,
)
number_of_rooms = fields.Integer(
"Number of Rooms",
@@ -69,7 +72,7 @@ class PmsFolio(models.Model):
store="True",
)
number_of_services = fields.Integer(
"Number of Rooms",
"Number of Services",
compute="_compute_number_of_services",
store="True",
)
@@ -81,9 +84,7 @@ class PmsFolio(models.Model):
help="Services detail provide to customer and it will "
"include in main Invoice.",
check_company=True,
domain="['|',"
"('pms_property_id','=',pms_property_id),"
"('pms_property_id','=',False)]",
check_pms_properties=True,
)
sale_line_ids = fields.One2many(
"folio.sale.line",
@@ -98,8 +99,8 @@ class PmsFolio(models.Model):
company_id = fields.Many2one(
"res.company",
"Company",
required=True,
default=lambda self: self.env.company,
compute="_compute_company_id",
store=True,
)
move_line_ids = fields.Many2many(
"account.move.line",
@@ -132,9 +133,7 @@ class PmsFolio(models.Model):
store=True,
readonly=False,
help="Pricelist for current folio.",
domain="['|',"
"(pms_property_id, 'in', 'pms_property_ids'),"
"('pms_property_ids','=',False)]",
check_pms_properties=True,
)
commission = fields.Float(
string="Commission",
@@ -158,6 +157,7 @@ class PmsFolio(models.Model):
string="Agency",
ondelete="restrict",
domain=[("is_agency", "=", True)],
check_pms_properties=True,
)
channel_type_id = fields.Many2one(
"pms.sale.channel",
@@ -167,6 +167,7 @@ class PmsFolio(models.Model):
string="Direct Sale Channel",
ondelete="restrict",
domain=[("channel_type", "=", "direct")],
check_pms_properties=True,
)
transaction_ids = fields.Many2many(
"payment.transaction",
@@ -236,6 +237,7 @@ class PmsFolio(models.Model):
store=True,
readonly=False,
help="Invoice address for current group.",
check_pms_properties=True,
)
# REVIEW THIS
# partner_invoice_state_id = fields.Many2one(related="partner_invoice_id.state_id")
@@ -247,9 +249,7 @@ class PmsFolio(models.Model):
)
closure_reason_id = fields.Many2one(
"room.closure.reason",
domain="['|',"
"(pms_property_id, 'in', 'pms_property_ids'),"
"('pms_property_ids', '=', False)]",
check_pms_properties=True,
)
segmentation_ids = fields.Many2many(
"res.partner.category", string="Segmentation", ondelete="restrict"
@@ -472,6 +472,11 @@ class PmsFolio(models.Model):
for fsl in folio_sale_lines_to_remove:
self.env["folio.sale.line"].browse(fsl).unlink()
@api.depends("pms_property_id")
def _compute_company_id(self):
for record in self:
record.company_id = record.pms_property_id.company_id
@api.model
def generate_reservation_services_sale_lines(self, folio, reservation):
for service in reservation.service_ids:
@@ -1396,18 +1401,6 @@ class PmsFolio(models.Model):
_("The Sale Channel does not correspond to the agency's")
)
@api.constrains(
"closure_reason_id",
)
def _check_property_integrity(self):
for rec in self:
if rec.pms_property_id:
if (
rec.pms_property_id.id
not in rec.closure_reason_id.pms_property_ids.ids
):
raise ValidationError(_("Property not allowed"))
@api.model
def _prepare_down_payment_section_line(self, **optional_values):
"""

View File

@@ -30,6 +30,7 @@ class PmsProperty(models.Model):
help="The company that owns or operates this property.",
comodel_name="res.company",
required=True,
check_pms_properties=True,
)
user_ids = fields.Many2many(
string="Accepted Users",
@@ -45,7 +46,6 @@ class PmsProperty(models.Model):
comodel_name="pms.room",
inverse_name="pms_property_id",
)
# TODO: establecer tarifa publica por defecto
default_pricelist_id = fields.Many2one(
string="Product Pricelist",
help="The default pricelist used in this property.",

View File

@@ -16,7 +16,9 @@ class PmsReservation(models.Model):
_description = "Reservation"
_inherit = ["mail.thread", "mail.activity.mixin", "portal.mixin"]
_order = "priority desc, create_date desc, write_date desc"
# TODO:
# consider near_to_checkin & pending_notifications to order
_check_pms_properties_auto = True
_check_company_auto = True
name = fields.Text(
@@ -37,9 +39,13 @@ class PmsReservation(models.Model):
"empty if reservation is splitted",
copy=False,
comodel_name="pms.room",
domain="[('id', 'in', allowed_room_ids)]",
ondelete="restrict",
domain="["
"('id', 'in', allowed_room_ids),"
"('pms_property_id', '=', pms_property_id),"
"]",
tracking=True,
check_pms_properties=True,
)
allowed_room_ids = fields.Many2many(
string="Allowed Rooms",
@@ -68,12 +74,9 @@ class PmsReservation(models.Model):
readonly=False,
store=True,
comodel_name="pms.board.service.room.type",
domain="["
"'|',"
"('pms_property_ids', 'in', pms_property_id),"
"('pms_property_ids', '=', False)]",
compute="_compute_board_service_room_id",
tracking=True,
check_pms_properties=True,
)
room_type_id = fields.Many2one(
string="Room Type",
@@ -84,11 +87,9 @@ class PmsReservation(models.Model):
copy=False,
store=True,
comodel_name="pms.room.type",
domain="['|',"
"('pms_property_ids', 'in', pms_property_id),"
"('pms_property_ids', '=', False)]",
compute="_compute_room_type_id",
tracking=True,
check_pms_properties=True,
)
partner_id = fields.Many2one(
string="Customer",
@@ -99,6 +100,7 @@ class PmsReservation(models.Model):
ondelete="restrict",
compute="_compute_partner_id",
tracking=True,
check_pms_properties=True,
)
agency_id = fields.Many2one(
string="Agency",
@@ -120,9 +122,7 @@ class PmsReservation(models.Model):
string="Closure Reason",
help="Reason why the reservation cannot be made",
related="folio_id.closure_reason_id",
domain="['|',"
"(pms_property_id, 'in', 'pms_property_ids'),"
"('pms_property_ids', '=', False)]",
check_pms_properties=True,
)
company_id = fields.Many2one(
string="Company",
@@ -150,6 +150,7 @@ class PmsReservation(models.Model):
compute="_compute_reservation_line_ids",
comodel_name="pms.reservation.line",
inverse_name="reservation_id",
check_pms_properties=True,
)
service_ids = fields.One2many(
string="Services",
@@ -158,11 +159,9 @@ class PmsReservation(models.Model):
store=True,
comodel_name="pms.service",
inverse_name="reservation_id",
domain="['|',"
"('pms_property_id', '=', pms_property_id),"
"('pms_property_id', '=', False)]",
compute="_compute_service_ids",
check_company=True,
check_pms_properties=True,
)
pricelist_id = fields.Many2one(
string="Pricelist",
@@ -170,12 +169,10 @@ class PmsReservation(models.Model):
readonly=False,
store=True,
comodel_name="product.pricelist",
domain="['|',"
"('pms_property_ids', 'in', pms_property_id),"
"('pms_property_ids', '=', False)]",
ondelete="restrict",
compute="_compute_pricelist_id",
tracking=True,
check_pms_properties=True,
)
user_id = fields.Many2one(
string="Salesperson",
@@ -216,6 +213,7 @@ class PmsReservation(models.Model):
compute="_compute_checkin_partner_ids",
comodel_name="pms.checkin.partner",
inverse_name="reservation_id",
check_pms_properties=True,
)
count_pending_arrival = fields.Integer(
string="Pending Arrival",
@@ -278,7 +276,7 @@ class PmsReservation(models.Model):
)
currency_id = fields.Many2one(
string="Currency",
hepl="The currency used in relation to the pricelist",
help="The currency used in relation to the pricelist",
readonly=True,
store=True,
related="pricelist_id.currency_id",
@@ -1292,44 +1290,7 @@ class PmsReservation(models.Model):
if record.agency_id and not record.agency_id.is_agency:
raise ValidationError(_("booking agency with wrong configuration: "))
@api.constrains("pms_property_id", "preferred_room_id")
def _check_room_property_integrity(self):
for record in self:
if record.pms_property_id and record.preferred_room_id.pms_property_id:
if record.pms_property_id != record.preferred_room_id.pms_property_id:
raise ValidationError(
_("Property doesn't match with room property")
)
@api.constrains("pms_property_id", "room_type_id")
def _check_room_type_property_integrity(self):
for record in self:
if record.pms_property_id and record.room_type_id.pms_property_ids:
if (
record.pms_property_id.id
not in record.room_type_id.pms_property_ids.ids
):
raise ValidationError(_("Property isn't allowed in Room Type"))
@api.constrains("pms_property_id", "pricelist_id")
def _check_pricelist_property_integrity(self):
for record in self:
if record.pms_property_id and record.pricelist_id.pms_property_ids:
if (
record.pms_property_id.id
not in record.pricelist_id.pms_property_ids.ids
):
raise ValidationError(_("Property isn't allowed in Pricelist"))
@api.constrains("pms_property_id", "board_service_room_id")
def _check_board_service_property_integrity(self):
for record in self:
if record.pms_property_id and record.board_service_room_id.pms_property_ids:
if (
record.pms_property_id.id
not in record.board_service_room_id.pms_property_ids.ids
):
raise ValidationError(_("Property isn't allowed in Board Service"))
# Action methods
def open_folio(self):
action = self.env.ref("pms.open_pms_folio1_form_tree_all").sudo().read()[0]

View File

@@ -14,6 +14,7 @@ class PmsReservationLine(models.Model):
_name = "pms.reservation.line"
_description = "Reservations by day"
_order = "date"
_check_company_auto = True
reservation_id = fields.Many2one(
string="Reservation",
@@ -22,6 +23,7 @@ class PmsReservationLine(models.Model):
copy=False,
comodel_name="pms.reservation",
ondelete="cascade",
check_pms_properties=True,
)
room_id = fields.Many2one(
string="Room",
@@ -31,6 +33,7 @@ class PmsReservationLine(models.Model):
compute="_compute_room_id",
comodel_name="pms.room",
ondelete="restrict",
check_pms_properties=True,
)
sale_line_ids = fields.Many2many(
@@ -41,6 +44,7 @@ class PmsReservationLine(models.Model):
relation="reservation_line_sale_line_rel",
column1="reservation_line_id",
column2="sale_line_id",
check_pms_properties=True,
)
pms_property_id = fields.Many2one(
string="Property",
@@ -84,6 +88,7 @@ class PmsReservationLine(models.Model):
comodel_name="pms.availability",
ondelete="restrict",
compute="_compute_avail_id",
check_pms_properties=True,
)
discount = fields.Float(

View File

@@ -15,6 +15,7 @@ class PmsRoom(models.Model):
_name = "pms.room"
_description = "Property Room"
_order = "sequence, room_type_id, name"
_check_pms_properties_auto = True
name = fields.Char(
string="Room Name",
@@ -44,14 +45,10 @@ class PmsRoom(models.Model):
help="Unique room type for the rooms",
required=True,
comodel_name="pms.room.type",
domain=[
"|",
("pms_property_ids", "=", False),
(pms_property_id, "in", "pms_property_ids"),
],
ondelete="restrict",
check_pms_properties=True,
)
# TODO: Dario, design shared rooms
# TODO: design shared rooms
shared_room_id = fields.Many2one(
string="Shared Room",
help="The room can be sold by beds",
@@ -62,11 +59,7 @@ class PmsRoom(models.Model):
string="Ubication",
help="At which ubication the room is located.",
comodel_name="pms.ubication",
domain=[
"|",
("pms_property_ids", "=", False),
(pms_property_id, "in", "pms_property_ids"),
],
check_pms_properties=True,
)
capacity = fields.Integer(
string="Capacity", help="The maximum number of people that can occupy a room"
@@ -85,18 +78,6 @@ class PmsRoom(models.Model):
translate=True,
)
allowed_property_ids = fields.Many2many(
string="Allowed Properties",
help="Allowed properties for rooms",
store=True,
readonly=True,
compute="_compute_allowed_property_ids",
comodel_name="pms.property",
relation="room_property_rel",
column1="room_id",
column2="property_id",
)
_sql_constraints = [
(
"room_property_unique",
@@ -115,30 +96,7 @@ class PmsRoom(models.Model):
result.append((room.id, name))
return result
@api.depends(
"room_type_id",
"room_type_id.pms_property_ids",
"ubication_id",
"ubication_id.pms_property_ids",
)
# TODO: Dario, revisar flujo de allowed properties
def _compute_allowed_property_ids(self):
for record in self:
if not (
record.room_type_id.pms_property_ids
or record.ubication_id.pms_property_ids
):
record.allowed_property_ids = self.env["pms.property"].search([])
elif not record.room_type_id.pms_property_ids:
record.allowed_property_ids = record.ubication_id.pms_property_ids
elif not record.ubication_id.pms_property_ids:
record.allowed_property_ids = record.room_type_id.pms_property_ids
else:
record.allowed_property_ids = (
record.room_type_id.pms_property_ids
& record.ubication_id.pms_property_ids
)
# Constraints and onchanges
@api.constrains("capacity")
def _check_capacity(self):
for record in self:
@@ -150,17 +108,7 @@ class PmsRoom(models.Model):
)
)
@api.constrains(
"allowed_property_ids",
"pms_property_id",
)
def _check_property_integrity(self):
for rec in self:
if rec.pms_property_id:
if rec.pms_property_id.id not in rec.allowed_property_ids.ids:
raise ValidationError(
_("Property not allowed in room type or in ubication")
)
# Business methods
def get_capacity(self, extra_bed=0):
for record in self:

View File

@@ -6,6 +6,7 @@ from odoo import fields, models
class RoomClosureReason(models.Model):
_name = "room.closure.reason"
_description = "Cause of out of service"
_check_pms_properties_auto = True
name = fields.Char(
string="Name",
@@ -22,6 +23,7 @@ class RoomClosureReason(models.Model):
column1="room_closure_reason_type_id",
column2="pms_property_id",
ondelete="restrict",
check_pms_properties=True,
)
description = fields.Text(
string="Description",

View File

@@ -17,6 +17,7 @@ class PmsRoomType(models.Model):
_description = "Room Type"
_inherits = {"product.product": "product_id"}
_order = "sequence,default_code,name"
_check_pms_properties_auto = True
sequence = fields.Integer(
string="Sequence",
@@ -30,36 +31,28 @@ class PmsRoomType(models.Model):
required=True,
delegate=True,
ondelete="cascade",
# check_pms_properties=True,
)
room_ids = fields.One2many(
string="Rooms",
help="Rooms that belong to room type.",
comodel_name="pms.room",
inverse_name="room_type_id",
domain="["
"'|', "
"('pms_property_id', '=', False), "
"('pms_property_id','in', pms_property_ids)"
"]",
check_pms_properties=True,
)
class_id = fields.Many2one(
string="Property Type Class",
help="Class to which the room type belongs",
comodel_name="pms.room.type.class",
required=True,
domain="["
"'|', "
"('pms_property_ids', '=', False), "
"('pms_property_ids', 'in', pms_property_ids)"
"]",
check_pms_properties=True,
)
board_service_room_type_ids = fields.One2many(
string="Board Services",
help="Board Service included in room type",
comodel_name="pms.board.service.room.type",
inverse_name="pms_room_type_id",
domain="['|', ('pms_property_ids', '=', False), ('pms_property_ids', 'in', "
"pms_property_ids)]",
check_pms_properties=True,
)
room_amenity_ids = fields.Many2many(
string="Room Type Amenities",
@@ -68,11 +61,7 @@ class PmsRoomType(models.Model):
relation="pms_room_type_amenity_rel",
column1="room_type_id",
column2="amenity_id",
domain="["
"'|', "
"('pms_property_ids', '=', False), "
"('pms_property_ids', 'in', pms_property_ids)"
"]",
check_pms_properties=True,
)
default_code = fields.Char(
string="Code",
@@ -171,16 +160,6 @@ class PmsRoomType(models.Model):
)
return self.browse(list(res.values()))
@api.constrains("pms_property_ids", "class_id")
def _check_integrity_property_class(self):
for record in self:
if record.pms_property_ids and record.class_id.pms_property_ids:
for pms_property in record.pms_property_ids:
if pms_property.id not in record.class_id.pms_property_ids.ids:
raise ValidationError(
_("Property isn't allowed in Room Type Class")
)
@api.constrains("default_code", "pms_property_ids", "company_id")
def _check_code_property_company_uniqueness(self):
msg = _("Already exists another room type with the same code and properties")
@@ -203,39 +182,6 @@ class PmsRoomType(models.Model):
if other and other != rec:
raise ValidationError(msg)
@api.constrains("room_amenity_ids", "pms_property_ids")
def _check_integrity_property_amenity(self):
for record in self:
if record.room_amenity_ids.pms_property_ids and record.pms_property_ids:
for pms_property in record.pms_property_ids:
if pms_property not in record.room_amenity_ids.pms_property_ids:
raise ValidationError(_("Property not allowed in amenity"))
@api.constrains("room_ids", "pms_property_ids")
def _check_integrity_property_room(self):
for record in self:
if record.room_ids and record.pms_property_ids:
for room in record.room_ids:
if room.pms_property_id not in record.pms_property_ids:
raise ValidationError(_("Property not allowed in room"))
# TODO: Not allowed repeat boardservice on room_type with
# same properties os without properties
@api.constrains("board_service_room_type_ids", "pms_property_ids")
def _check_integrity_property_board_service_room_type(self):
for record in self:
if record.board_service_room_type_ids and record.pms_property_ids:
for board_service_room_type in record.board_service_room_type_ids:
if board_service_room_type.pms_property_ids:
for pms_property in record.pms_property_ids:
if (
pms_property
not in board_service_room_type.pms_property_ids
):
raise ValidationError(
_("Property not allowed in board service room type")
)
# ORM Overrides
# TODO: Review Check product fields default values to room
@api.model

View File

@@ -42,15 +42,19 @@ class PmsRoomTypeClass(models.Model):
column1="room_type_class_id",
column2="pms_property_id",
ondelete="restrict",
check_pms_properties=True,
)
room_type_ids = fields.One2many(
string="Types",
help="Room Types that belong to this Room Type Class",
comodel_name="pms.room.type",
inverse_name="class_id",
check_pms_properties=True,
)
default_code = fields.Char(
string="Code", help="Room type class identification code", required=True
string="Code",
help="Room type class identification code",
required=True,
)
@api.model

View File

@@ -4,6 +4,7 @@ from odoo import fields, models
class PmsSaleChannel(models.Model):
_name = "pms.sale.channel"
_description = "Sales Channel"
_check_pms_properties_auto = True
name = fields.Text(string="Sale Channel Name", help="The name of the sale channel")
channel_type = fields.Selection(
@@ -23,4 +24,17 @@ class PmsSaleChannel(models.Model):
relation="pms_sale_channel_product_pricelist_rel",
column1="pms_sale_channel_id",
column2="product_pricelist_id",
check_pms_properties=True,
)
pms_property_ids = fields.Many2many(
string="Properties",
help="Properties with access to the element;"
" if not set, all properties can access",
required=False,
ondelete="restrict",
comodel_name="pms.property",
relation="pms_sale_channel_pms_property_rel",
column1="pms_sale_channel_id",
column2="pms_property_id",
check_pms_properties=True,
)

View File

@@ -12,6 +12,7 @@ _logger = logging.getLogger(__name__)
class PmsService(models.Model):
_name = "pms.service"
_description = "Services and its charges"
_check_pms_properties_auto = True
name = fields.Char(
string="Service description",
@@ -26,6 +27,7 @@ class PmsService(models.Model):
required=True,
comodel_name="product.product",
ondelete="restrict",
check_pms_properties=True,
)
folio_id = fields.Many2one(
string="Folio",
@@ -34,6 +36,7 @@ class PmsService(models.Model):
store=True,
comodel_name="pms.folio",
compute="_compute_folio_id",
check_pms_properties=True,
)
sale_line_ids = fields.One2many(
string="Sale Lines",
@@ -41,6 +44,7 @@ class PmsService(models.Model):
copy=False,
comodel_name="folio.sale.line",
inverse_name="service_id",
check_pms_properties=True,
)
reservation_id = fields.Many2one(
string="Room",
@@ -48,6 +52,7 @@ class PmsService(models.Model):
default=lambda self: self._default_reservation_id(),
comodel_name="pms.reservation",
ondelete="cascade",
check_pms_properties=True,
)
service_line_ids = fields.One2many(
string="Service Lines",
@@ -57,6 +62,7 @@ class PmsService(models.Model):
comodel_name="pms.service.line",
inverse_name="service_id",
compute="_compute_service_line_ids",
check_pms_properties=True,
)
company_id = fields.Many2one(
string="Company",

View File

@@ -10,6 +10,7 @@ class PmsServiceLine(models.Model):
_description = "Service by day"
_order = "date"
_rec_name = "service_id"
_check_pms_properties_auto = True
service_id = fields.Many2one(
string="Service Room",
@@ -30,6 +31,7 @@ class PmsServiceLine(models.Model):
help="Product associated with this service line",
store=True,
related="service_id.product_id",
check_pms_properties=True,
)
tax_ids = fields.Many2many(
string="Taxes",
@@ -93,6 +95,7 @@ class PmsServiceLine(models.Model):
readonly=True,
store=True,
related="service_id.reservation_id",
check_pms_properties=True,
)
discount = fields.Float(
string="Discount (%)",

View File

@@ -10,6 +10,8 @@ class PmsSharedRoom(models.Model):
_name = "pms.shared.room"
_description = "Shared Room"
_order = "room_type_id, name"
_check_pms_properties_auto = True
name = fields.Char(
string="Room Name", help="Name of the shared room", required=True
)
@@ -39,6 +41,7 @@ class PmsSharedRoom(models.Model):
relation="pms_shared_room_pms_property_rel",
column1="shared_room_id",
column2="pms_property_id",
check_pms_properties=True,
)
ubication_id = fields.Many2one(
string="Ubication",

View File

@@ -7,6 +7,7 @@ from odoo.exceptions import ValidationError
class PmsUbication(models.Model):
_name = "pms.ubication"
_description = "Ubication"
_check_pms_properties_auto = True
name = fields.Char(
string="Ubication Name",
@@ -27,12 +28,15 @@ class PmsUbication(models.Model):
relation="pms_ubication_pms_property_rel",
column1="ubication_type_id",
column2="pms_property_id",
ondelete="restrict",
check_pms_properties=True,
)
pms_room_ids = fields.One2many(
string="Rooms",
help="Rooms found in this location",
comodel_name="pms.room",
inverse_name="ubication_id",
check_pms_properties=True,
)
@api.constrains(

View File

@@ -2,8 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
from odoo import fields, models
_logger = logging.getLogger(__name__)
@@ -15,37 +14,44 @@ class ProductPricelist(models.Model):
"""
_inherit = "product.pricelist"
_check_pms_properties_auto = True
# Fields declaration
pms_property_ids = fields.Many2many(
"pms.property", string="Properties", required=False, ondelete="restrict"
string="Properties",
help="Properties with access to the element;"
" if not set, all properties can access",
required=False,
comodel_name="pms.property",
relation="product_pricelist_pms_property_rel",
column1="product_pricelist_id",
column2="pms_property_id",
ondelete="restrict",
check_pms_properties=True,
)
company_id = fields.Many2one(
check_pms_properties=True,
)
cancelation_rule_id = fields.Many2one(
"pms.cancelation.rule",
string="Cancelation Policy",
domain=[
"|",
("pms_property_ids", "=", False),
("pms_property_ids", "in", pms_property_ids),
],
check_pms_properties=True,
)
pricelist_type = fields.Selection(
[("daily", "Daily Plan")], string="Pricelist Type", default="daily"
)
pms_sale_channel_ids = fields.Many2many(
"pms.sale.channel", string="Available Channels"
"pms.sale.channel",
string="Available Channels",
check_pms_properties=True,
)
availability_plan_id = fields.Many2one(
comodel_name="pms.availability.plan",
string="Availability Plan",
ondelete="restrict",
domain=[
"|",
("pms_property_ids", "=", False),
("pms_property_ids", "in", pms_property_ids),
],
check_pms_properties=True,
)
item_ids = fields.One2many(check_pms_properties=True)
# Constraints and onchanges
# @api.constrains("pricelist_type", "pms_property_ids")
@@ -96,9 +102,9 @@ class ProductPricelist(models.Model):
FROM product_pricelist_item item
LEFT JOIN product_category categ
ON item.categ_id = categ.id
LEFT JOIN pms_property_product_pricelist_rel cab
LEFT JOIN product_pricelist_pms_property_rel cab
ON item.pricelist_id = cab.product_pricelist_id
LEFT JOIN pms_property_product_pricelist_item_rel lin
LEFT JOIN product_pricelist_item_pms_property_rel lin
ON item.id = lin.product_pricelist_item_id
LEFT JOIN board_service_pricelist_item_rel board
ON item.id = board.pricelist_item_id
@@ -121,10 +127,10 @@ class ProductPricelist(models.Model):
item.date_end - item.date_start ASC,
item.date_end_overnight - item.date_start_overnight ASC,
NULLIF((SELECT COUNT(1)
FROM pms_property_product_pricelist_item_rel l
FROM product_pricelist_item_pms_property_rel l
WHERE item.id = l.product_pricelist_item_id)
+ (SELECT COUNT(1)
FROM pms_property_product_pricelist_rel c
FROM product_pricelist_pms_property_rel c
WHERE item.pricelist_id = c.product_pricelist_id),0)
NULLS LAST,
item.id DESC;
@@ -168,25 +174,3 @@ class ProductPricelist(models.Model):
"pricelist_id": self.id,
},
}
@api.constrains(
"cancelation_rule_id",
)
def _check_property_integrity(self):
for rec in self:
if rec.pms_property_ids:
for p in rec.pms_property_ids:
if p.id not in rec.cancelation_rule_id.pms_property_ids.ids:
raise ValidationError(
_("Property not allowed in cancelation rule")
)
@api.constrains("pms_property_ids", "availability_plan_id")
def _check_availability_plan_property_integrity(self):
for record in self:
if record.pms_property_ids and record.availability_plan_id.pms_property_ids:
for pms_property in record.pms_property_ids:
if pms_property not in record.availability_plan_id.pms_property_ids:
raise ValidationError(
_("Property not allowed availability plan")
)

View File

@@ -1,14 +1,22 @@
# Copyright 2017 Alexandre Díaz, Pablo Quesada, Darío Lodeiros
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
from odoo import fields, models
class ProductPricelistItem(models.Model):
_inherit = "product.pricelist.item"
_check_pms_properties_auto = True
pms_property_ids = fields.Many2many(
"pms.property", string="Properties", required=False, ondelete="restrict"
string="Properties",
help="Properties with access to the element;"
" if not set, all properties can access",
comodel_name="pms.property",
relation="product_pricelist_item_pms_property_rel",
column1="product_pricelist_item_id",
column2="pms_property_id",
ondelete="restrict",
check_pms_properties=True,
)
date_start_overnight = fields.Date(
string="Start Date Overnight",
@@ -27,56 +35,8 @@ class ProductPricelistItem(models.Model):
string="Board Services on Room Types",
ondelete="cascade", # check_company=True,
help="""Specify a Board services on Room Types.""",
# domain="[('pms_property_ids', 'in', [allowed_property_ids, False])]",
check_pms_properties=True,
)
allowed_property_ids = fields.Many2many(
"pms.property",
"allowed_pricelist_move_rel",
"pricelist_item_id",
"property_id",
string="Allowed Properties",
store=True,
readonly=True,
compute="_compute_allowed_property_ids",
)
@api.depends("product_id.pms_property_ids", "pricelist_id.pms_property_ids")
def _compute_allowed_property_ids(self):
for record in self:
properties = []
if record.applied_on == "0_product_variant":
product = record.product_id
elif record.applied_on == "1_product":
product = record.product_tmpl_id
else:
product = False
if not record.pricelist_id.pms_property_ids or not product:
record.allowed_property_ids = False
else:
if record.pricelist_id.pms_property_ids:
if product.pms_property_ids:
properties = list(
set(record.pricelist_id.pms_property_ids.ids)
& set(product.pms_property_ids.ids)
)
record.allowed_property_ids = self.env["pms.property"].search(
[("id", "in", properties)]
)
else:
record.allowed_property_ids = product.pms_property_ids
else:
record.allowed_property_ids = product.pms_property_ids
# else:
# record.allowed_property_ids = False
@api.constrains(
"allowed_property_ids",
"pms_property_ids",
)
def _check_property_integrity(self):
for rec in self:
if rec.pms_property_ids and rec.allowed_property_ids:
for p in rec.pms_property_ids:
if p.id not in rec.allowed_property_ids.ids:
raise ValidationError(_("Property not allowed"))
pricelist_id = fields.Many2one(check_pms_properties=True)
product_id = fields.Many2one(check_pms_properties=True)
product_tmpl_id = fields.Many2one(check_pms_properties=True)

View File

@@ -1,8 +1,7 @@
# Copyright 2017 Alexandre Díaz
# Copyright 2017 Dario Lodeiros
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
from odoo import fields, models
class ProductTemplate(models.Model):
@@ -17,6 +16,11 @@ class ProductTemplate(models.Model):
relation="product_template_pms_property_rel",
column1="product_tmpl_id",
column2="pms_property_id",
ondelete="restrict",
check_pms_properties=True,
)
company_id = fields.Many2one(
check_pms_properties=True,
)
per_day = fields.Boolean(
string="Unit increment per day",
@@ -40,16 +44,3 @@ class ProductTemplate(models.Model):
help="Indicates if that product is a extra bed, add +1 capacity in the room",
default=False,
)
@api.constrains("pms_property_ids", "company_id")
def _check_property_company_integrity(self):
for rec in self:
if rec.company_id and rec.pms_property_ids:
property_companies = rec.pms_property_ids.mapped("company_id")
if len(property_companies) > 1 or rec.company_id != property_companies:
raise ValidationError(
_(
"The company of the properties must match "
"the company on the room type"
)
)

View File

@@ -40,6 +40,21 @@ class ResPartner(models.Model):
string="Invoice Agency",
help="Indicates if agency invoices partner",
)
pms_property_ids = fields.Many2many(
string="Properties",
help="Properties with access to the element;"
" if not set, all properties can access",
required=False,
comodel_name="pms.property",
relation="res_partner_pms_property_rel",
column1="res_partner_id",
column2="pms_property_id",
ondelete="restrict",
check_pms_properties=True,
)
company_id = fields.Many2one(
check_pms_properties=True,
)
def _compute_reservations_count(self):
# TODO: recuperar las reservas de los folios del partner

View File

@@ -1,4 +1,4 @@
from odoo.exceptions import ValidationError
from odoo.exceptions import UserError
from .common import TestPms
@@ -51,7 +51,7 @@ class TestPmsAmenity(TestPms):
}
)
# ACT & ASSERT
with self.assertRaises(ValidationError), self.cr.savepoint():
with self.assertRaises(UserError), self.cr.savepoint():
Amenity.create(
{
"name": "TestAmenity1",
@@ -69,115 +69,3 @@ class TestPmsAmenity(TestPms):
],
}
)
def test_property_allowed(self):
# Creation of a Amenity with Properties compatible with it Amenity Type
# Check Properties of Amenity are in Properties of Amenity Type
# +----------------------------------------+-----------------------------------+
# | Amenity Type (TestAmenityType1) | Amenity (TestAmenity1) |
# +----------------------------------------+-----------------------------------+
# | Property1 - Property2 - Property3 | Property1 - Property2 - Property3 |
# +----------------------------------------+-----------------------------------+
# ARRANGE
AmenityType = self.env["pms.amenity.type"]
Amenity = self.env["pms.amenity"]
amenity_type1 = AmenityType.create(
{
"name": "TestAmenityType1",
"pms_property_ids": [
(
6,
0,
[
self.pms_property1.id,
self.pms_property2.id,
self.pms_property3.id,
],
)
],
}
)
# ACT
amenity1 = Amenity.create(
{
"name": "TestAmenity1",
"pms_amenity_type_id": amenity_type1.id,
"pms_property_ids": [
(
6,
0,
[
self.pms_property1.id,
self.pms_property2.id,
self.pms_property3.id,
],
)
],
}
)
# ASSERT
self.assertEqual(
amenity1.pms_property_ids.ids,
amenity_type1.pms_property_ids.ids,
"Properties not allowed in amenity type",
)
def test_change_amenity_property(self):
# Creation of a Amenity with Properties compatible with it Amenity Type
# Delete a Property in Amenity Type, check Validation Error when do that
# 1st scenario:
# +----------------------------------------+-----------------------------------+
# | Amenity Type (TestAmenityType1) | Amenity (TestAmenity1) |
# +----------------------------------------+-----------------------------------+
# | Property1 - Property2 - Property3 | Property1 - Property2 - Property3 |
# +----------------------------------------+-----------------------------------+
# 2nd scenario(Error):
# +----------------------------------------+-----------------------------------+
# | Amenity Type (TestAmenityType1) | Amenity (TestAmenity1) |
# +----------------------------------------+-----------------------------------+
# | Property1 - Property2 | Property1 - Property2 - Property3 |
# +----------------------------------------+-----------------------------------+
# ARRANGE
AmenityType = self.env["pms.amenity.type"]
Amenity = self.env["pms.amenity"]
amenity_type1 = AmenityType.create(
{
"name": "TestAmenityType1",
"pms_property_ids": [
(4, self.pms_property1.id),
(4, self.pms_property2.id),
(4, self.pms_property3.id),
],
}
)
# ACT
Amenity.create(
{
"name": "TestAmenity1",
"pms_amenity_type_id": amenity_type1.id,
"pms_property_ids": [
(
6,
0,
[
self.pms_property1.id,
self.pms_property2.id,
self.pms_property3.id,
],
)
],
}
)
# ASSERT
with self.assertRaises(ValidationError):
amenity_type1.pms_property_ids = [
(
6,
0,
[self.pms_property1.id, self.pms_property2.id],
)
]
amenity_type1.flush()

View File

@@ -3,24 +3,42 @@ import datetime
from freezegun import freeze_time
from odoo import fields
from odoo.exceptions import ValidationError
from odoo.exceptions import UserError, ValidationError
from odoo.tests import common
@freeze_time("1980-01-01")
class TestPmsRoomTypeAvailabilityRules(common.SavepointCase):
def create_common_scenario(self):
# product.pricelist
self.test_pricelist1 = self.env["product.pricelist"].create(
{
"name": "test pricelist 1",
}
)
self.test_pricelist2 = self.env["product.pricelist"].create(
{
"name": "test pricelist 2",
}
)
self.test_property1 = self.env["pms.property"].create(
{
"name": "Property 1",
"company_id": self.env.ref("base.main_company").id,
"default_pricelist_id": self.test_pricelist2.id,
}
)
self.test_property2 = self.env["pms.property"].create(
{
"name": "Property 2",
"company_id": self.env.ref("base.main_company").id,
"default_pricelist_id": self.test_pricelist2.id,
}
)
self.test_pricelist1 = self.env["product.pricelist"].create(
{
"name": "test pricelist 1",
"pms_property_ids": [
(4, self.test_property1.id),
(4, self.test_property2.id),
],
}
)
# pms.availability.plan
self.test_room_type_availability1 = self.env["pms.availability.plan"].create(
{
@@ -148,27 +166,6 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase):
def create_scenario_multiproperty(self):
self.create_common_scenario()
self.test_property1 = self.env["pms.property"].create(
{
"name": "Property 1",
"company_id": self.env.ref("base.main_company").id,
"default_pricelist_id": self.test_pricelist2.id,
"folio_sequence_id": self.folio_sequence.id,
"reservation_sequence_id": self.reservation_sequence.id,
"checkin_sequence_id": self.checkin_sequence.id,
}
)
self.test_property2 = self.env["pms.property"].create(
{
"name": "Property 2",
"company_id": self.env.ref("base.main_company").id,
"default_pricelist_id": self.test_pricelist2.id,
"folio_sequence_id": self.folio_sequence.id,
"reservation_sequence_id": self.reservation_sequence.id,
"checkin_sequence_id": self.checkin_sequence.id,
}
)
self.test_property3 = self.env["pms.property"].create(
{
"name": "Property 3",
@@ -583,6 +580,11 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase):
"pms_property_id": self.test_property.id,
}
)
self.test_pricelist1.pms_property_ids = [
(4, self.test_property1.id),
(4, self.test_property2.id),
(4, self.test_property.id),
]
r1 = self.env["pms.reservation"].create(
{
"pms_property_id": self.test_property.id,
@@ -627,6 +629,11 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase):
"name": "test pricelist 2",
}
)
self.test_pricelist1.pms_property_ids = [
(4, self.test_property1.id),
(4, self.test_property2.id),
(4, self.test_property.id),
]
rule = self.env["pms.availability.plan.rule"].create(
{
"availability_plan_id": self.test_room_type_availability1.id,
@@ -801,52 +808,7 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase):
# ASSERT
for test_case in test_cases:
with self.subTest(k=test_case):
with self.assertRaises(ValidationError):
with self.assertRaises(UserError):
self.availability_rule1.pms_property_id = test_case[
"pms_property_id"
]
def test_compute_allowed_property_ids(self):
# TEST CASE:
#
# ARRANGE
self.create_scenario_multiproperty()
# create new room_type
self.test_room_type_special = self.env["pms.room.type"].create(
{
"pms_property_ids": [
(4, self.test_property1.id),
(4, self.test_property3.id),
],
"name": "Special Room Test",
"default_code": "SP_Test",
"class_id": self.test_room_type_class.id,
}
)
# ACT
self.availability_example = self.env["pms.availability.plan"].create(
{
"name": "Availability plan for TEST",
"pms_pricelist_ids": [(6, 0, [self.test_pricelist1.id])],
"pms_property_ids": [
(4, self.test_property1.id),
(4, self.test_property2.id),
],
}
)
self.availability_rule1 = self.env["pms.availability.plan.rule"].create(
{
"availability_plan_id": self.availability_example.id,
"room_type_id": self.test_room_type_special.id,
"date": (fields.datetime.today() + datetime.timedelta(days=2)).date(),
"closed": True,
"pms_property_id": self.test_property1.id,
}
)
self.assertIn(
self.test_property1.id,
self.availability_rule1.allowed_property_ids.mapped("id"),
"error",
)

View File

@@ -1,4 +1,4 @@
from odoo.exceptions import ValidationError
from odoo.exceptions import UserError
from odoo.tests import common
@@ -63,7 +63,7 @@ class TestPmsBoardService(common.SavepointCase):
"default_code": "CB",
}
)
with self.assertRaises(ValidationError):
with self.assertRaises(UserError):
board_service_line = self.board_service_line = self.env[
"pms.board.service.line"
].create(

View File

@@ -1,4 +1,4 @@
from odoo.exceptions import ValidationError
from odoo.exceptions import UserError
from odoo.tests import common
@@ -57,19 +57,21 @@ class TestPmsBoardServiceRoomTypeLine(common.SavepointCase):
{
"name": "Board Service",
"default_code": "CB",
"pms_property_ids": self.property1,
}
)
self.room_type_class = self.env["pms.room.type.class"].create(
{
"name": "Room Type Class",
"pms_property_ids": self.property1,
"default_code": "SIN1",
"pms_property_ids": self.property1,
}
)
self.room_type = self.env["pms.room.type"].create(
{
"name": "Room Type",
"default_code": "Type1",
"pms_property_ids": self.property1,
"class_id": self.room_type_class.id,
}
)
@@ -84,8 +86,7 @@ class TestPmsBoardServiceRoomTypeLine(common.SavepointCase):
self.product = self.env["product.product"].create(
{"name": "Product", "pms_property_ids": self.property2}
)
with self.assertRaises(ValidationError):
with self.assertRaises(UserError):
self.env["pms.board.service.room.type.line"].create(
{
"pms_board_service_room_type_id": self.board_service_room_type.id,

View File

@@ -3,7 +3,7 @@ import datetime
from freezegun import freeze_time
from odoo import fields
from odoo.exceptions import ValidationError
from odoo.exceptions import UserError
from odoo.tests import common
freeze_time("2000-02-02")
@@ -279,7 +279,7 @@ class TestPmsFolio(common.SavepointCase):
}
)
with self.assertRaises(ValidationError):
with self.assertRaises(UserError):
self.env["pms.folio"].create(
{
"pms_property_id": self.property3.id,

View File

@@ -1,6 +1,6 @@
import datetime
from odoo.exceptions import ValidationError
from odoo.exceptions import UserError, ValidationError
from odoo.tests import common, tagged
@@ -124,7 +124,7 @@ class TestPmsPricelist(common.SavepointCase):
# ARRANGE
self.create_common_scenario()
# ACT & ASSERT
with self.assertRaises(ValidationError):
with self.assertRaises(UserError):
self.item1 = self.env["product.pricelist.item"].create(
{
"name": "item_1",
@@ -149,7 +149,7 @@ class TestPmsPricelist(common.SavepointCase):
}
)
# ASSERT
with self.assertRaises(ValidationError):
with self.assertRaises(UserError):
self.item1 = self.env["product.pricelist.item"].create(
{
"name": "item_1",
@@ -175,7 +175,7 @@ class TestPmsPricelist(common.SavepointCase):
}
)
# ASSERT
with self.assertRaises(ValidationError):
with self.assertRaises(UserError):
Pricelist.create(
{
"name": "Pricelist Test",
@@ -189,7 +189,7 @@ class TestPmsPricelist(common.SavepointCase):
self.availability_plan = self.env["pms.availability.plan"].create(
{"name": "Availability Plan", "pms_property_ids": [self.property1.id]}
)
with self.assertRaises(ValidationError):
with self.assertRaises(UserError):
self.env["product.pricelist"].create(
{
"name": "Pricelist",

View File

@@ -122,7 +122,6 @@ class TestPmsPricelistRules(common.SavepointCase):
"partner_id": self.partner1.id,
}
)
# ACT
n_days = (reservation.checkout - reservation.checkin).days
expected_price = self.room.room_type_id.list_price * n_days
@@ -147,7 +146,7 @@ class TestPmsPricelistRules(common.SavepointCase):
# 5. id
# - tie
# - no [date_start|date_end|date_start_overnight|date_end_overnight]
properties = self.room_type.product_id.pms_property_ids.ids
test_cases = [
{
"name": "sorting applied_on",
@@ -164,6 +163,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"applied_on": "0_product_variant",
"product_id": self.room_type.product_id.id,
"fixed_price": 50.0,
"pms_property_ids": properties,
},
{
"pricelist_id": self.pricelist.id,
@@ -171,6 +171,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"product_id": self.room_type.product_id.id,
"product_tmpl_id": self.product_template.id,
"fixed_price": 40.0,
"pms_property_ids": properties,
},
],
},
@@ -186,6 +187,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"date_end": datetime.datetime.now()
+ datetime.timedelta(days=2),
"fixed_price": 60.0,
"pms_property_ids": properties,
},
{
"pricelist_id": self.pricelist.id,
@@ -195,6 +197,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"date_end": datetime.datetime.now()
+ datetime.timedelta(days=1),
"fixed_price": 50.0,
"pms_property_ids": properties,
},
{
"pricelist_id": self.pricelist.id,
@@ -204,6 +207,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"date_end": datetime.datetime.now()
+ datetime.timedelta(days=3),
"fixed_price": 40.0,
"pms_property_ids": properties,
},
],
},
@@ -219,6 +223,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"date_end_overnight": datetime.datetime.now()
+ datetime.timedelta(days=6),
"fixed_price": 60.0,
"pms_property_ids": properties,
},
{
"pricelist_id": self.pricelist.id,
@@ -228,6 +233,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"date_end_overnight": datetime.datetime.now()
+ datetime.timedelta(days=10),
"fixed_price": 50.0,
"pms_property_ids": properties,
},
{
"pricelist_id": self.pricelist.id,
@@ -237,6 +243,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"date_end_overnight": datetime.datetime.now()
+ datetime.timedelta(days=3),
"fixed_price": 40.0,
"pms_property_ids": properties,
},
],
},
@@ -249,6 +256,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"applied_on": "0_product_variant",
"product_id": self.room_type.product_id.id,
"fixed_price": 60.0,
"pms_property_ids": properties,
},
{
"pricelist_id": self.pricelist.id,
@@ -275,18 +283,21 @@ class TestPmsPricelistRules(common.SavepointCase):
"applied_on": "0_product_variant",
"product_id": self.room_type.product_id.id,
"fixed_price": 60.0,
"pms_property_ids": properties,
},
{
"pricelist_id": self.pricelist.id,
"applied_on": "0_product_variant",
"product_id": self.room_type.product_id.id,
"fixed_price": 50.0,
"pms_property_ids": properties,
},
{
"pricelist_id": self.pricelist.id,
"applied_on": "0_product_variant",
"product_id": self.room_type.product_id.id,
"fixed_price": 40.0,
"pms_property_ids": properties,
},
],
},
@@ -302,6 +313,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"date_end": datetime.datetime.now()
+ datetime.timedelta(days=2),
"fixed_price": 60.0,
"pms_property_ids": properties,
},
{
"pricelist_id": self.pricelist.id,
@@ -312,6 +324,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"date_end": datetime.datetime.now()
+ datetime.timedelta(days=1),
"fixed_price": 50.0,
"pms_property_ids": properties,
},
],
},
@@ -327,6 +340,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"date_end": datetime.datetime.now()
+ datetime.timedelta(days=10),
"fixed_price": 120.0,
"pms_property_ids": properties,
},
{
"pricelist_id": self.pricelist.id,
@@ -336,6 +350,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"date_end_overnight": datetime.datetime.now()
+ datetime.timedelta(days=3),
"fixed_price": 50.0,
"pms_property_ids": properties,
},
],
},
@@ -351,6 +366,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"date_end_overnight": datetime.datetime.now()
+ datetime.timedelta(days=3),
"fixed_price": 120.0,
"pms_property_ids": properties,
},
{
"pricelist_id": self.pricelist.id,
@@ -376,6 +392,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"date_end_overnight": datetime.datetime.now()
+ datetime.timedelta(days=3),
"fixed_price": 120.0,
"pms_property_ids": properties,
},
{
"pricelist_id": self.pricelist.id,
@@ -432,6 +449,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"date_end": datetime.datetime.now()
+ datetime.timedelta(days=1),
"fixed_price": 40.0,
"pms_property_ids": properties,
},
],
},
@@ -445,6 +463,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"product_id": self.room_type.product_id.id,
"date_start": datetime.datetime.now(),
"fixed_price": 40.0,
"pms_property_ids": properties,
},
],
},
@@ -458,6 +477,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"product_id": self.room_type.product_id.id,
"date_end_overnight": datetime.datetime.now(),
"fixed_price": 40.0,
"pms_property_ids": properties,
},
],
},
@@ -471,6 +491,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"product_id": self.room_type.product_id.id,
"date_start_overnight": datetime.datetime.now(),
"fixed_price": 40.0,
"pms_property_ids": properties,
},
],
},
@@ -485,6 +506,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"date_start_overnight": datetime.datetime.now(),
"date_end_overnight": datetime.datetime.now(),
"fixed_price": 40.0,
"pms_property_ids": properties,
},
],
},

View File

@@ -951,7 +951,7 @@ class TestPmsReservations(common.SavepointCase):
for test_case in test_cases:
with self.subTest(k=test_case):
with self.assertRaises(ValidationError):
with self.assertRaises(UserError):
self.reservation_test.write(test_case)
@freeze_time("1950-11-01")

View File

@@ -1,6 +1,6 @@
from psycopg2 import IntegrityError
from odoo.exceptions import ValidationError
from odoo.exceptions import UserError
from odoo.tools import mute_logger
from .common import TestPms
@@ -38,9 +38,7 @@ class TestPmsRoom(TestPms):
}
)
# ACT & ARRANGE
with self.assertRaises(
ValidationError, msg="Room has been created and it should't"
):
with self.assertRaises(UserError, msg="Room has been created and it should't"):
self.env["pms.room"].create(
{
"name": "Room 101",
@@ -60,9 +58,7 @@ class TestPmsRoom(TestPms):
}
)
# ACT & ARRANGE
with self.assertRaises(
ValidationError, msg="Room has been created and it should't"
):
with self.assertRaises(UserError, msg="Room has been created and it should't"):
self.env["pms.room"].create(
{
"name": "Room 101",

View File

@@ -1,7 +1,7 @@
# Copyright 2021 Eric Antones <eantones@nuobit.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.exceptions import ValidationError
from odoo.exceptions import UserError, ValidationError
from .common import TestPms
@@ -68,7 +68,7 @@ class TestRoomType(TestPms):
"""
# ARRANGE & ACT & ASSERT
with self.assertRaises(
ValidationError, msg="The room type has been created and it shouldn't"
UserError, msg="The room type has been created and it shouldn't"
):
# room_type1
self.env["pms.room.type"].create(
@@ -95,7 +95,7 @@ class TestRoomType(TestPms):
"""
# ARRANGE & ACT & ASSERT
with self.assertRaises(
ValidationError, msg="The room type has been created and it shouldn't"
UserError, msg="The room type has been created and it shouldn't"
):
# room_type1
self.env["pms.room.type"].create(
@@ -728,7 +728,7 @@ class TestRoomType(TestPms):
)
# ACT & ASSERT
with self.assertRaises(
ValidationError, msg="Room Type has been created and it shouldn't"
UserError, msg="Room Type has been created and it shouldn't"
):
room_type1 = self.env["pms.room.type"].create(
{
@@ -776,7 +776,7 @@ class TestRoomType(TestPms):
self.amenity1 = self.env["pms.amenity"].create(
{"name": "Amenity", "pms_property_ids": self.pms_property1}
)
with self.assertRaises(ValidationError):
with self.assertRaises(UserError):
self.env["pms.room.type"].create(
{
"name": "Room Type",

View File

@@ -268,7 +268,7 @@ class TestPmsWizardMassiveChanges(common.SavepointCase):
expected_price_total = days * price_today * num_double_rooms
# set pricelist item for current day
product_tmpl_id = self.test_room_type_double.product_id.product_tmpl_id.id
product_tmpl = self.test_room_type_double.product_id.product_tmpl_id
pricelist_item = self.env["product.pricelist.item"].create(
{
"pricelist_id": self.test_pricelist.id,
@@ -276,9 +276,10 @@ class TestPmsWizardMassiveChanges(common.SavepointCase):
"date_end_overnight": checkin,
"compute_price": "fixed",
"applied_on": "1_product",
"product_tmpl_id": product_tmpl_id,
"product_tmpl_id": product_tmpl.id,
"fixed_price": price_today,
"min_quantity": 0,
"pms_property_ids": product_tmpl.pms_property_ids.ids,
}
)
pricelist_item.flush()

View File

@@ -8,6 +8,7 @@
<group>
<field name="amount" />
<field name="board_service_line_ids">
<field name="pms_property_ids" invisible="1" />
<tree editable="bottom">
<field
name="pms_board_service_room_type_id"
@@ -15,6 +16,7 @@
/>
<field name="product_id" />
<field name="amount" />
<field name="pms_property_ids" invisible="1" />
</tree>
</field>
</group>

View File

@@ -18,6 +18,7 @@
<tree editable="bottom">
<field name="product_id" />
<field name="amount" />
<field name="pms_property_ids" invisible="1" />
</tree>
</field>
<field name="show_detail_report" />
@@ -34,6 +35,7 @@
<field name="default_code" />
<field name="amount" />
<field name="show_detail_report" />
<field name="pms_property_ids" invisible="1" />
</tree>
</field>
</record>

View File

@@ -41,6 +41,7 @@
<field name="reservation_id" />
<field name="folio_id" />
<field name="identifier" />
<field name="pms_property_id" invisible="1" />
</group>
</group>
</sheet>
@@ -77,6 +78,7 @@
<field name="reservation_id" invisible="1" />
<field name="folio_id" force_save="1" invisible="1" />
<field name="state" invisible="0" />
<field name="pms_property_id" invisible="1" />
</tree>
</field>
</record>
@@ -103,6 +105,7 @@
attrs="{'invisible': [('state','!=','precheckin')]}"
/>
<field name="reservation_id" />
<field name="pms_property_id" invisible="1" />
<field name="partner_id" domain="[('is_company','=', False)]" />
<field name="name" />
<field name="mobile" />
@@ -142,6 +145,7 @@
<field name="arrival" />
<field name="departure" />
<field name="reservation_id" />
<field name="pms_property_id" invisible="1" />
<field name="folio_id" force_save="1" invisible="1" />
<field name="state" />
</tree>
@@ -218,6 +222,10 @@
name="reservation_id"
placeholder="Room Reservation"
/>
<field
name="pms_property_id"
invisible="1"
/>
</strong>
<span
t-if="record.arrival.raw_value"
@@ -484,6 +492,7 @@
<field name="reservation_id" />
<field name="folio_id" />
<field name="state" filters="1" />
<field name="pms_property_id" invisible="1" />
</calendar>
</field>
</record>

View File

@@ -443,6 +443,7 @@
name="cancel_discount"
attrs="{'column_invisible': [('parent.state','!=','cancelled')]}"
/>
<field name="pms_property_id" invisible="1" />
</tree>
</field>
<group string="Services" name="reservation_services">

View File

@@ -65,6 +65,7 @@
<field name="pms_room_type_id" invisible="1" />
<field name="pms_board_service_id" />
<field name="amount" />
<field name="pms_property_ids" invisible="1" />
<button
type="object"
class="oe_stat_button"

View File

@@ -11,6 +11,7 @@
<field name="channel_type" />
<field name="is_on_line" />
<field name="product_pricelist_ids" widget="many2many_tags" />
<field name="pms_property_ids" widget="many2many_tags" />
</group>
</sheet>
</form>
@@ -25,6 +26,7 @@
<field name="channel_type" />
<field name="is_on_line" />
<field name="product_pricelist_ids" widget="many2many_tags" />
<field name="pms_property_ids" />
</tree>
</field>
</record>

View File

@@ -6,7 +6,6 @@
<field name="arch" type="xml">
<xpath expr="//field[@name='applied_on']" position="before">
<field name="on_board_service" />
<field name="allowed_property_ids" invisible="1" />
<field
name="board_service_room_type_ids"
widget="many2many_tags"

View File

@@ -64,6 +64,11 @@
<field name="is_agency" />
</group>
</xpath>
<xpath expr="//field[@name='company_id']" position="after">
<group>
<field name="pms_property_ids" />
</group>
</xpath>
<xpath expr="//page[@name='internal_notes']" position="after">
<page
name="agency"

View File

@@ -9,6 +9,8 @@ class FolioWizard(models.TransientModel):
"Wizard to check availability by room type and pricelist &"
" creation of folios with its reservations"
)
_check_pms_properties_auto = True
# Fields declaration
start_date = fields.Date(
string="From:",
@@ -24,6 +26,7 @@ class FolioWizard(models.TransientModel):
compute="_compute_pricelist_id",
store=True,
readonly=False,
check_pms_properties=True,
)
pms_property_id = fields.Many2one(
comodel_name="pms.property",
@@ -35,9 +38,11 @@ class FolioWizard(models.TransientModel):
)
partner_id = fields.Many2one(
"res.partner",
check_pms_properties=True,
)
folio_id = fields.Many2one(
"pms.folio",
check_pms_properties=True,
)
availability_results = fields.One2many(
comodel_name="pms.folio.availability.wizard",
@@ -45,6 +50,7 @@ class FolioWizard(models.TransientModel):
compute="_compute_availability_results",
store=True,
readonly=False,
check_pms_properties=True,
)
agency_id = fields.Many2one(
string="Agency",

View File

@@ -41,7 +41,6 @@
name="pricelist_id"
string="Pricelist"
required="1"
domain="['|', ('pms_property_ids', '=', False), ('pms_property_ids', 'in', pms_property_id)]"
options="{'no_create': True,'no_open': True}"
/>
<field name="channel_type_id" />

View File

@@ -16,6 +16,7 @@ class NumRoomsSelectionModel(models.TransientModel):
class AvailabilityWizard(models.TransientModel):
_name = "pms.folio.availability.wizard"
_check_pms_properties_auto = True
# Fields declarations
folio_wizard_id = fields.Many2one(
@@ -29,7 +30,10 @@ class AvailabilityWizard(models.TransientModel):
string="To:",
required=True,
)
room_type_id = fields.Many2one(comodel_name="pms.room.type")
room_type_id = fields.Many2one(
comodel_name="pms.room.type",
check_pms_properties=True,
)
num_rooms_available = fields.Integer(
string="Available rooms",

View File

@@ -8,6 +8,7 @@ class AvailabilityWizard(models.TransientModel):
_name = "pms.massive.changes.wizard"
_description = "Wizard for massive changes on Availability Plans & Pricelists."
_check_pms_properties_auto = True
def _default_avail_readonly(self):
return True if self._context.get("availability_plan_id") else False
@@ -32,11 +33,13 @@ class AvailabilityWizard(models.TransientModel):
availability_plan_id = fields.Many2one(
comodel_name="pms.availability.plan",
string="Availability Plan to apply massive changes",
check_pms_properties=True,
# can be setted by context from availability plan detail
)
pricelist_id = fields.Many2one(
comodel_name="product.pricelist",
string="Pricelist to apply massive changes",
check_pms_properties=True,
)
allowed_pricelist_ids = fields.One2many(
comodel_name="product.pricelist", compute="_compute_allowed_pricelist_ids"
@@ -49,7 +52,11 @@ class AvailabilityWizard(models.TransientModel):
string="To",
required=True,
)
room_type_id = fields.Many2one(comodel_name="pms.room.type", string="Room Type")
room_type_id = fields.Many2one(
comodel_name="pms.room.type",
string="Room Type",
check_pms_properties=True,
)
price = fields.Float(string="Price")
min_quantity = fields.Float(string="Min. Quantity")

View File

@@ -50,11 +50,7 @@
'required': [('massive_changes_on','=','pricelist')]}"
domain="[('id', 'in', allowed_pricelist_ids), '|', ('pms_property_ids', '=', False), ('pms_property_ids', 'in', pms_property_ids)]"
/>
<field
name="room_type_id"
default_focus="1"
domain="['|', ('pms_property_ids', '=', False), ('pms_property_ids', 'in', pms_property_ids)]"
/>
<field name="room_type_id" default_focus="1" />
</group>
</div>