Files
pms/pms/models/product_pricelist_item.py
Sara 57d3ab0c8a 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>
2021-01-31 13:07:03 +01:00

72 lines
2.7 KiB
Python

# 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
class ProductPricelistItem(models.Model):
_inherit = "product.pricelist.item"
pms_property_ids = fields.Many2many(
"pms.property", string="Properties", required=False, ondelete="restrict"
)
date_start_overnight = fields.Date(
string="Start Date Overnight",
help="Start date to apply daily pricelist items",
)
date_end_overnight = fields.Date(
string="End Date Overnight",
help="End date to apply daily pricelist items",
)
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"))