[FIX]pms: disable mail and mobile constrains in checkin

This commit is contained in:
Darío Lodeiros
2021-09-28 14:51:36 +02:00
committed by Eric Antones
parent 953115cf26
commit fb4d272a5d
2 changed files with 168 additions and 167 deletions

View File

@@ -3,7 +3,6 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import json
import re
from odoo import _, api, fields, models
from odoo.exceptions import UserError, ValidationError
@@ -482,29 +481,30 @@ class PmsCheckinPartner(models.Model):
_("This guest is already registered in the room")
)
@api.constrains("email")
def check_email_pattern(self):
for record in self:
if record.email:
if not re.search(
r"^[a-zA-Z0-9]([a-zA-z0-9\-\_]*[\.]?[a-zA-Z0-9\-\_]+)*"
r"@([a-zA-z0-9\-]+([\.][a-zA-Z0-9\-\_]+)?\.[a-zA-Z0-9]+)+$",
record.email,
):
raise ValidationError(_("'%s' is not a valid email", record.email))
# REVIEW: Redesign email & mobile control (res.partner? other module in OCA?)
# @api.constrains("email")
# def check_email_pattern(self):
# for record in self:
# if record.email:
# if not re.search(
# r"^[a-zA-Z0-9]([a-zA-z0-9\-\_]*[\.]?[a-zA-Z0-9\-\_]+)*"
# r"@([a-zA-z0-9\-]+([\.][a-zA-Z0-9\-\_]+)?\.[a-zA-Z0-9]+)+$",
# record.email,
# ):
# raise ValidationError(_("'%s' is not a valid email", record.email))
@api.constrains("mobile")
def check_phone_pattern(self):
# @api.constrains("mobile")
# def check_phone_pattern(self):
for record in self:
if record.mobile:
# for record in self:
# if record.mobile:
if not re.search(
r"^(\d{3}[\-\s]?\d{2}[\-\s]?\d{2}[\-\s]?\d{2}[\-\s]?|"
r"\d{3}[\-\s]?\d{3}[\-\s]?\d{3})$",
str(record.mobile),
):
raise ValidationError(_("'%s' is not a valid phone", record.mobile))
# if not re.search(
# r"^(\d{3}[\-\s]?\d{2}[\-\s]?\d{2}[\-\s]?\d{2}[\-\s]?|"
# r"\d{3}[\-\s]?\d{3}[\-\s]?\d{3})$",
# str(record.mobile),
# ):
# raise ValidationError(_("'%s' is not a valid phone", record.mobile))
@api.constrains("document_number")
def check_document_number(self):

View File

