[IMP]added tests for pms_reservation, pms_folio and pms_checkin_partner

This commit is contained in:
braisab
2021-09-10 16:40:33 +02:00
parent 20a6197c11
commit 4f5aa2c0e4
5 changed files with 483 additions and 69 deletions

View File

@@ -921,3 +921,244 @@ class TestPmsCheckinPartner(TestPms):
host.id,
"Checkin partner_id must be the same as the one who has that document",
)
def test_is_possible_customer_by_email(self):
"""
It is checked that the field possible_existing_customer_ids
exists in a checkin partner with an email from a res.partner saved
in the DB.
----------------
A res.partner is created with the name and email fields. A checkin partner
is created by adding the same email as the res.partner. Then it is
checked that some possible_existing_customer_ids exists.
"""
# 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)
reservation = self.env["pms.reservation"].create(
{
"checkin": checkin,
"checkout": checkout,
"room_type_id": self.room_type1.id,
"pms_property_id": self.pms_property1.id,
"partner_name": partner.name,
"email": partner.email,
}
)
# ACT
checkin = self.env["pms.checkin.partner"].create(
{
"name": partner.name,
"email": partner.email,
"reservation_id": reservation.id,
}
)
# ASSERT
self.assertTrue(
checkin.possible_existing_customer_ids,
"No customer found with this email",
)
def test_is_possible_customer_by_mobile(self):
"""
It is checked that the field possible_existing_customer_ids
exists in a checkin partner with a mobile from a res.partner saved
in the DB.
----------------
A res.partner is created with the name and email fields. A checkin partner
is created by adding the same mobile as the res.partner. Then it is
checked that some possible_existing_customer_ids exists.
"""
# ARRANGE
partner = self.env["res.partner"].create(
{
"name": "Ledicia Sandoval",
"mobile": "615369231",
}
)
checkin = fields.date.today()
checkout = fields.date.today() + datetime.timedelta(days=3)
reservation = self.env["pms.reservation"].create(
{
"checkin": checkin,
"checkout": checkout,
"room_type_id": self.room_type1.id,
"pms_property_id": self.pms_property1.id,
"partner_name": partner.name,
}
)
# ACT
checkin = self.env["pms.checkin.partner"].create(
{
"name": partner.name,
"mobile": partner.mobile,
"reservation_id": reservation.id,
}
)
# ASSERT
self.assertTrue(
checkin.possible_existing_customer_ids,
"No customer found with this mobile",
)
def test_add_possible_customer(self):
"""
Check that a partner was correctly added to the checkin partner
after launching the add_partner() method of the several partners wizard
---------------
A res.partner is created with name, email and mobile. A checkin partner is
created with the email field equal to that of the res.partner created before.
The wizard is created with the checkin partner id and the partner added to the
possible_existing_customer_ids field. The add_partner method of the wizard
is launched and it is checked that the partner was correctly added to the
checkin partner.
"""
# ARRANGE
partner = self.env["res.partner"].create(
{
"name": "Serafín Rivas",
"email": "serafin@example.com",
"mobile": "60595595",
}
)
checkin = fields.date.today()
checkout = fields.date.today() + datetime.timedelta(days=3)
reservation = self.env["pms.reservation"].create(
{
"checkin": checkin,
"checkout": checkout,
"room_type_id": self.room_type1.id,
"pms_property_id": self.pms_property1.id,
"partner_name": partner.name,
}
)
checkin = self.env["pms.checkin.partner"].create(
{
"name": partner.name,
"email": partner.email,
"reservation_id": reservation.id,
}
)
several_partners_wizard = self.env["pms.several.partners.wizard"].create(
{
"checkin_partner_id": checkin.id,
"possible_existing_customer_ids": [(6, 0, [partner.id])],
}
)
# ACT
several_partners_wizard.add_partner()
# ASSERT
self.assertEqual(
checkin.partner_id.id,
partner.id,
"The partner was not added to the checkin partner ",
)
def test_not_add_several_possibles_customers(self):
"""
Check that multiple partners cannot be added to a checkin partner
from the several partners wizard.
---------------
Two res.partner are created with name, email and mobile. A checkin partner is
created with the email field equal to that of the partner1 created before.
The wizard is created with the checkin partner id and the two partners added to the
possible_existing_customer_ids field. The add_partner method of the wizard
is launched and it is verified that a Validation_Error was raised.
"""
# ARRANGE
partner1 = self.env["res.partner"].create(
{
"name": "Serafín Rivas",
"email": "serafin@example.com",
"mobile": "60595595",
}
)
partner2 = self.env["res.partner"].create(
{
"name": "Simon",
"mobile": "654667733",
"email": "simon@example.com",
}
)
checkin = fields.date.today()
checkout = fields.date.today() + datetime.timedelta(days=3)
reservation = self.env["pms.reservation"].create(
{
"checkin": checkin,
"checkout": checkout,
"room_type_id": self.room_type1.id,
"pms_property_id": self.pms_property1.id,
"partner_name": partner1.name,
}
)
checkin = self.env["pms.checkin.partner"].create(
{
"name": partner1.name,
"email": partner1.email,
"reservation_id": reservation.id,
}
)
several_partners_wizard = self.env["pms.several.partners.wizard"].create(
{
"checkin_partner_id": checkin.id,
"possible_existing_customer_ids": [(6, 0, [partner1.id, partner2.id])],
}
)
# ACT AND ASSERT
with self.assertRaises(
ValidationError,
msg="Two partners cannot be added to the checkin partner",
):
several_partners_wizard.add_partner()
def test_not_add_any_possibles_customers(self):
"""
Check that the possible_existing_customer_ids field of the several
partners wizard can be left empty and then launch the add_partner()
method of this wizard to add a partner in checkin_partner.
---------------
A checkin_partner is created. The wizard is created without the
possible_existing_customer_ids field. The add_partner method of
the wizard is launched and it is verified that a Validation_Error
was raised.
"""
# ARRANGE
checkin = fields.date.today()
checkout = fields.date.today() + datetime.timedelta(days=3)
reservation = self.env["pms.reservation"].create(
{
"checkin": checkin,
"checkout": checkout,
"room_type_id": self.room_type1.id,
"pms_property_id": self.pms_property1.id,
"partner_name": "Rosa Costa",
}
)
checkin = self.env["pms.checkin.partner"].create(
{"name": "Rosa Costa", "reservation_id": reservation.id}
)
several_partners_wizard = self.env["pms.several.partners.wizard"].create(
{
"checkin_partner_id": checkin.id,
}
)
# ACT AND ASSERT
with self.assertRaises(
ValidationError,
msg="A partner can be added to the checkin partner",
):
several_partners_wizard.add_partner()

