Merge PR #59 into 14.0

Signed-off-by DarioLodeiros
This commit is contained in:
OCA-git-bot
2021-09-16 15:36:59 +00:00
15 changed files with 702 additions and 119 deletions

View File

@@ -47,6 +47,7 @@
"wizards/folio_make_invoice_advance_views.xml",
"wizards/pms_booking_engine_views.xml",
"wizards/wizard_folio_changes.xml",
"wizards/wizard_several_partners.xml",
"views/pms_amenity_views.xml",
"views/pms_amenity_type_views.xml",
"views/pms_board_service_views.xml",

View File

@@ -213,15 +213,15 @@ class PmsCheckinPartner(models.Model):
compute="_compute_partner_incongruences",
)
is_possible_existing_customer_id = fields.Many2one(
possible_existing_customer_ids = fields.One2many(
string="Possible existing customer",
readonly=False,
store=True,
compute="_compute_is_possible_existing_customer_id",
compute="_compute_possible_existing_customer_ids",
comodel_name="res.partner",
inverse_name="checkin_partner_possible_customer_id",
)
add_possible_customer = fields.Boolean(string="Add possible Customer")
@api.depends("partner_id")
def _compute_document_number(self):
for record in self:
@@ -389,7 +389,6 @@ class PmsCheckinPartner(models.Model):
"firstname",
"lastname",
"lastname2",
"add_possible_customer",
)
def _compute_partner_id(self):
for record in self:
@@ -416,13 +415,17 @@ 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):
def _compute_possible_existing_customer_ids(self):
for record in self:
self.env["pms.folio"]._apply_is_possible_existing_customer_id(record)
possible_customer = self.env[
"pms.folio"
]._apply_possible_existing_customer_ids(record.email, record.mobile)
if possible_customer:
record.possible_existing_customer_ids = possible_customer
else:
record.possible_existing_customer_ids = False
@api.depends(
"firstname",
@@ -686,3 +689,18 @@ class PmsCheckinPartner(models.Model):
"target": "new",
"flags": {"form": {"action_buttons": True}},
}
def open_wizard_several_partners(self):
ctx = dict(
checkin_partner_id=self.id,
possible_existing_customer_ids=self.possible_existing_customer_ids.ids,
)
return {
"view_type": "form",
"view_mode": "form",
"name": "Several Customers",
"res_model": "pms.several.partners.wizard",
"target": "new",
"type": "ir.actions.act_window",
"context": ctx,
}

View File

