[ADD] product pricelist constraint and test cases

This commit is contained in:
Pablo
2019-09-20 12:58:21 +02:00
parent d8095ef599
commit 05571bc65c
3 changed files with 39 additions and 4 deletions

View File

@@ -28,7 +28,11 @@ class ProductPricelist(models.Model):
if record.pricelist_type == 'daily' and len(record.hotel_ids) != 1:
raise ValidationError(_("A daily pricelist is used as a daily Rate Plan for room types "
"and therefore must be related with one and only one hotel."))
if record.pricelist_type == 'daily' and len(record.hotel_ids) == 1 \
and record.hotel_ids.id != record.hotel_ids.default_pricelist_id.hotel_ids.id:
raise ValidationError(_("Relationship mismatch.") + " " +
_("This pricelist is used as default in a different hotel."))
if record.pricelist_type == 'daily' and len(record.hotel_ids) == 1:
hotel_id = self.env['hotel.property'].search([
('default_pricelist_id', '=', record.id)
]) or None
if hotel_id and hotel_id != record.hotel_ids:
raise ValidationError(_("Relationship mismatch.") + " " +
_("This pricelist is used as default in a different hotel."))