mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[FIX]pms: disable mail and mobile constrains in checkin
This commit is contained in:
committed by
Eric Antones
parent
953115cf26
commit
fb4d272a5d
@@ -3,7 +3,6 @@
|
|||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import re
|
|
||||||
|
|
||||||
from odoo import _, api, fields, models
|
from odoo import _, api, fields, models
|
||||||
from odoo.exceptions import UserError, ValidationError
|
from odoo.exceptions import UserError, ValidationError
|
||||||
@@ -482,29 +481,30 @@ class PmsCheckinPartner(models.Model):
|
|||||||
_("This guest is already registered in the room")
|
_("This guest is already registered in the room")
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.constrains("email")
|
# REVIEW: Redesign email & mobile control (res.partner? other module in OCA?)
|
||||||
def check_email_pattern(self):
|
# @api.constrains("email")
|
||||||
for record in self:
|
# def check_email_pattern(self):
|
||||||
if record.email:
|
# for record in self:
|
||||||
if not re.search(
|
# if record.email:
|
||||||
r"^[a-zA-Z0-9]([a-zA-z0-9\-\_]*[\.]?[a-zA-Z0-9\-\_]+)*"
|
# 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,
|
# 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))
|
# ):
|
||||||
|
# raise ValidationError(_("'%s' is not a valid email", record.email))
|
||||||
|
|
||||||
@api.constrains("mobile")
|
# @api.constrains("mobile")
|
||||||
def check_phone_pattern(self):
|
# def check_phone_pattern(self):
|
||||||
|
|
||||||
for record in self:
|
# for record in self:
|
||||||
if record.mobile:
|
# if record.mobile:
|
||||||
|
|
||||||
if not re.search(
|
# if not re.search(
|
||||||
r"^(\d{3}[\-\s]?\d{2}[\-\s]?\d{2}[\-\s]?\d{2}[\-\s]?|"
|
# r"^(\d{3}[\-\s]?\d{2}[\-\s]?\d{2}[\-\s]?\d{2}[\-\s]?|"
|
||||||
r"\d{3}[\-\s]?\d{3}[\-\s]?\d{3})$",
|
# r"\d{3}[\-\s]?\d{3}[\-\s]?\d{3})$",
|
||||||
str(record.mobile),
|
# str(record.mobile),
|
||||||
):
|
# ):
|
||||||
raise ValidationError(_("'%s' is not a valid phone", record.mobile))
|
# raise ValidationError(_("'%s' is not a valid phone", record.mobile))
|
||||||
|
|
||||||
@api.constrains("document_number")
|
@api.constrains("document_number")
|
||||||
def check_document_number(self):
|
def check_document_number(self):
|
||||||
|
|||||||
@@ -574,159 +574,160 @@ class TestPmsCheckinPartner(TestPms):
|
|||||||
"Reservations not set like Departure delayed",
|
"Reservations not set like Departure delayed",
|
||||||
)
|
)
|
||||||
|
|
||||||
@freeze_time("2010-12-10")
|
# REVIEW: Redesing constrains mobile&mail control
|
||||||
def test_not_valid_emails(self):
|
# @freeze_time("2010-12-10")
|
||||||
# TEST CASES
|
# def test_not_valid_emails(self):
|
||||||
# Check that the email format is incorrect
|
# # TEST CASES
|
||||||
|
# # Check that the email format is incorrect
|
||||||
|
|
||||||
# ARRANGE
|
# # ARRANGE
|
||||||
reservation = self.env["pms.reservation"].create(
|
# reservation = self.env["pms.reservation"].create(
|
||||||
{
|
# {
|
||||||
"checkin": datetime.date.today(),
|
# "checkin": datetime.date.today(),
|
||||||
"checkout": datetime.date.today() + datetime.timedelta(days=3),
|
# "checkout": datetime.date.today() + datetime.timedelta(days=3),
|
||||||
"room_type_id": self.room_type1.id,
|
# "room_type_id": self.room_type1.id,
|
||||||
"partner_id": self.env.ref("base.res_partner_12").id,
|
# "partner_id": self.env.ref("base.res_partner_12").id,
|
||||||
"adults": 3,
|
# "adults": 3,
|
||||||
"pms_property_id": self.pms_property1.id,
|
# "pms_property_id": self.pms_property1.id,
|
||||||
}
|
# }
|
||||||
)
|
# )
|
||||||
test_cases = [
|
# test_cases = [
|
||||||
"myemail",
|
# "myemail",
|
||||||
"myemail@",
|
# "myemail@",
|
||||||
"myemail@",
|
# "myemail@",
|
||||||
"myemail@.com",
|
# "myemail@.com",
|
||||||
".myemail",
|
# ".myemail",
|
||||||
".myemail@",
|
# ".myemail@",
|
||||||
".myemail@.com" ".myemail@.com." "123myemail@aaa.com",
|
# ".myemail@.com" ".myemail@.com." "123myemail@aaa.com",
|
||||||
]
|
# ]
|
||||||
for mail in test_cases:
|
# for mail in test_cases:
|
||||||
with self.subTest(i=mail):
|
# with self.subTest(i=mail):
|
||||||
with self.assertRaises(
|
# with self.assertRaises(
|
||||||
ValidationError, msg="Email format is correct and shouldn't"
|
# ValidationError, msg="Email format is correct and shouldn't"
|
||||||
):
|
# ):
|
||||||
reservation.write(
|
# reservation.write(
|
||||||
{
|
# {
|
||||||
"checkin_partner_ids": [
|
# "checkin_partner_ids": [
|
||||||
(
|
# (
|
||||||
0,
|
# 0,
|
||||||
False,
|
# False,
|
||||||
{
|
# {
|
||||||
"name": "Carlos",
|
# "name": "Carlos",
|
||||||
"email": mail,
|
# "email": mail,
|
||||||
},
|
# },
|
||||||
)
|
# )
|
||||||
]
|
# ]
|
||||||
}
|
# }
|
||||||
)
|
# )
|
||||||
|
|
||||||
@freeze_time("2014-12-10")
|
# @freeze_time("2014-12-10")
|
||||||
def test_valid_emails(self):
|
# def test_valid_emails(self):
|
||||||
# TEST CASES
|
# # TEST CASES
|
||||||
# Check that the email format is correct
|
# # Check that the email format is correct
|
||||||
|
|
||||||
# ARRANGE
|
# # ARRANGE
|
||||||
reservation = self.env["pms.reservation"].create(
|
# reservation = self.env["pms.reservation"].create(
|
||||||
{
|
# {
|
||||||
"checkin": datetime.date.today(),
|
# "checkin": datetime.date.today(),
|
||||||
"checkout": datetime.date.today() + datetime.timedelta(days=4),
|
# "checkout": datetime.date.today() + datetime.timedelta(days=4),
|
||||||
"room_type_id": self.room_type1.id,
|
# "room_type_id": self.room_type1.id,
|
||||||
"partner_id": self.env.ref("base.res_partner_12").id,
|
# "partner_id": self.env.ref("base.res_partner_12").id,
|
||||||
"adults": 3,
|
# "adults": 3,
|
||||||
"pms_property_id": self.pms_property1.id,
|
# "pms_property_id": self.pms_property1.id,
|
||||||
}
|
# }
|
||||||
)
|
# )
|
||||||
test_cases = [
|
# test_cases = [
|
||||||
"hello@commitsun.com",
|
# "hello@commitsun.com",
|
||||||
"hi.welcome@commitsun.com",
|
# "hi.welcome@commitsun.com",
|
||||||
"hi.welcome@dev.commitsun.com",
|
# "hi.welcome@dev.commitsun.com",
|
||||||
"hi.welcome@dev-commitsun.com",
|
# "hi.welcome@dev-commitsun.com",
|
||||||
"john.doe@xxx.yyy.zzz",
|
# "john.doe@xxx.yyy.zzz",
|
||||||
]
|
# ]
|
||||||
for mail in test_cases:
|
# for mail in test_cases:
|
||||||
with self.subTest(i=mail):
|
# with self.subTest(i=mail):
|
||||||
guest = self.env["pms.checkin.partner"].create(
|
# guest = self.env["pms.checkin.partner"].create(
|
||||||
{
|
# {
|
||||||
"name": "Carlos",
|
# "name": "Carlos",
|
||||||
"email": mail,
|
# "email": mail,
|
||||||
"reservation_id": reservation.id,
|
# "reservation_id": reservation.id,
|
||||||
}
|
# }
|
||||||
)
|
# )
|
||||||
self.assertEqual(
|
# self.assertEqual(
|
||||||
mail,
|
# mail,
|
||||||
guest.email,
|
# guest.email,
|
||||||
)
|
# )
|
||||||
guest.unlink()
|
# guest.unlink()
|
||||||
|
|
||||||
@freeze_time("2016-12-10")
|
# @freeze_time("2016-12-10")
|
||||||
def test_not_valid_phone(self):
|
# def test_not_valid_phone(self):
|
||||||
# TEST CASES
|
# # TEST CASES
|
||||||
# Check that the phone format is incorrect
|
# # Check that the phone format is incorrect
|
||||||
|
|
||||||
# ARRANGE
|
# # ARRANGE
|
||||||
reservation = self.env["pms.reservation"].create(
|
# reservation = self.env["pms.reservation"].create(
|
||||||
{
|
# {
|
||||||
"checkin": datetime.date.today(),
|
# "checkin": datetime.date.today(),
|
||||||
"checkout": datetime.date.today() + datetime.timedelta(days=1),
|
# "checkout": datetime.date.today() + datetime.timedelta(days=1),
|
||||||
"room_type_id": self.room_type1.id,
|
# "room_type_id": self.room_type1.id,
|
||||||
"partner_id": self.env.ref("base.res_partner_12").id,
|
# "partner_id": self.env.ref("base.res_partner_12").id,
|
||||||
"adults": 3,
|
# "adults": 3,
|
||||||
"pms_property_id": self.pms_property1.id,
|
# "pms_property_id": self.pms_property1.id,
|
||||||
}
|
# }
|
||||||
)
|
# )
|
||||||
test_cases = [
|
# test_cases = [
|
||||||
"phone",
|
# "phone",
|
||||||
"123456789123",
|
# "123456789123",
|
||||||
"123.456.789",
|
# "123.456.789",
|
||||||
"123",
|
# "123",
|
||||||
"123123",
|
# "123123",
|
||||||
]
|
# ]
|
||||||
for phone in test_cases:
|
# for phone in test_cases:
|
||||||
with self.subTest(i=phone):
|
# with self.subTest(i=phone):
|
||||||
with self.assertRaises(
|
# with self.assertRaises(
|
||||||
ValidationError, msg="Phone format is correct and shouldn't"
|
# ValidationError, msg="Phone format is correct and shouldn't"
|
||||||
):
|
# ):
|
||||||
self.env["pms.checkin.partner"].create(
|
# self.env["pms.checkin.partner"].create(
|
||||||
{
|
# {
|
||||||
"name": "Carlos",
|
# "name": "Carlos",
|
||||||
"mobile": phone,
|
# "mobile": phone,
|
||||||
"reservation_id": reservation.id,
|
# "reservation_id": reservation.id,
|
||||||
}
|
# }
|
||||||
)
|
# )
|
||||||
|
|
||||||
@freeze_time("2018-12-10")
|
# @freeze_time("2018-12-10")
|
||||||
def test_valid_phones(self):
|
# def test_valid_phones(self):
|
||||||
# TEST CASES
|
# # TEST CASES
|
||||||
# Check that the phone format is correct
|
# # Check that the phone format is correct
|
||||||
|
|
||||||
# ARRANGE
|
# # ARRANGE
|
||||||
reservation = self.env["pms.reservation"].create(
|
# reservation = self.env["pms.reservation"].create(
|
||||||
{
|
# {
|
||||||
"checkin": datetime.date.today(),
|
# "checkin": datetime.date.today(),
|
||||||
"checkout": datetime.date.today() + datetime.timedelta(days=5),
|
# "checkout": datetime.date.today() + datetime.timedelta(days=5),
|
||||||
"room_type_id": self.room_type1.id,
|
# "room_type_id": self.room_type1.id,
|
||||||
"partner_id": self.env.ref("base.res_partner_12").id,
|
# "partner_id": self.env.ref("base.res_partner_12").id,
|
||||||
"adults": 3,
|
# "adults": 3,
|
||||||
"pms_property_id": self.pms_property1.id,
|
# "pms_property_id": self.pms_property1.id,
|
||||||
}
|
# }
|
||||||
)
|
# )
|
||||||
test_cases = [
|
# test_cases = [
|
||||||
"981 981 981",
|
# "981 981 981",
|
||||||
"981981981",
|
# "981981981",
|
||||||
"981 98 98 98",
|
# "981 98 98 98",
|
||||||
]
|
# ]
|
||||||
for mobile in test_cases:
|
# for mobile in test_cases:
|
||||||
with self.subTest(i=mobile):
|
# with self.subTest(i=mobile):
|
||||||
guest = self.env["pms.checkin.partner"].create(
|
# guest = self.env["pms.checkin.partner"].create(
|
||||||
{
|
# {
|
||||||
"name": "Carlos",
|
# "name": "Carlos",
|
||||||
"mobile": mobile,
|
# "mobile": mobile,
|
||||||
"reservation_id": reservation.id,
|
# "reservation_id": reservation.id,
|
||||||
}
|
# }
|
||||||
)
|
# )
|
||||||
self.assertEqual(
|
# self.assertEqual(
|
||||||
mobile,
|
# mobile,
|
||||||
guest.mobile,
|
# guest.mobile,
|
||||||
)
|
# )
|
||||||
|
|
||||||
def test_complete_checkin_data_with_partner_data(self):
|
def test_complete_checkin_data_with_partner_data(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user