@@ -469,15 +469,15 @@ class PmsFolio(models.Model):
ondelete="restrict",
)
is_possible_existing_customer_id = fields.Many2one(
possible_existing_customer_ids = fields.One2many(
string="Possible existing customer",
readonly=False,
store=True,
compute="_compute_is_possible_existing_customer_id",
compute="_compute_possible_existing_customer_ids",
comodel_name="res.partner",
inverse_name="folio_possible_customer_id",
)
add_possible_customer = fields.Boolean(string="Add possible Customer")
def name_get(self):
result = []
for folio in self:
@@ -676,7 +676,6 @@ class PmsFolio(models.Model):
"reservation_type",
"document_number",
"document_type",
"add_possible_customer",
"partner_name",
"email",
"mobile",
@@ -689,8 +688,6 @@ class PmsFolio(models.Model):
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
@@ -1011,10 +1008,17 @@ class PmsFolio(models.Model):
for record in self:
self._apply_document_id(record)
@api.depends("email", "mobile")
def _compute_is_possible_existing_customer_id(self):
@api.depends("email", "mobile", "partner_name")
def _compute_possible_existing_customer_ids(self):
for record in self:
self._apply_is_possible_existing_customer_id(record)
if record.partner_name:
possible_customer = self._apply_possible_existing_customer_ids(
record.email, record.mobile, record.partner_id
)
if possible_customer:
record.possible_existing_customer_ids = possible_customer
else:
record.possible_existing_customer_ids = False
def _search_invoice_ids(self, operator, value):
if operator == "in" and value:
@@ -1473,6 +1477,21 @@ class PmsFolio(models.Model):
)
self.env["account.bank.statement.line"].sudo().create(line)
def open_wizard_several_partners(self):
ctx = dict(
folio_id=self.id,
possible_existing_customer_ids=self.possible_existing_customer_ids.ids,
)
return {
"view_type": "form",
"view_mode": "form",
"name": "Several Customers",
"res_model": "pms.several.partners.wizard",
"target": "new",
"type": "ir.actions.act_window",
"context": ctx,
}
@api.model
def _get_statement_line_vals(
self,
@@ -1748,7 +1767,7 @@ class PmsFolio(models.Model):
@api.model
def _apply_partner_name(self, record):
if record.partner_id and not record.partner_name:
if record.partner_id:
record.partner_name = record.partner_id.name
elif (
record.agency_id
@@ -1776,17 +1795,17 @@ class PmsFolio(models.Model):
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
def _apply_possible_existing_customer_ids(
self, email=False, mobile=False, partner=False
):
possible_customer = False
if email and not partner:
possible_customer = self.env["res.partner"].search([("email", "=", email)])
if mobile and not partner:
possible_customer = self.env["res.partner"].search(
[("mobile", "=", mobile)]
)
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
return possible_customer
@api.model
def _apply_document_id(self, record):
@@ -1855,13 +1874,3 @@ class PmsFolio(models.Model):
}
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()

View File

@@ -635,15 +635,15 @@ class PmsReservation(models.Model):
ondelete="restrict",
)
is_possible_existing_customer_id = fields.Many2one(
possible_existing_customer_ids = fields.One2many(
string="Possible existing customer",
readonly=False,
store=True,
compute="_compute_is_possible_existing_customer_id",
compute="_compute_possible_existing_customer_ids",
comodel_name="res.partner",
inverse_name="reservation_possible_customer_id",
)
add_possible_customer = fields.Boolean(string="Add possible Customer")
is_mail_send = fields.Boolean(string="Mail Sent", default=False)
is_modified_reservation = fields.Boolean(
@@ -838,7 +838,6 @@ class PmsReservation(models.Model):
"partner_name",
"email",
"mobile",
"add_possible_customer",
)
def _compute_partner_id(self):
for reservation in self:
@@ -851,8 +850,6 @@ class PmsReservation(models.Model):
reservation.partner_id = 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
@@ -1340,7 +1337,7 @@ class PmsReservation(models.Model):
else:
record.partner_name = record.out_service_description
@api.depends("partner_id", "partner_id.email", "agency_id", "add_possible_customer")
@api.depends("partner_id", "partner_id.email", "agency_id")
def _compute_email(self):
for record in self:
self.env["pms.folio"]._apply_email(record)
@@ -1436,10 +1433,21 @@ class PmsReservation(models.Model):
for record in self:
self.env["pms.folio"]._apply_document_id(record)
@api.depends("email", "mobile")
def _compute_is_possible_existing_customer_id(self):
@api.depends("email", "mobile", "partner_name")
def _compute_possible_existing_customer_ids(self):
for record in self:
self.env["pms.folio"]._apply_is_possible_existing_customer_id(record)
if record.partner_name:
possible_customer = self.env[
"pms.folio"
]._apply_possible_existing_customer_ids(
record.email, record.mobile, record.partner_id
)
if possible_customer:
record.possible_existing_customer_ids = possible_customer
else:
record.possible_existing_customer_ids = False
else:
record.possible_existing_customer_ids = False
@api.depends("checkin", "checkout")
def _compute_is_modified_reservation(self):
@@ -1746,6 +1754,21 @@ class PmsReservation(models.Model):
"context": ctx,
}
def open_wizard_several_partners(self):
ctx = dict(
reservation_id=self.id,
possible_existing_customer_ids=self.possible_existing_customer_ids.ids,
)
return {
"view_type": "form",
"view_mode": "form",
"name": "Several Customers",
"res_model": "pms.several.partners.wizard",
"target": "new",
"type": "ir.actions.act_window",
"context": ctx,
}
@api.model
def name_search(self, name="", args=None, operator="ilike", limit=100):
if args is None:

View File

@@ -126,6 +126,16 @@ class ResPartner(models.Model):
comment = fields.Text(
tracking=True,
)
reservation_possible_customer_id = fields.Many2one(
string="Possible Customer In Reservation", comodel_name="pms.reservation"
)
folio_possible_customer_id = fields.Many2one(
string="Possible Customer In Folio", comodel_name="pms.folio"
)
checkin_partner_possible_customer_id = fields.Many2one(
string="Possible Customer In Checkin Partner",
comodel_name="pms.checkin.partner",
)
@api.depends("pms_checkin_partner_ids", "pms_checkin_partner_ids.gender")
def _compute_gender(self):

View File

