[ADD] product pricelist constraint and test cases

This commit is contained in:
Pablo
2019-09-20 12:58:21 +02:00
parent d8095ef599
commit c430e1e75f
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."))

View File

@@ -23,6 +23,7 @@
# from . import test_reservation
# from . import test_folio
from . import test_inherited_ir_http
from . import test_inherited_product_pricelist
from . import test_hotel_room_type
from . import test_hotel_room
from . import test_massive_changes

View File

@@ -0,0 +1,30 @@
from .common import TestHotel
from odoo import fields
from odoo.exceptions import ValidationError
class TestInheritedProductPricelist(TestHotel):
# be aware using self.env.user.hotel_id because it is the value configure for the user running the tests
def test_daily_pricelist(self):
# A daily pricelist must be related with one and only one hotel #1
with self.assertRaises(ValidationError):
self.list0.hotel_ids += self.demo_hotel_property
# A daily pricelist must be related with one and only one hotel #2
with self.assertRaises(ValidationError):
self.list0.hotel_ids = False
# create a valid record using a daily pricelist
test_result = self.env['product.pricelist'].create({
'name': 'Test Daily Pricelist',
'hotel_ids': [(4, self.demo_hotel_property.id)]
})
self.assertEqual(test_result.pricelist_type, 'daily')
self.assertEqual(test_result.hotel_ids, self.demo_hotel_property)
def test_pricelist_by_hotel(self):
# A daily pricelist must be related with one and only one hotel #1
with self.assertRaises(ValidationError):
self.list0.hotel_ids = self.demo_hotel_property