[ADD]pms: min price room type control

This commit is contained in:
Darío Lodeiros
2023-02-05 17:56:06 +01:00
parent cb5367b82c
commit 993b34349a
3 changed files with 39 additions and 0 deletions

View File

@@ -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 = []

View File

@@ -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)

View File

@@ -41,6 +41,7 @@
<field name="total_rooms_count" />
<field name="default_max_avail" />
<field name="default_quota" />
<field name="min_price" />
</group>
<group name="accounting_group">
<field