@@ -574,159 +574,160 @@ class TestPmsCheckinPartner(TestPms):
"Reservations not set like Departure delayed",
)
@freeze_time("2010-12-10")
def test_not_valid_emails(self):
# TEST CASES
# Check that the email format is incorrect
# REVIEW: Redesing constrains mobile&mail control
# @freeze_time("2010-12-10")
# def test_not_valid_emails(self):
# # TEST CASES
# # Check that the email format is incorrect
# ARRANGE
reservation = self.env["pms.reservation"].create(
{
"checkin": datetime.date.today(),
"checkout": datetime.date.today() + datetime.timedelta(days=3),
"room_type_id": self.room_type1.id,
"partner_id": self.env.ref("base.res_partner_12").id,
"adults": 3,
"pms_property_id": self.pms_property1.id,
}
)
test_cases = [
"myemail",
"myemail@",
"myemail@",
"myemail@.com",
".myemail",
".myemail@",
".myemail@.com" ".myemail@.com." "123myemail@aaa.com",
]
for mail in test_cases:
with self.subTest(i=mail):
with self.assertRaises(
ValidationError, msg="Email format is correct and shouldn't"
):
reservation.write(
{
"checkin_partner_ids": [
(
0,
False,
{
"name": "Carlos",
"email": mail,
},
)
]
}
)
# # ARRANGE
# reservation = self.env["pms.reservation"].create(
# {
# "checkin": datetime.date.today(),
# "checkout": datetime.date.today() + datetime.timedelta(days=3),
# "room_type_id": self.room_type1.id,
# "partner_id": self.env.ref("base.res_partner_12").id,
# "adults": 3,
# "pms_property_id": self.pms_property1.id,
# }
# )
# test_cases = [
# "myemail",
# "myemail@",
# "myemail@",
# "myemail@.com",
# ".myemail",
# ".myemail@",
# ".myemail@.com" ".myemail@.com." "123myemail@aaa.com",
# ]
# for mail in test_cases:
# with self.subTest(i=mail):
# with self.assertRaises(
# ValidationError, msg="Email format is correct and shouldn't"
# ):
# reservation.write(
# {
# "checkin_partner_ids": [
# (
# 0,
# False,
# {
# "name": "Carlos",
# "email": mail,
# },
# )
# ]
# }
# )
@freeze_time("2014-12-10")
def test_valid_emails(self):
# TEST CASES
# Check that the email format is correct
# @freeze_time("2014-12-10")
# def test_valid_emails(self):
# # TEST CASES
# # Check that the email format is correct
# ARRANGE
reservation = self.env["pms.reservation"].create(
{
"checkin": datetime.date.today(),
"checkout": datetime.date.today() + datetime.timedelta(days=4),
"room_type_id": self.room_type1.id,
"partner_id": self.env.ref("base.res_partner_12").id,
"adults": 3,
"pms_property_id": self.pms_property1.id,
}
)
test_cases = [
"hello@commitsun.com",
"hi.welcome@commitsun.com",
"hi.welcome@dev.commitsun.com",
"hi.welcome@dev-commitsun.com",
"john.doe@xxx.yyy.zzz",
]
for mail in test_cases:
with self.subTest(i=mail):
guest = self.env["pms.checkin.partner"].create(
{
"name": "Carlos",
"email": mail,
"reservation_id": reservation.id,
}
)
self.assertEqual(
mail,
guest.email,
)
guest.unlink()
# # ARRANGE
# reservation = self.env["pms.reservation"].create(
# {
# "checkin": datetime.date.today(),
# "checkout": datetime.date.today() + datetime.timedelta(days=4),
# "room_type_id": self.room_type1.id,
# "partner_id": self.env.ref("base.res_partner_12").id,
# "adults": 3,
# "pms_property_id": self.pms_property1.id,
# }
# )
# test_cases = [
# "hello@commitsun.com",
# "hi.welcome@commitsun.com",
# "hi.welcome@dev.commitsun.com",
# "hi.welcome@dev-commitsun.com",
# "john.doe@xxx.yyy.zzz",
# ]
# for mail in test_cases:
# with self.subTest(i=mail):
# guest = self.env["pms.checkin.partner"].create(
# {
# "name": "Carlos",
# "email": mail,
# "reservation_id": reservation.id,
# }
# )
# self.assertEqual(
# mail,
# guest.email,
# )
# guest.unlink()
@freeze_time("2016-12-10")
def test_not_valid_phone(self):
# TEST CASES
# Check that the phone format is incorrect
# @freeze_time("2016-12-10")
# def test_not_valid_phone(self):
# # TEST CASES
# # Check that the phone format is incorrect
# ARRANGE
reservation = self.env["pms.reservation"].create(
{
"checkin": datetime.date.today(),
"checkout": datetime.date.today() + datetime.timedelta(days=1),
"room_type_id": self.room_type1.id,
"partner_id": self.env.ref("base.res_partner_12").id,
"adults": 3,
"pms_property_id": self.pms_property1.id,
}
)
test_cases = [
"phone",
"123456789123",
"123.456.789",
"123",
"123123",
]
for phone in test_cases:
with self.subTest(i=phone):
with self.assertRaises(
ValidationError, msg="Phone format is correct and shouldn't"
):
self.env["pms.checkin.partner"].create(
{
"name": "Carlos",
"mobile": phone,
"reservation_id": reservation.id,
}
)
# # ARRANGE
# reservation = self.env["pms.reservation"].create(
# {
# "checkin": datetime.date.today(),
# "checkout": datetime.date.today() + datetime.timedelta(days=1),
# "room_type_id": self.room_type1.id,
# "partner_id": self.env.ref("base.res_partner_12").id,
# "adults": 3,
# "pms_property_id": self.pms_property1.id,
# }
# )
# test_cases = [
# "phone",
# "123456789123",
# "123.456.789",
# "123",
# "123123",
# ]
# for phone in test_cases:
# with self.subTest(i=phone):
# with self.assertRaises(
# ValidationError, msg="Phone format is correct and shouldn't"
# ):
# self.env["pms.checkin.partner"].create(
# {
# "name": "Carlos",
# "mobile": phone,
# "reservation_id": reservation.id,
# }
# )
@freeze_time("2018-12-10")
def test_valid_phones(self):
# TEST CASES
# Check that the phone format is correct
# @freeze_time("2018-12-10")
# def test_valid_phones(self):
# # TEST CASES
# # Check that the phone format is correct
# ARRANGE
reservation = self.env["pms.reservation"].create(
{
"checkin": datetime.date.today(),
"checkout": datetime.date.today() + datetime.timedelta(days=5),
"room_type_id": self.room_type1.id,
"partner_id": self.env.ref("base.res_partner_12").id,
"adults": 3,
"pms_property_id": self.pms_property1.id,
}
)
test_cases = [
"981 981 981",
"981981981",
"981 98 98 98",
]
for mobile in test_cases:
with self.subTest(i=mobile):
guest = self.env["pms.checkin.partner"].create(
{
"name": "Carlos",
"mobile": mobile,
"reservation_id": reservation.id,
}
)
self.assertEqual(
mobile,
guest.mobile,
)
# # ARRANGE
# reservation = self.env["pms.reservation"].create(
# {
# "checkin": datetime.date.today(),
# "checkout": datetime.date.today() + datetime.timedelta(days=5),
# "room_type_id": self.room_type1.id,
# "partner_id": self.env.ref("base.res_partner_12").id,
# "adults": 3,
# "pms_property_id": self.pms_property1.id,
# }
# )
# test_cases = [
# "981 981 981",
# "981981981",
# "981 98 98 98",
# ]
# for mobile in test_cases:
# with self.subTest(i=mobile):
# guest = self.env["pms.checkin.partner"].create(
# {
# "name": "Carlos",
# "mobile": mobile,
# "reservation_id": reservation.id,
# }
# )
# self.assertEqual(
# mobile,
# guest.mobile,
# )
def test_complete_checkin_data_with_partner_data(self):
"""