mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
@@ -213,6 +213,15 @@ class PmsCheckinPartner(models.Model):
|
||||
compute="_compute_partner_incongruences",
|
||||
)
|
||||
|
||||
is_possible_existing_customer_id = fields.Many2one(
|
||||
string="Possible existing customer",
|
||||
readonly=False,
|
||||
store=True,
|
||||
compute="_compute_is_possible_existing_customer_id",
|
||||
)
|
||||
|
||||
add_possible_customer = fields.Boolean(string="Add possible Customer")
|
||||
|
||||
@api.depends("partner_id")
|
||||
def _compute_document_number(self):
|
||||
for record in self:
|
||||
@@ -375,7 +384,12 @@ class PmsCheckinPartner(models.Model):
|
||||
record.document_id = False
|
||||
|
||||
@api.depends(
|
||||
"document_number", "document_type", "firstname", "lastname", "lastname2"
|
||||
"document_number",
|
||||
"document_type",
|
||||
"firstname",
|
||||
"lastname",
|
||||
"lastname2",
|
||||
"add_possible_customer",
|
||||
)
|
||||
def _compute_partner_id(self):
|
||||
for record in self:
|
||||
@@ -402,6 +416,13 @@ class PmsCheckinPartner(models.Model):
|
||||
}
|
||||
partner = self.env["res.partner"].create(partner_values)
|
||||
record.partner_id = partner
|
||||
elif record.add_possible_customer:
|
||||
self.env["pms.folio"]._add_customer(record)
|
||||
|
||||
@api.depends("email", "mobile")
|
||||
def _compute_is_possible_existing_customer_id(self):
|
||||
for record in self:
|
||||
self.env["pms.folio"]._apply_is_possible_existing_customer_id(record)
|
||||
|
||||
@api.depends(
|
||||
"firstname",
|
||||
|
||||
@@ -446,6 +446,37 @@ class PmsFolio(models.Model):
|
||||
help="The payment communication of this sale order.",
|
||||
copy=False,
|
||||
)
|
||||
document_number = fields.Char(
|
||||
string="Document Number",
|
||||
readonly=False,
|
||||
store=True,
|
||||
compute="_compute_document_number",
|
||||
)
|
||||
document_type = fields.Many2one(
|
||||
string="Document Type",
|
||||
readonly=False,
|
||||
store=True,
|
||||
comodel_name="res.partner.id_category",
|
||||
compute="_compute_document_type",
|
||||
)
|
||||
|
||||
document_id = fields.Many2one(
|
||||
string="Document",
|
||||
readonly=False,
|
||||
store=True,
|
||||
comodel_name="res.partner.id_number",
|
||||
compute="_compute_document_id",
|
||||
ondelete="restrict",
|
||||
)
|
||||
|
||||
is_possible_existing_customer_id = fields.Many2one(
|
||||
string="Possible existing customer",
|
||||
readonly=False,
|
||||
store=True,
|
||||
compute="_compute_is_possible_existing_customer_id",
|
||||
)
|
||||
|
||||
add_possible_customer = fields.Boolean(string="Add possible Customer")
|
||||
|
||||
def name_get(self):
|
||||
result = []
|
||||
@@ -640,13 +671,26 @@ class PmsFolio(models.Model):
|
||||
elif not folio.pricelist_id:
|
||||
folio.pricelist_id = folio.pms_property_id.default_pricelist_id
|
||||
|
||||
@api.depends("agency_id", "reservation_type")
|
||||
@api.depends(
|
||||
"agency_id",
|
||||
"reservation_type",
|
||||
"document_number",
|
||||
"document_type",
|
||||
"add_possible_customer",
|
||||
"partner_name",
|
||||
"email",
|
||||
"mobile",
|
||||
)
|
||||
def _compute_partner_id(self):
|
||||
for folio in self:
|
||||
if folio.reservation_type == "out":
|
||||
folio.partner_id = False
|
||||
elif folio.agency_id and folio.agency_id.invoice_to_agency:
|
||||
folio.partner_id = folio.agency_id.id
|
||||
elif folio.document_number and folio.document_type:
|
||||
self._create_partner(folio)
|
||||
elif folio.add_possible_customer:
|
||||
self._add_customer(folio)
|
||||
elif not folio.partner_id:
|
||||
folio.partner_id = False
|
||||
|
||||
@@ -952,6 +996,26 @@ class PmsFolio(models.Model):
|
||||
)
|
||||
record.checkin_partner_pending_count = sum(mapped_checkin_partner_count)
|
||||
|
||||
@api.depends("partner_id")
|
||||
def _compute_document_number(self):
|
||||
for record in self:
|
||||
self._apply_document_number(record)
|
||||
|
||||
@api.depends("partner_id")
|
||||
def _compute_document_type(self):
|
||||
for record in self:
|
||||
self._apply_document_type(record)
|
||||
|
||||
@api.depends("partner_id")
|
||||
def _compute_document_id(self):
|
||||
for record in self:
|
||||
self._apply_document_id(record)
|
||||
|
||||
@api.depends("email", "mobile")
|
||||
def _compute_is_possible_existing_customer_id(self):
|
||||
for record in self:
|
||||
self._apply_is_possible_existing_customer_id(record)
|
||||
|
||||
def _search_invoice_ids(self, operator, value):
|
||||
if operator == "in" and value:
|
||||
self.env.cr.execute(
|
||||
@@ -1710,3 +1774,94 @@ class PmsFolio(models.Model):
|
||||
record.email = record.partner_id.email
|
||||
elif not record.email:
|
||||
record.email = False
|
||||
|
||||
@api.model
|
||||
def _apply_is_possible_existing_customer_id(self, record):
|
||||
if record.email and not record.partner_id:
|
||||
record.is_possible_existing_customer_id = (
|
||||
self.env["res.partner"].search([("email", "=", record.email)]).id
|
||||
)
|
||||
elif record.mobile and not record.partner_id:
|
||||
record.is_possible_existing_customer_id = (
|
||||
self.env["res.partner"].search([("mobile", "=", record.mobile)]).id
|
||||
)
|
||||
else:
|
||||
record.is_possible_existing_customer_id = False
|
||||
|
||||
@api.model
|
||||
def _apply_document_id(self, record):
|
||||
if record.partner_id:
|
||||
if (
|
||||
not record.document_id
|
||||
and record.document_number
|
||||
and record.document_type
|
||||
):
|
||||
id_number_id = self.env["res.partner.id_number"].search(
|
||||
[
|
||||
("partner_id", "=", record.partner_id.id),
|
||||
("name", "=", record.document_number),
|
||||
("category_id", "=", record.document_type.id),
|
||||
]
|
||||
)
|
||||
if not id_number_id:
|
||||
id_number_id = self.env["res.partner.id_number"].create(
|
||||
{
|
||||
"partner_id": record.partner_id.id,
|
||||
"name": record.document_number,
|
||||
"category_id": record.document_type.id,
|
||||
"valid_from": record.document_expedition_date,
|
||||
}
|
||||
)
|
||||
|
||||
record.document_id = id_number_id
|
||||
else:
|
||||
record.document_id = False
|
||||
|
||||
@api.model
|
||||
def _apply_document_number(self, record):
|
||||
if record.partner_id and record.partner_id.id_numbers:
|
||||
if not record.document_number:
|
||||
if record.partner_id.id_numbers:
|
||||
record.document_number = record.partner_id.id_numbers[0].name
|
||||
|
||||
@api.model
|
||||
def _apply_document_type(self, record):
|
||||
if record.partner_id and record.partner_id.id_numbers:
|
||||
if not record.document_type:
|
||||
if record.partner_id.id_numbers:
|
||||
record.document_type = record.partner_id.id_numbers[0].category_id
|
||||
|
||||
@api.model
|
||||
def _create_partner(self, record):
|
||||
number = self.env["res.partner.id_number"].search(
|
||||
[
|
||||
("name", "=", record.document_number),
|
||||
("category_id", "=", record.document_type.id),
|
||||
]
|
||||
)
|
||||
partner = self.env["res.partner"].search([("id", "=", number.partner_id.id)])
|
||||
if not partner:
|
||||
if record.partner_name and record.document_number and record.document_type:
|
||||
partner_values = {
|
||||
"name": record.partner_name,
|
||||
"email": record.email,
|
||||
"mobile": record.mobile,
|
||||
}
|
||||
partner = self.env["res.partner"].create(partner_values)
|
||||
number_values = {
|
||||
"partner_id": partner.id,
|
||||
"name": record.document_number,
|
||||
"category_id": record.document_type.id,
|
||||
}
|
||||
self.env["res.partner.id_number"].create(number_values)
|
||||
record.partner_id = partner
|
||||
|
||||
# REVIEW: we should not force the email and mobile computes,
|
||||
# but if we do not do so,the cache sets the partner_id to False
|
||||
# and therefore also the document_number, email or mobile
|
||||
@api.model
|
||||
def _add_customer(self, record):
|
||||
record.partner_id = record.is_possible_existing_customer_id.id
|
||||
record._compute_document_number()
|
||||
record._compute_email()
|
||||
record._compute_mobile()
|
||||
|
||||
@@ -612,6 +612,38 @@ class PmsReservation(models.Model):
|
||||
store=True,
|
||||
)
|
||||
|
||||
document_number = fields.Char(
|
||||
string="Document Number",
|
||||
readonly=False,
|
||||
store=True,
|
||||
compute="_compute_document_number",
|
||||
)
|
||||
document_type = fields.Many2one(
|
||||
string="Document Type",
|
||||
readonly=False,
|
||||
store=True,
|
||||
comodel_name="res.partner.id_category",
|
||||
compute="_compute_document_type",
|
||||
)
|
||||
|
||||
document_id = fields.Many2one(
|
||||
string="Document",
|
||||
readonly=False,
|
||||
store=True,
|
||||
comodel_name="res.partner.id_number",
|
||||
compute="_compute_document_id",
|
||||
ondelete="restrict",
|
||||
)
|
||||
|
||||
is_possible_existing_customer_id = fields.Many2one(
|
||||
string="Possible existing customer",
|
||||
readonly=False,
|
||||
store=True,
|
||||
compute="_compute_is_possible_existing_customer_id",
|
||||
)
|
||||
|
||||
add_possible_customer = fields.Boolean(string="Add possible Customer")
|
||||
|
||||
def _compute_date_order(self):
|
||||
for record in self:
|
||||
record.date_order = datetime.datetime.today()
|
||||
@@ -783,7 +815,18 @@ class PmsReservation(models.Model):
|
||||
else:
|
||||
reservation.allowed_room_ids = False
|
||||
|
||||
@api.depends("reservation_type", "agency_id", "folio_id", "folio_id.agency_id")
|
||||
@api.depends(
|
||||
"reservation_type",
|
||||
"agency_id",
|
||||
"folio_id",
|
||||
"folio_id.agency_id",
|
||||
"document_number",
|
||||
"document_type",
|
||||
"partner_name",
|
||||
"email",
|
||||
"mobile",
|
||||
"add_possible_customer",
|
||||
)
|
||||
def _compute_partner_id(self):
|
||||
for reservation in self:
|
||||
if not reservation.partner_id:
|
||||
@@ -793,7 +836,11 @@ class PmsReservation(models.Model):
|
||||
reservation.partner_id = reservation.folio_id.partner_id
|
||||
elif reservation.agency_id and reservation.agency_id.invoice_to_agency:
|
||||
reservation.partner_id = reservation.agency_id
|
||||
elif not reservation.folio_id and not reservation.agency_id:
|
||||
elif reservation.document_number and reservation.document_type:
|
||||
self.env["pms.folio"]._create_partner(reservation)
|
||||
elif reservation.add_possible_customer:
|
||||
self.env["pms.folio"]._add_customer(reservation)
|
||||
elif not reservation.partner_id:
|
||||
reservation.partner_id = False
|
||||
|
||||
@api.depends("checkin", "checkout")
|
||||
@@ -1280,7 +1327,7 @@ class PmsReservation(models.Model):
|
||||
else:
|
||||
record.partner_name = record.out_service_description
|
||||
|
||||
@api.depends("partner_id", "partner_id.email", "agency_id")
|
||||
@api.depends("partner_id", "partner_id.email", "agency_id", "add_possible_customer")
|
||||
def _compute_email(self):
|
||||
for record in self:
|
||||
self.env["pms.folio"]._apply_email(record)
|
||||
@@ -1361,6 +1408,26 @@ class PmsReservation(models.Model):
|
||||
else:
|
||||
record.reservation_type = "normal"
|
||||
|
||||
@api.depends("partner_id")
|
||||
def _compute_document_number(self):
|
||||
for record in self:
|
||||
self.env["pms.folio"]._apply_document_number(record)
|
||||
|
||||
@api.depends("partner_id")
|
||||
def _compute_document_type(self):
|
||||
for record in self:
|
||||
self.env["pms.folio"]._apply_document_type(record)
|
||||
|
||||
@api.depends("partner_id")
|
||||
def _compute_document_id(self):
|
||||
for record in self:
|
||||
self.env["pms.folio"]._apply_document_id(record)
|
||||
|
||||
@api.depends("email", "mobile")
|
||||
def _compute_is_possible_existing_customer_id(self):
|
||||
for record in self:
|
||||
self.env["pms.folio"]._apply_is_possible_existing_customer_id(record)
|
||||
|
||||
def _search_allowed_checkin(self, operator, value):
|
||||
if operator not in ("=",):
|
||||
raise UserError(
|
||||
|
||||
@@ -115,7 +115,7 @@ class TestPmsCheckinPartner(TestPms):
|
||||
self.env["res.partner.id_number"].create(
|
||||
{
|
||||
"category_id": self.id_category.id,
|
||||
"name": "30065089H",
|
||||
"name": "85564627G",
|
||||
"valid_from": datetime.date.today(),
|
||||
"partner_id": host2.id,
|
||||
}
|
||||
@@ -232,7 +232,7 @@ class TestPmsCheckinPartner(TestPms):
|
||||
self.env["res.partner.id_number"].create(
|
||||
{
|
||||
"category_id": self.id_category.id,
|
||||
"name": "30065089H",
|
||||
"name": "95876871Z",
|
||||
"valid_from": datetime.date.today(),
|
||||
"partner_id": host2.id,
|
||||
}
|
||||
@@ -249,7 +249,7 @@ class TestPmsCheckinPartner(TestPms):
|
||||
self.env["res.partner.id_number"].create(
|
||||
{
|
||||
"category_id": self.id_category.id,
|
||||
"name": "30065089H",
|
||||
"name": "58261664L",
|
||||
"valid_from": datetime.date.today(),
|
||||
"partner_id": host3.id,
|
||||
}
|
||||
@@ -266,7 +266,7 @@ class TestPmsCheckinPartner(TestPms):
|
||||
self.env["res.partner.id_number"].create(
|
||||
{
|
||||
"category_id": self.id_category.id,
|
||||
"name": "30065089H",
|
||||
"name": "61645604S",
|
||||
"valid_from": datetime.date.today(),
|
||||
"partner_id": host4.id,
|
||||
}
|
||||
@@ -322,7 +322,7 @@ class TestPmsCheckinPartner(TestPms):
|
||||
self.env["res.partner.id_number"].create(
|
||||
{
|
||||
"category_id": self.id_category.id,
|
||||
"name": "30065089H",
|
||||
"name": "63073204M",
|
||||
"valid_from": datetime.date.today(),
|
||||
"partner_id": self.host2.id,
|
||||
}
|
||||
@@ -339,7 +339,7 @@ class TestPmsCheckinPartner(TestPms):
|
||||
self.env["res.partner.id_number"].create(
|
||||
{
|
||||
"category_id": self.id_category.id,
|
||||
"name": "30065089H",
|
||||
"name": "70699468K",
|
||||
"valid_from": datetime.date.today(),
|
||||
"partner_id": self.host3.id,
|
||||
}
|
||||
@@ -397,7 +397,7 @@ class TestPmsCheckinPartner(TestPms):
|
||||
self.env["res.partner.id_number"].create(
|
||||
{
|
||||
"category_id": self.id_category.id,
|
||||
"name": "30065089H",
|
||||
"name": "12650631X",
|
||||
"valid_from": datetime.date.today(),
|
||||
"partner_id": self.host2.id,
|
||||
}
|
||||
@@ -450,7 +450,7 @@ class TestPmsCheckinPartner(TestPms):
|
||||
self.env["res.partner.id_number"].create(
|
||||
{
|
||||
"category_id": self.id_category.id,
|
||||
"name": "30065089H",
|
||||
"name": "61369791H",
|
||||
"valid_from": datetime.date.today(),
|
||||
"partner_id": self.host2.id,
|
||||
}
|
||||
@@ -467,7 +467,7 @@ class TestPmsCheckinPartner(TestPms):
|
||||
self.env["res.partner.id_number"].create(
|
||||
{
|
||||
"category_id": self.id_category.id,
|
||||
"name": "30065089H",
|
||||
"name": "53563260D",
|
||||
"valid_from": datetime.date.today(),
|
||||
"partner_id": self.host3.id,
|
||||
}
|
||||
@@ -484,7 +484,7 @@ class TestPmsCheckinPartner(TestPms):
|
||||
self.env["res.partner.id_number"].create(
|
||||
{
|
||||
"category_id": self.id_category.id,
|
||||
"name": "30065089H",
|
||||
"name": "63742138F",
|
||||
"valid_from": datetime.date.today(),
|
||||
"partner_id": self.host4.id,
|
||||
}
|
||||
|
||||
@@ -558,3 +558,234 @@ class TestPmsFolio(TestPms):
|
||||
"reservation_type": "staff",
|
||||
}
|
||||
)
|
||||
|
||||
def test_create_partner_in_folio(self):
|
||||
"""
|
||||
Check that a res_partner is created from a folio.
|
||||
------------
|
||||
A folio is created by adding the document_type and
|
||||
document_number fields, with these two fields a res.partner
|
||||
should be created, which is what is checked after creating
|
||||
the folio.
|
||||
"""
|
||||
# ARRANGE
|
||||
self.id_category = self.env["res.partner.id_category"].create(
|
||||
{"name": "DNI", "code": "D"}
|
||||
)
|
||||
# ACT
|
||||
folio1 = self.env["pms.folio"].create(
|
||||
{
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
"partner_name": "Savannah Byles",
|
||||
"document_type": self.id_category.id,
|
||||
"document_number": "32861114W",
|
||||
}
|
||||
)
|
||||
# ASSERT
|
||||
self.assertTrue(folio1.partner_id.id, "The partner has not been created")
|
||||
|
||||
def test_auto_complete_partner_mobile(self):
|
||||
"""
|
||||
It is checked that the mobile field of the folio
|
||||
is correctly added to it when the document_number and
|
||||
document_type fields of a res.partner that exists in
|
||||
the DB are put in the folio.
|
||||
--------------------
|
||||
A res.partner is created with the name, mobile and email fields.
|
||||
The document_id is added to the res.partner. The folio is
|
||||
created and the category_id of the document_id associated with
|
||||
the res.partner is added as document_type and as document_number
|
||||
the name of the document_id associated with the res.partner as well.
|
||||
Then it is checked that the mobile of the res.partner and that of
|
||||
the folio are the same.
|
||||
"""
|
||||
# ARRANGE
|
||||
partner = self.env["res.partner"].create(
|
||||
{
|
||||
"name": "Enrique",
|
||||
"mobile": "654667733",
|
||||
"email": "enrique@example.com",
|
||||
}
|
||||
)
|
||||
self.id_category = self.env["res.partner.id_category"].create(
|
||||
{"name": "DNI", "code": "D"}
|
||||
)
|
||||
self.document_id = self.env["res.partner.id_number"].create(
|
||||
{
|
||||
"category_id": self.id_category.id,
|
||||
"name": "61645604S",
|
||||
"partner_id": partner.id,
|
||||
}
|
||||
)
|
||||
# ACT
|
||||
folio1 = self.env["pms.folio"].create(
|
||||
{
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
"partner_name": partner.name,
|
||||
"document_type": self.document_id.category_id.id,
|
||||
"document_number": self.document_id.name,
|
||||
}
|
||||
)
|
||||
# ASSERT
|
||||
self.assertEqual(
|
||||
folio1.mobile,
|
||||
partner.mobile,
|
||||
"The partner mobile has not autocomplete in folio",
|
||||
)
|
||||
|
||||
def test_auto_complete_partner_email(self):
|
||||
"""
|
||||
It is checked that the email field of the folio
|
||||
is correctly added to it when the document_number and
|
||||
document_type fields of a res.partner that exists in
|
||||
the DB are put in the folio.
|
||||
--------------------
|
||||
A res.partner is created with the name, mobile and email fields.
|
||||
The document_id is added to the res.partner. The folio is
|
||||
created and the category_id of the document_id associated with
|
||||
the res.partner is added as document_type and as document_number
|
||||
the name of the document_id associated with the res.partner as well.
|
||||
Then it is checked that the email of the res.partner and that of
|
||||
the folio are the same.
|
||||
"""
|
||||
# ARRANGE
|
||||
partner = self.env["res.partner"].create(
|
||||
{
|
||||
"name": "Simon",
|
||||
"mobile": "654667733",
|
||||
"email": "simon@example.com",
|
||||
}
|
||||
)
|
||||
self.id_category = self.env["res.partner.id_category"].create(
|
||||
{"name": "DNI", "code": "D"}
|
||||
)
|
||||
self.document_id = self.env["res.partner.id_number"].create(
|
||||
{
|
||||
"category_id": self.id_category.id,
|
||||
"name": "74247377L",
|
||||
"partner_id": partner.id,
|
||||
}
|
||||
)
|
||||
|
||||
# ACT
|
||||
folio1 = self.env["pms.folio"].create(
|
||||
{
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
"partner_name": partner.name,
|
||||
"document_type": self.document_id.category_id.id,
|
||||
"document_number": self.document_id.name,
|
||||
}
|
||||
)
|
||||
# ASSERT
|
||||
self.assertEqual(
|
||||
folio1.email,
|
||||
partner.email,
|
||||
"The partner mobile has not autocomplete in folio",
|
||||
)
|
||||
|
||||
def test_is_possible_customer_by_email(self):
|
||||
"""
|
||||
It is checked that the field is_possible_existing_customer_id
|
||||
exists in a folio with an email from a res.partner saved
|
||||
in the DB.
|
||||
----------------
|
||||
A res.partner is created with the name and email fields. A folio
|
||||
is created by adding the same email as the res.partner. Then it is
|
||||
checked that the field is_possible_existing_customer_id is equal to True.
|
||||
"""
|
||||
# ARRANGE
|
||||
partner = self.env["res.partner"].create(
|
||||
{
|
||||
"name": "Courtney Campbell",
|
||||
"email": "courtney@example.com",
|
||||
}
|
||||
)
|
||||
# ACT
|
||||
folio1 = self.env["pms.folio"].create(
|
||||
{
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
"partner_name": partner.name,
|
||||
"email": partner.email,
|
||||
}
|
||||
)
|
||||
# ASSERT
|
||||
self.assertTrue(
|
||||
folio1.is_possible_existing_customer_id, "No customer found with this email"
|
||||
)
|
||||
|
||||
def test_is_possible_customer_by_mobile(self):
|
||||
"""
|
||||
It is checked that the field is_possible_existing_customer_id
|
||||
exists in a folio with a mobile from a res.partner saved
|
||||
in the DB.
|
||||
----------------
|
||||
A res.partner is created with the name and email fields. A folio
|
||||
is created by adding the same mobile as the res.partner. Then it is
|
||||
checked that the field is_possible_existing_customer_id is equal to True.
|
||||
"""
|
||||
# ARRANGE
|
||||
partner = self.env["res.partner"].create(
|
||||
{
|
||||
"name": "Ledicia Sandoval",
|
||||
"mobile": "615369231",
|
||||
}
|
||||
)
|
||||
# ACT
|
||||
folio1 = self.env["pms.folio"].create(
|
||||
{
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
"partner_name": partner.name,
|
||||
"mobile": partner.mobile,
|
||||
}
|
||||
)
|
||||
# ASSERT
|
||||
self.assertTrue(
|
||||
folio1.is_possible_existing_customer_id,
|
||||
"No customer found with this mobile",
|
||||
)
|
||||
|
||||
def test_add_possible_customer(self):
|
||||
"""
|
||||
It is checked that after setting the add_possible_customer
|
||||
field of a folio to True, the partner_id that has the
|
||||
email that was placed in the folio is added.
|
||||
---------------
|
||||
A res.partner is created with name, email and mobile. The document_id
|
||||
is added to the res.partner. A folio is created with the email
|
||||
field equal to that of the res.partner created before. The value of
|
||||
the add_possible_customer field is changed to True. Then it is checked
|
||||
that the id of the partner_id of the folio is equal to the id of
|
||||
the res.partner created previously.
|
||||
"""
|
||||
# ARRANGE
|
||||
partner = self.env["res.partner"].create(
|
||||
{
|
||||
"name": "Serafín Rivas",
|
||||
"email": "serafin@example.com",
|
||||
"mobile": "60595595",
|
||||
}
|
||||
)
|
||||
self.id_category = self.env["res.partner.id_category"].create(
|
||||
{"name": "DNI", "code": "D"}
|
||||
)
|
||||
self.document_id = self.env["res.partner.id_number"].create(
|
||||
{
|
||||
"category_id": self.id_category.id,
|
||||
"name": "84223588A",
|
||||
"partner_id": partner.id,
|
||||
}
|
||||
)
|
||||
# ACT
|
||||
folio1 = self.env["pms.folio"].create(
|
||||
{
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
"partner_name": partner.name,
|
||||
"email": partner.email,
|
||||
}
|
||||
)
|
||||
|
||||
folio1.add_possible_customer = True
|
||||
# ASSERT
|
||||
self.assertEqual(
|
||||
folio1.partner_id.id, partner.id, "The partner was not added to the folio "
|
||||
)
|
||||
|
||||
@@ -3159,3 +3159,268 @@ class TestPmsReservations(TestPms):
|
||||
reservation.partner_id,
|
||||
"The partner of an out of service reservation should be False",
|
||||
)
|
||||
|
||||
def test_create_partner_in_reservation(self):
|
||||
"""
|
||||
Check that a res_partner is created from a reservation.
|
||||
------------
|
||||
A reservation is created by adding the document_type and
|
||||
document_number fields, with these two fields a res.partner
|
||||
should be created, which is what is checked after creating
|
||||
the reservation.
|
||||
"""
|
||||
# ARRANGE
|
||||
checkin = fields.date.today()
|
||||
checkout = fields.date.today() + datetime.timedelta(days=3)
|
||||
self.id_category = self.env["res.partner.id_category"].create(
|
||||
{"name": "DNI", "code": "D"}
|
||||
)
|
||||
# ACT
|
||||
reservation = self.env["pms.reservation"].create(
|
||||
{
|
||||
"checkin": checkin,
|
||||
"checkout": checkout,
|
||||
"room_type_id": self.room_type_double.id,
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
"partner_name": "Elis",
|
||||
"email": "elis@mail.com",
|
||||
"mobile": "61568547",
|
||||
"document_type": self.id_category.id,
|
||||
"document_number": "31640132K",
|
||||
}
|
||||
)
|
||||
# ASSERT
|
||||
self.assertTrue(reservation.partner_id, "The partner has not been created")
|
||||
|
||||
def test_auto_complete_partner_mobile(self):
|
||||
"""
|
||||
It is checked that the mobile field of the reservation
|
||||
is correctly added to it when the document_number and
|
||||
document_type fields of a res.partner that exists in
|
||||
the DB are put in the reservation.
|
||||
--------------------
|
||||
A res.partner is created with the name, mobile and email fields.
|
||||
The document_id is added to the res.partner. The reservation is
|
||||
created and the category_id of the document_id associated with
|
||||
the res.partner is added as document_type and as document_number
|
||||
the name of the document_id associated with the res.partner as well.
|
||||
Then it is verified that the mobile of the res.partner and that of
|
||||
the reservation are the same.
|
||||
"""
|
||||
# ARRANGE
|
||||
partner = self.env["res.partner"].create(
|
||||
{
|
||||
"name": "Enrique",
|
||||
"mobile": "654667733",
|
||||
"email": "enrique@example.com",
|
||||
}
|
||||
)
|
||||
self.id_category = self.env["res.partner.id_category"].create(
|
||||
{"name": "DNI", "code": "D"}
|
||||
)
|
||||
self.document_id = self.env["res.partner.id_number"].create(
|
||||
{
|
||||
"category_id": self.id_category.id,
|
||||
"name": "61645604S",
|
||||
"partner_id": partner.id,
|
||||
}
|
||||
)
|
||||
checkin = fields.date.today()
|
||||
checkout = fields.date.today() + datetime.timedelta(days=3)
|
||||
# ACT
|
||||
reservation = self.env["pms.reservation"].create(
|
||||
{
|
||||
"checkin": checkin,
|
||||
"checkout": checkout,
|
||||
"room_type_id": self.room_type_double.id,
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
"partner_name": partner.name,
|
||||
"document_type": self.document_id.category_id.id,
|
||||
"document_number": self.document_id.name,
|
||||
}
|
||||
)
|
||||
# ASSERT
|
||||
self.assertEqual(
|
||||
reservation.mobile,
|
||||
partner.mobile,
|
||||
"The partner mobile has not autocomplete in reservation",
|
||||
)
|
||||
|
||||
def test_auto_complete_partner_email(self):
|
||||
"""
|
||||
It is checked that the email field of the reservation
|
||||
is correctly added to it when the document_number and
|
||||
document_type fields of a res.partner that exists in
|
||||
the DB are put in the reservation.
|
||||
--------------------
|
||||
A res.partner is created with the name, mobile and email fields.
|
||||
The document_id is added to the res.partner. The reservation is
|
||||
created and the category_id of the document_id associated with
|
||||
the res.partner is added as document_type and as document_number
|
||||
the name of the document_id associated with the res.partner as well.
|
||||
Then it is verified that the email of the res.partner and that of
|
||||
the reservation are the same.
|
||||
"""
|
||||
# ARRANGE
|
||||
partner = self.env["res.partner"].create(
|
||||
{
|
||||
"name": "Simon",
|
||||
"mobile": "654667733",
|
||||
"email": "simon@example.com",
|
||||
}
|
||||
)
|
||||
self.id_category = self.env["res.partner.id_category"].create(
|
||||
{"name": "DNI", "code": "D"}
|
||||
)
|
||||
self.document_id = self.env["res.partner.id_number"].create(
|
||||
{
|
||||
"category_id": self.id_category.id,
|
||||
"name": "74247377L",
|
||||
"partner_id": partner.id,
|
||||
}
|
||||
)
|
||||
checkin = fields.date.today()
|
||||
checkout = fields.date.today() + datetime.timedelta(days=3)
|
||||
# ACT
|
||||
reservation = self.env["pms.reservation"].create(
|
||||
{
|
||||
"checkin": checkin,
|
||||
"checkout": checkout,
|
||||
"room_type_id": self.room_type_double.id,
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
"partner_name": partner.name,
|
||||
"document_type": self.document_id.category_id.id,
|
||||
"document_number": self.document_id.name,
|
||||
}
|
||||
)
|
||||
# ASSERT
|
||||
self.assertEqual(
|
||||
reservation.email,
|
||||
partner.email,
|
||||
"The partner mobile has not autocomplete in reservation",
|
||||
)
|
||||
|
||||
def test_is_possible_customer_by_email(self):
|
||||
"""
|
||||
It is checked that the field is_possible_existing_customer_id
|
||||
exists in a reservation with an email from a res.partner saved
|
||||
in the DB.
|
||||
----------------
|
||||
A res.partner is created with the name and email fields. A reservation
|
||||
is created by adding the same email as the res.partner. Then it is
|
||||
checked that the field is_possible_existing_customer_id is equal to True.
|
||||
"""
|
||||
# ARRANGE
|
||||
partner = self.env["res.partner"].create(
|
||||
{
|
||||
"name": "Courtney Campbell",
|
||||
"email": "courtney@example.com",
|
||||
}
|
||||
)
|
||||
checkin = fields.date.today()
|
||||
checkout = fields.date.today() + datetime.timedelta(days=3)
|
||||
# ACT
|
||||
reservation = self.env["pms.reservation"].create(
|
||||
{
|
||||
"checkin": checkin,
|
||||
"checkout": checkout,
|
||||
"room_type_id": self.room_type_double.id,
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
"partner_name": partner.name,
|
||||
"email": partner.email,
|
||||
}
|
||||
)
|
||||
# ASSERT
|
||||
self.assertTrue(
|
||||
reservation.is_possible_existing_customer_id,
|
||||
"No customer found with this email",
|
||||
)
|
||||
|
||||
def test_is_possible_customer_by_mobile(self):
|
||||
"""
|
||||
It is checked that the field is_possible_existing_customer_id
|
||||
exists in a reservation with a mobile from a res.partner saved
|
||||
in the DB.
|
||||
----------------
|
||||
A res.partner is created with the name and email fields. A reservation
|
||||
is created by adding the same mobile as the res.partner. Then it is
|
||||
checked that the field is_possible_existing_customer_id is equal to True.
|
||||
"""
|
||||
# ARRANGE
|
||||
partner = self.env["res.partner"].create(
|
||||
{
|
||||
"name": "Ledicia Sandoval",
|
||||
"mobile": "615369231",
|
||||
}
|
||||
)
|
||||
checkin = fields.date.today()
|
||||
checkout = fields.date.today() + datetime.timedelta(days=3)
|
||||
# ACT
|
||||
reservation = self.env["pms.reservation"].create(
|
||||
{
|
||||
"checkin": checkin,
|
||||
"checkout": checkout,
|
||||
"room_type_id": self.room_type_double.id,
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
"partner_name": partner.name,
|
||||
"mobile": partner.mobile,
|
||||
}
|
||||
)
|
||||
# ASSERT
|
||||
self.assertTrue(
|
||||
reservation.is_possible_existing_customer_id,
|
||||
"No customer found with this mobile",
|
||||
)
|
||||
|
||||
def test_add_possible_customer(self):
|
||||
"""
|
||||
It is checked that after setting the add_possible_customer
|
||||
field of a reservation to True, the partner_id that has the
|
||||
email that was placed in the reservation is added.
|
||||
---------------
|
||||
A res.partner is created with name, email and mobile. The document_id
|
||||
is added to the res.partner. A reservation is created with the email
|
||||
field equal to that of the res.partner created before. The value of
|
||||
the add_possible_customer field is changed to True. Then it is verified
|
||||
that the id of the partner_id of the reservation is equal to the id of
|
||||
the res.partner created previously.
|
||||
"""
|
||||
# ARRANGE
|
||||
partner = self.env["res.partner"].create(
|
||||
{
|
||||
"name": "Serafín Rivas",
|
||||
"email": "serafin@example.com",
|
||||
"mobile": "60595595",
|
||||
}
|
||||
)
|
||||
self.id_category = self.env["res.partner.id_category"].create(
|
||||
{"name": "DNI", "code": "D"}
|
||||
)
|
||||
self.document_id = self.env["res.partner.id_number"].create(
|
||||
{
|
||||
"category_id": self.id_category.id,
|
||||
"name": "84223588A",
|
||||
"partner_id": partner.id,
|
||||
}
|
||||
)
|
||||
checkin = fields.date.today()
|
||||
checkout = fields.date.today() + datetime.timedelta(days=3)
|
||||
# ACT
|
||||
reservation = self.env["pms.reservation"].create(
|
||||
{
|
||||
"checkin": checkin,
|
||||
"checkout": checkout,
|
||||
"room_type_id": self.room_type_double.id,
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
"partner_name": partner.name,
|
||||
"email": partner.email,
|
||||
}
|
||||
)
|
||||
|
||||
reservation.add_possible_customer = True
|
||||
# ASSERT
|
||||
self.assertEqual(
|
||||
reservation.partner_id.id,
|
||||
partner.id,
|
||||
"The partner was not added to the reservation ",
|
||||
)
|
||||
|
||||
@@ -38,6 +38,19 @@
|
||||
/>
|
||||
</bold>
|
||||
</div>
|
||||
<div
|
||||
class="alert alert-warning"
|
||||
role="alert"
|
||||
style="margin-bottom:0px;"
|
||||
attrs="{'invisible': [('is_possible_existing_customer_id','=',False)]}"
|
||||
>
|
||||
There is a customer with this email or mobile, do you want to add it to the reservation?
|
||||
<field name="is_possible_existing_customer_id" invisible="1" />
|
||||
<field
|
||||
name="add_possible_customer"
|
||||
attrs="{'invisible': [('is_possible_existing_customer_id','=',False)]}"
|
||||
/>
|
||||
</div>
|
||||
<group name="group_top">
|
||||
<group name="group_left">
|
||||
<field
|
||||
|
||||
@@ -55,6 +55,19 @@
|
||||
/>
|
||||
</bold>
|
||||
</div>
|
||||
<div
|
||||
class="alert alert-warning"
|
||||
role="alert"
|
||||
style="margin-bottom:0px;"
|
||||
attrs="{'invisible': [('is_possible_existing_customer_id','=',False)]}"
|
||||
>
|
||||
There is a customer with this email or mobile, do you want to add it to the reservation?
|
||||
<field name="is_possible_existing_customer_id" invisible="1" />
|
||||
<field
|
||||
name="add_possible_customer"
|
||||
attrs="{'invisible': [('is_possible_existing_customer_id','=',False)]}"
|
||||
/>
|
||||
</div>
|
||||
<sheet>
|
||||
<div class="oe_button_box" name="button_box">
|
||||
<button
|
||||
@@ -209,6 +222,14 @@
|
||||
string="General Info"
|
||||
name="contact_details"
|
||||
>
|
||||
<field
|
||||
name="document_type"
|
||||
attrs="{'invisible':[('reservation_type','in',('out'))]}"
|
||||
/>
|
||||
<field
|
||||
name="document_number"
|
||||
attrs="{'invisible':[('reservation_type','in',('out'))]}"
|
||||
/>
|
||||
<field
|
||||
name="partner_name"
|
||||
placeholder="Guest"
|
||||
|
||||
@@ -116,6 +116,19 @@
|
||||
|
||||
</bold>
|
||||
</div>
|
||||
<div
|
||||
class="alert alert-warning"
|
||||
role="alert"
|
||||
style="margin-bottom:0px;"
|
||||
attrs="{'invisible': [('is_possible_existing_customer_id','=',False)]}"
|
||||
>
|
||||
There is a customer with this email or mobile, do you want to add it to the reservation?
|
||||
<field name="is_possible_existing_customer_id" invisible="1" />
|
||||
<field
|
||||
name="add_possible_customer"
|
||||
attrs="{'invisible': [('is_possible_existing_customer_id','=',False)]}"
|
||||
/>
|
||||
</div>
|
||||
<sheet>
|
||||
<field name="shared_folio" invisible="1" />
|
||||
<field name="allowed_checkin" invisible="1" />
|
||||
@@ -308,8 +321,13 @@
|
||||
string="General Info"
|
||||
name="contact_details"
|
||||
>
|
||||
<field name="partner_id" invisible="1" />
|
||||
<field
|
||||
name="partner_id"
|
||||
name="document_type"
|
||||
attrs="{'invisible':[('reservation_type','in',('out'))]}"
|
||||
/>
|
||||
<field
|
||||
name="document_number"
|
||||
attrs="{'invisible':[('reservation_type','in',('out'))]}"
|
||||
/>
|
||||
<field
|
||||
|
||||
Reference in New Issue
Block a user