@@ -61,3 +61,4 @@ user_access_wizard_folio_changes,user_access_wizard_folio_changes,model_wizard_f
user_access_pms_folio_portal,user_access_pms_folio_portal,model_pms_folio,base.group_portal,1,0,0,0
user_access_pms_reservation_portal,user_access_pms_reservation_portal,model_pms_reservation,base.group_portal,1,0,0,0
user_access_pms_automated_mails,user_access_pms_automated_mails,model_pms_automated_mails,pms.group_pms_user,1,1,1,1
access_pms_several_partners_wizard,access_pms_several_partners_wizard,model_pms_several_partners_wizard,base.group_user,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
61 user_access_pms_folio_portal user_access_pms_folio_portal model_pms_folio base.group_portal 1 0 0 0
62 user_access_pms_reservation_portal user_access_pms_reservation_portal model_pms_reservation base.group_portal 1 0 0 0
63 user_access_pms_automated_mails user_access_pms_automated_mails model_pms_automated_mails pms.group_pms_user 1 1 1 1
64 access_pms_several_partners_wizard access_pms_several_partners_wizard model_pms_several_partners_wizard base.group_user 1 1 1 1

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,95 @@ 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

@@ -42,13 +42,14 @@
class="alert alert-warning"
role="alert"
style="margin-bottom:0px;"
attrs="{'invisible': [('is_possible_existing_customer_id','=',False)]}"
attrs="{'invisible': [('possible_existing_customer_ids','=',[])]}"
>
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)]}"
A customer/s has this email or mobile, do you want to add it?
<field name="possible_existing_customer_ids" invisible="1" />
<button
name="open_wizard_several_partners"
string="Add customer"
type="object"
/>
</div>
<group name="group_top">

View File

@@ -59,13 +59,14 @@
class="alert alert-warning"
role="alert"
style="margin-bottom:0px;"
attrs="{'invisible': [('is_possible_existing_customer_id','=',False)]}"
attrs="{'invisible': [('possible_existing_customer_ids','=',[])]}"
>
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)]}"
A customer/s has this email or mobile, do you want to add it?
<field name="possible_existing_customer_ids" invisible="1" />
<button
name="open_wizard_several_partners"
string="Add customer"
type="object"
/>
</div>
<sheet>

View File

@@ -140,13 +140,14 @@
class="alert alert-warning"
role="alert"
style="margin-bottom:0px;"
attrs="{'invisible': [('is_possible_existing_customer_id','=',[])]}"
attrs="{'invisible': [('possible_existing_customer_ids','=',[])]}"
>
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)]}"
A customer/s has this email or mobile, do you want to add it?
<field name="possible_existing_customer_ids" invisible="1" />
<button
name="open_wizard_several_partners"
string="Add customer"
type="object"
/>
</div>
<sheet>

View File

@@ -5,3 +5,4 @@ from . import pms_booking_engine
from . import folio_make_invoice_advance
from . import wizard_payment_folio
from . import wizard_folio_changes
from . import wizard_several_partners

View File

@@ -0,0 +1,78 @@
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
class SeveralPartners(models.TransientModel):
_name = "pms.several.partners.wizard"
reservation_id = fields.Many2one(
string="Reservation",
comodel_name="pms.reservation",
)
folio_id = fields.Many2one(
string="Folio",
comodel_name="pms.folio",
)
checkin_partner_id = fields.Many2one(
string="Checkin Partner", comodel_name="pms.checkin.partner"
)
possible_existing_customer_ids = fields.Many2many(
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})
reservation = self.env["pms.reservation"].browse(
self._context.get("reservation_id")
)
if reservation:
res.update(
{
"reservation_id": reservation.id,
}
)
folio = self.env["pms.folio"].browse(self._context.get("folio_id"))
if folio:
res.update(
{
"folio_id": folio.id,
}
)
checkin_partner = self.env["pms.checkin.partner"].browse(
self._context.get("checkin_partner_id")
)
if checkin_partner:
res.update(
{
"checkin_partner_id": checkin_partner.id,
}
)
return res
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 "
)
)
if len(record.possible_existing_customer_ids) > 1:
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
)

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="several_partners_wizard" model="ir.ui.view">
<field name="name">Several Partners</field>
<field name="model">pms.several.partners.wizard</field>
<field name="arch" type="xml">
<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" />
</group>
<footer>
<button
type="object"
class="btn-primary"
name="add_partner"
string="Add Customer"
/>
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
<record id="action_open_several_partners_wizard" model="ir.actions.act_window">
<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_mode">form</field>
<field name="target">new</field>
</record>
</odoo>