diff --git a/pms/models/pms_room_type.py b/pms/models/pms_room_type.py index ef9bcffc4..81a4b897b 100644 --- a/pms/models/pms_room_type.py +++ b/pms/models/pms_room_type.py @@ -90,6 +90,11 @@ class PmsRoomType(models.Model): related="class_id.overnight", store=True, ) + min_price = fields.Float( + string="Min. Price", + help="Minimum price for a room type", + default=5.0, + ) def name_get(self): result = [] diff --git a/pms/models/product_pricelist_item.py b/pms/models/product_pricelist_item.py index d6507ae46..319833d70 100644 --- a/pms/models/product_pricelist_item.py +++ b/pms/models/product_pricelist_item.py @@ -112,3 +112,36 @@ class ProductPricelistItem(models.Model): if domain else False ) + + def write(self, vals): + # Check that the price in product room types are not + # minor that min price in room type defined + # REVIEW: By the momment only check fixed prices + if "fixed_price" in vals: + if any( + [ + item.product_id.room_type_id + and item.product_id.room_type_id.min_price + and vals["fixed_price"] < item.product_id.room_type_id.min_price + for item in self + ] + ): + raise ValueError( + """The price in product room types can't be minor + that min price in room type defined""" + ) + return super().write(vals) + + def create(self, vals): + # Check that the price in product room types are not + # minor that min price in room type defined + # REVIEW: By the momment only check fixed prices + if "fixed_price" in vals: + product_id = self.env["product.product"].browse(vals["product_id"]) + if product_id.room_type_id and product_id.room_type_id.min_price: + if vals["fixed_price"] < product_id.room_type_id.min_price: + raise ValueError( + """The price in product room types can't be minor + that min price in room type defined""" + ) + return super().create(vals) diff --git a/pms/views/pms_room_type_views.xml b/pms/views/pms_room_type_views.xml index 2dc62f12f..a218d5641 100644 --- a/pms/views/pms_room_type_views.xml +++ b/pms/views/pms_room_type_views.xml @@ -41,6 +41,7 @@ +