mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP] pms: xls checkin partners export & validate fields import (#34)
* [FIX] pms: fix xls checkin partners export & validate fields import * [FIX] pms: fix last commit file missing
This commit is contained in:
@@ -35,7 +35,7 @@ class TestResPartner(common.SavepointCase):
|
||||
partner = self.env["res.partner"].create(
|
||||
{
|
||||
"name": "name1",
|
||||
#"lastname": "lastname1",
|
||||
# "lastname": "lastname1",
|
||||
"lastname2": "secondlastname",
|
||||
"expedition_name": "2011-02-20",
|
||||
"birthdate": "1995-12-10",
|
||||
@@ -97,7 +97,7 @@ class TestResPartner(common.SavepointCase):
|
||||
partner = self.env["res.partner"].create(
|
||||
{
|
||||
"name": "name1",
|
||||
#"lastname": "lastname1",
|
||||
# "lastname": "lastname1",
|
||||
"lastname2": "secondlastname",
|
||||
"expedition_name": "2011-02-20",
|
||||
"birthdate": "1995-12-10",
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
# 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 ValidationError
|
||||
@@ -170,6 +171,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))
|
||||
|
||||
@api.constrains("mobile")
|
||||
def check_phone_pattern(self):
|
||||
|
||||
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})$",
|
||||
record.mobile,
|
||||
):
|
||||
raise ValidationError(_("'%s' is not a valid phone", record.mobile))
|
||||
|
||||
# CRUD
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
|
||||
@@ -382,3 +382,77 @@ class TestPmsCheckinPartner(TestHotel):
|
||||
1,
|
||||
"Reservations not set like No checkout",
|
||||
)
|
||||
|
||||
def test_not_valid_emails(self):
|
||||
# TEST CASES
|
||||
# emails that should be detected as incorrect
|
||||
|
||||
# ARRANGE
|
||||
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):
|
||||
self.env["pms.checkin.partner"].create({"email": mail})
|
||||
|
||||
def test_valid_emails(self):
|
||||
# TEST CASES
|
||||
# emails that should be detected as correct
|
||||
|
||||
# ARRANGE
|
||||
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({"email": mail})
|
||||
self.assertEqual(
|
||||
mail,
|
||||
guest.email,
|
||||
)
|
||||
|
||||
def test_not_valid_phone(self):
|
||||
# TEST CASES
|
||||
# phones that should be detected as incorrect
|
||||
|
||||
# ARRANGE
|
||||
test_cases = [
|
||||
"phone",
|
||||
"123456789123",
|
||||
"123.456.789",
|
||||
"123",
|
||||
"123123",
|
||||
]
|
||||
for phone in test_cases:
|
||||
with self.subTest(i=phone):
|
||||
with self.assertRaises(ValidationError):
|
||||
self.env["pms.checkin.partner"].create({"mobile": phone})
|
||||
|
||||
def test_valid_phones(self):
|
||||
# TEST CASES
|
||||
# emails that should be detected as incorrect
|
||||
|
||||
# ARRANGE
|
||||
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({"mobile": mobile})
|
||||
self.assertEqual(
|
||||
mobile,
|
||||
guest.mobile,
|
||||
)
|
||||
|
||||
@@ -49,7 +49,9 @@ class RoomingCheckinXlsx(models.AbstractModel):
|
||||
}
|
||||
wanted_list = ["code", "folio", "room"]
|
||||
for field_str in self.env["pms.checkin.partner"]._checkin_partner_fields():
|
||||
render_field_str = "checkin." + field_str
|
||||
render_field_str = (
|
||||
"checkin." + field_str + " if checkin." + field_str + " else ''"
|
||||
)
|
||||
checkin_template[field_str] = {
|
||||
"header": {
|
||||
"value": CheckinPartner._fields[field_str].string,
|
||||
|
||||
Reference in New Issue
Block a user