View File

@@ -710,7 +710,7 @@ class TestPmsFolio(TestPms):
)
# ASSERT
self.assertTrue(
folio1.is_possible_existing_customer_id, "No customer found with this email"
folio1.possible_existing_customer_ids, "No customer found with this email"
)
def test_is_possible_customer_by_mobile(self):
@@ -740,22 +740,20 @@ class TestPmsFolio(TestPms):
)
# ASSERT
self.assertTrue(
folio1.is_possible_existing_customer_id,
folio1.possible_existing_customer_ids,
"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.
Check that a partner was correctly added to the folio
after launching the add_partner() method of the several partners wizard
---------------
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.
A res.partner is created with name, email and mobile. A folio is created.
The wizard is created with the folio id and the partner added to the
possible_existing_customer_ids field. The add_partner method of the wizard
is launched and it is checked that the partner was correctly added to the
folio.
"""
# ARRANGE
partner = self.env["res.partner"].create(
@@ -765,17 +763,7 @@ class TestPmsFolio(TestPms):
"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,
@@ -784,8 +772,98 @@ class TestPmsFolio(TestPms):
}
)
folio1.add_possible_customer = True
several_partners_wizard = self.env["pms.several.partners.wizard"].create(
{
"folio_id": folio1.id,
"possible_existing_customer_ids": [(6, 0, [partner.id])],
}
)
# ACT
several_partners_wizard.add_partner()
# ASSERT
self.assertEqual(
folio1.partner_id.id, partner.id, "The partner was not added to the folio "
folio1.partner_id.id,
partner.id,
"The partner was not added to the folio ",
)
def test_not_add_several_possibles_customers(self):
"""
Check that multiple partners cannot be added to a folio
from the several partners wizard.
---------------
Two res.partner are created with name, email and mobile. A folio is created.
The wizard is created with the folio id and the two partners added to the
possible_existing_customer_ids field. The add_partner method of the wizard
is launched and it is verified that a Validation_Error was raised.
"""
# ARRANGE
partner1 = self.env["res.partner"].create(
{
"name": "Serafín Rivas",
"email": "serafin@example.com",
"mobile": "60595595",
}
)
partner2 = self.env["res.partner"].create(
{
"name": "Simon",
"mobile": "654667733",
"email": "simon@example.com",
}
)
folio1 = self.env["pms.folio"].create(
{
"pms_property_id": self.pms_property1.id,
"partner_name": partner1.name,
"email": partner1.email,
}
)
several_partners_wizard = self.env["pms.several.partners.wizard"].create(
{
"folio_id": folio1.id,
"possible_existing_customer_ids": [(6, 0, [partner1.id, partner2.id])],
}
)
# ACT AND ASSERT
with self.assertRaises(
ValidationError,
msg="Two partners cannot be added to the folio",
):
several_partners_wizard.add_partner()
def test_not_add_any_possibles_customers(self):
"""
Check that the possible_existing_customer_ids field of the several
partners wizard can be left empty and then launch the add_partner()
method of this wizard to add a partner in folio.
---------------
A folio is created. The wizard is created without the
possible_existing_customer_ids field. The add_partner method of
the wizard is launched and it is verified that a Validation_Error
was raised.
"""
# ARRANGE
folio1 = self.env["pms.folio"].create(
{
"pms_property_id": self.pms_property1.id,
"partner_name": "Rosa Costa",
}
)
several_partners_wizard = self.env["pms.several.partners.wizard"].create(
{
"folio_id": folio1.id,
}
)
# ACT AND ASSERT
with self.assertRaises(
ValidationError,
msg="A partner can be added to the folio",
):
several_partners_wizard.add_partner()

View File

@@ -3302,13 +3302,13 @@ class TestPmsReservations(TestPms):
def test_is_possible_customer_by_email(self):
"""
It is checked that the field is_possible_existing_customer_id
It is checked that the field possible_existing_customer_ids
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.
checked that some possible_existing_customer_ids exists.
"""
# ARRANGE
partner = self.env["res.partner"].create(
@@ -3332,19 +3332,19 @@ class TestPmsReservations(TestPms):
)
# ASSERT
self.assertTrue(
reservation.is_possible_existing_customer_id,
reservation.possible_existing_customer_ids,
"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
It is checked that the field possible_existing_customer_ids
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.
checked that some possible_existing_customer_ids exists.
"""
# ARRANGE
partner = self.env["res.partner"].create(
@@ -3368,22 +3368,21 @@ class TestPmsReservations(TestPms):
)
# ASSERT
self.assertTrue(
reservation.is_possible_existing_customer_id,
reservation.possible_existing_customer_ids,
"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.
Check that a partner was correctly added to the reservation
after launching the add_partner() method of the several partners wizard
---------------
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.
A res.partner is created with name, email and mobile. A reservation is
created with the email field equal to that of the res.partner created before.
The wizard is created with the reservation id and the partner added to the
possible_existing_customer_ids field. The add_partner method of the wizard
is launched and it is checked that the partner was correctly added to the
reservation.
"""
# ARRANGE
partner = self.env["res.partner"].create(
@@ -3393,16 +3392,6 @@ class TestPmsReservations(TestPms):
"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
@@ -3417,7 +3406,14 @@ class TestPmsReservations(TestPms):
}
)
reservation.add_possible_customer = True
several_partners_wizard = self.env["pms.several.partners.wizard"].create(
{
"reservation_id": reservation.id,
"possible_existing_customer_ids": [(6, 0, [partner.id])],
}
)
several_partners_wizard.add_partner()
# ASSERT
self.assertEqual(
reservation.partner_id.id,
@@ -3498,3 +3494,96 @@ class TestPmsReservations(TestPms):
reservation.is_modified_reservation,
"is_modified_reservation field should be False ",
)
def test_not_add_several_possibles_customers(self):
"""
Check that multiple partners cannot be added to a reservation
from the several partners wizard.
---------------
Two res.partner are created with name, email and mobile. A reservation is
created with the email field equal to that of the partner1 created before.
The wizard is created with the reservation id and the two partners added to the
possible_existing_customer_ids field. The add_partner method of the wizard
is launched and it is verified that a Validation_Error was raised.
"""
# ARRANGE
partner1 = self.env["res.partner"].create(
{
"name": "Serafín Rivas",
"email": "serafin@example.com",
"mobile": "60595595",
}
)
partner2 = self.env["res.partner"].create(
{
"name": "Simon",
"mobile": "654667733",
"email": "simon@example.com",
}
)
checkin = fields.date.today()
checkout = fields.date.today() + datetime.timedelta(days=3)
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": partner1.name,
"email": partner1.email,
}
)
several_partners_wizard = self.env["pms.several.partners.wizard"].create(
{
"reservation_id": reservation.id,
"possible_existing_customer_ids": [(6, 0, [partner1.id, partner2.id])],
}
)
# ACT AND ASSERT
with self.assertRaises(
ValidationError,
msg="Two partners cannot be added to the reservation",
):
several_partners_wizard.add_partner()
def test_not_add_any_possibles_customers(self):
"""
Check that the possible_existing_customer_ids field of the several
partners wizard can be left empty and then launch the add_partner()
method of this wizard to add a partner in reservation.
---------------
A reservation is created. The wizard is created without the
possible_existing_customer_ids field. The add_partner method of
the wizard is launched and it is verified that a Validation_Error
was raised.
"""
# ARRANGE
checkin = fields.date.today()
checkout = fields.date.today() + datetime.timedelta(days=3)
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": "Rosa Costa",
}
)
several_partners_wizard = self.env["pms.several.partners.wizard"].create(
{
"reservation_id": reservation.id,
}
)
# ACT AND ASSERT
with self.assertRaises(
ValidationError,
msg="A partner must be added to the reservation",
):
several_partners_wizard.add_partner()

View File

@@ -1,4 +1,4 @@
from odoo import api, fields, models, _
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
@@ -16,26 +16,22 @@ class SeveralPartners(models.TransientModel):
)
checkin_partner_id = fields.Many2one(
string="Checkin Partner",
comodel_name="pms.checkin.partner"
string="Checkin Partner", comodel_name="pms.checkin.partner"
)
possible_existing_customer_ids = fields.Many2many(
string="Customers",
comodel_name="res.partner",
store=True,
readonly=False
string="Customers", comodel_name="res.partner", store=True, readonly=False
)
@api.model
def default_get(self, fields):
res = super(SeveralPartners, self).default_get(fields)
possibles_customers_ids = self.env["res.partner"].browse(self._context.get("possible_existing_customer_ids"))
res.update(
{
"possible_existing_customer_ids": possibles_customers_ids
}
possibles_customers_ids = self.env["res.partner"].browse(
self._context.get("possible_existing_customer_ids")
)
res.update({"possible_existing_customer_ids": possibles_customers_ids})
reservation = self.env["pms.reservation"].browse(
self._context.get("reservation_id")
)
reservation = self.env["pms.reservation"].browse(self._context.get("reservation_id"))
if reservation:
res.update(
{
@@ -49,7 +45,9 @@ class SeveralPartners(models.TransientModel):
"folio_id": folio.id,
}
)
checkin_partner = self.env["pms.checkin.partner"].browse(self._context.get("checkin_partner_id"))
checkin_partner = self.env["pms.checkin.partner"].browse(
self._context.get("checkin_partner_id")
)
if checkin_partner:
res.update(
{
@@ -61,12 +59,20 @@ class SeveralPartners(models.TransientModel):
def add_partner(self):
for record in self:
if len(record.possible_existing_customer_ids) == 0:
raise ValidationError(_("You must select a client to be able to add it to the reservation "))
raise ValidationError(
_(
"You must select a client to be able to add it to the reservation "
)
)
if len(record.possible_existing_customer_ids) > 1:
raise ValidationError(_("Only one customer can be added to the reservation"))
raise ValidationError(
_("Only one customer can be added to the reservation")
)
if record.reservation_id:
record.reservation_id.partner_id = record.possible_existing_customer_ids
elif record.folio_id:
record.folio_id.partner_id = record.possible_existing_customer_ids
elif record.checkin_partner_id:
record.checkin_partner_id.partner_id = record.possible_existing_customer_ids
record.checkin_partner_id.partner_id = (
record.possible_existing_customer_ids
)

View File

@@ -7,7 +7,7 @@
<form string="Possibles customers" colspan="4">
<h6> Choose a customer if you want to add it to the reservation</h6>
<group>
<field name="possible_existing_customer_ids"/>
<field name="possible_existing_customer_ids" />
</group>
<footer>
<button
@@ -25,7 +25,7 @@
<field name="name">Open Several Partners</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">pms.several.partners.wizard</field>
<field name="view_id" ref="several_partners_wizard"/>
<field name="view_id" ref="several_partners_wizard" />
<field name="view_mode">form</field>
<field name="target">new</field>
</record>