diff --git a/pms/__manifest__.py b/pms/__manifest__.py index 7ff82bd38..9bbbd5b1b 100644 --- a/pms/__manifest__.py +++ b/pms/__manifest__.py @@ -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", diff --git a/pms/models/pms_checkin_partner.py b/pms/models/pms_checkin_partner.py index 43e267065..dcacd85a9 100644 --- a/pms/models/pms_checkin_partner.py +++ b/pms/models/pms_checkin_partner.py @@ -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, + } diff --git a/pms/models/pms_folio.py b/pms/models/pms_folio.py index 4d3722511..6e2bb6c5a 100644 --- a/pms/models/pms_folio.py +++ b/pms/models/pms_folio.py @@ -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() diff --git a/pms/models/pms_reservation.py b/pms/models/pms_reservation.py index 3e0715b33..8b7b15701 100644 --- a/pms/models/pms_reservation.py +++ b/pms/models/pms_reservation.py @@ -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: diff --git a/pms/models/res_partner.py b/pms/models/res_partner.py index e8291423c..8e640e2e9 100644 --- a/pms/models/res_partner.py +++ b/pms/models/res_partner.py @@ -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): diff --git a/pms/security/ir.model.access.csv b/pms/security/ir.model.access.csv index f536bb9a2..4897a7e30 100644 --- a/pms/security/ir.model.access.csv +++ b/pms/security/ir.model.access.csv @@ -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 diff --git a/pms/tests/test_pms_checkin_partner.py b/pms/tests/test_pms_checkin_partner.py index 713c56894..6d08a1437 100644 --- a/pms/tests/test_pms_checkin_partner.py +++ b/pms/tests/test_pms_checkin_partner.py @@ -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() diff --git a/pms/tests/test_pms_folio.py b/pms/tests/test_pms_folio.py index 600e92cf9..910e62095 100644 --- a/pms/tests/test_pms_folio.py +++ b/pms/tests/test_pms_folio.py @@ -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() diff --git a/pms/tests/test_pms_reservation.py b/pms/tests/test_pms_reservation.py index c7c48f119..35c729cee 100644 --- a/pms/tests/test_pms_reservation.py +++ b/pms/tests/test_pms_reservation.py @@ -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() diff --git a/pms/views/pms_checkin_partner_views.xml b/pms/views/pms_checkin_partner_views.xml index 50aa60cfe..d1e72b911 100644 --- a/pms/views/pms_checkin_partner_views.xml +++ b/pms/views/pms_checkin_partner_views.xml @@ -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? - - +