mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
Multiproperty Constrains (#30)
* [IMP] add multiproperties demo data * [IMP] add multiproperties checks in res_users * [IMP] add test case in test_res_users * [IMP] Add multiproperty checks in pms_amenity and pms_amenity_type * [IMP] Add multiproperty in pms_board_service_room_type(pending review) * [IMP] Add test case in test_pms_room_type_availability_rule to check multiproperties * [IMP] Fixing test case in test_pms_room_type_availability_rule to check multiproperties * [IMP] Add test case in test_pms_room_type_availability_rule * [IMP] Removed field default_availability_plan_id from pms_property * [IMP] Add multiproperty in pms_room_type_available_plan * [IMP] pms: adding property in rooms_available * [IMP] Add multiproperty in pms_room_type_availability_rule and product_pricelist(work in progress) * [IMP] Add multiproperty in product_pricelist and product_pricelist_item * [IMP] add multiproperties demo data * [IMP] add multiproperties checks in res_users * [IMP] add test case in test_res_users and pms_room_type_availability_rule * [IMP] Add multiproperty checks in pms_amenity and pms_amenity_type * [IMP] Add multiproperty in pms_board_service_room_type(pending review) * [IMP] Removed field default_availability_plan_id from pms_property * [IMP] Add multiproperty in pms_room_type_available_plan * [IMP] pms: adding property in rooms_available * [IMP] Add multiproperty in pms_room_type_availability_rule and product_pricelist(work in progress) * [IMP] Add multiproperty in product_pricelist and product_pricelist_item * [IMP] Pms: add compute_folio method in pms.service * [IMP] Pms: add multiproperty integrity checks between room_type and its class * [IMP] Pms: pms_property_id related to folio * [IMP] Pms: add multiproperty integrity checks in pms_room with pms_room_type and pms_floor * [IMP] Pms: adding multiproperty checks in room_type(work in progress) * [IMP] Pms: Add property rules * [FIX]pms: external ids security rules * [FIX]pms: property checks * [FIX]pms: get product on pricelist item multiproperty check * [FIX]pms: delete test field default_plan * [FIX]pms: property constrain to product from room type model * [FIX]pms: ids references * [IMP]pms: folio wizard price flow on odoo standar Co-authored-by: Darío Lodeiros <dario@commitsun.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# Copyright 2019 Pablo Quesada
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from odoo import api, fields, models
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.http import request
|
||||
|
||||
|
||||
@@ -16,9 +17,9 @@ class ResUsers(models.Model):
|
||||
pms_property_id = fields.Many2one(
|
||||
"pms.property",
|
||||
string="Property",
|
||||
default=_get_default_pms_property,
|
||||
help="The property this user is currently working for.",
|
||||
context={"user_preference": True},
|
||||
domain="[('id','in',pms_property_ids)]",
|
||||
)
|
||||
pms_property_ids = fields.Many2many(
|
||||
"pms.property",
|
||||
@@ -26,8 +27,9 @@ class ResUsers(models.Model):
|
||||
"user_id",
|
||||
"pms_property_id",
|
||||
string="Properties",
|
||||
default=_get_default_pms_property,
|
||||
domain="[('company_id','in',company_ids)]",
|
||||
)
|
||||
company_id = fields.Many2one(domain="[('id','in',company_ids)]")
|
||||
|
||||
@api.model
|
||||
def get_active_property_ids(self):
|
||||
@@ -43,3 +45,19 @@ class ResUsers(models.Model):
|
||||
]
|
||||
return self.env["pms.property"].browse(active_property_ids).ids
|
||||
return user_property_ids
|
||||
|
||||
@api.constrains("pms_property_id", "pms_property_ids")
|
||||
def _check_property_in_allowed_properties(self):
|
||||
if any(user.pms_property_id not in user.pms_property_ids for user in self):
|
||||
raise ValidationError(
|
||||
_("The chosen property is not in the allowed properties for this user")
|
||||
)
|
||||
|
||||
@api.constrains("pms_property_ids", "company_id")
|
||||
def _check_company_in_property_ids(self):
|
||||
for record in self:
|
||||
for pms_property in record.pms_property_ids:
|
||||
if pms_property.company_id not in record.company_ids:
|
||||
raise ValidationError(
|
||||
_("Some properties do not belong to the allowed companies")
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user