diff --git a/pms/models/pms_checkin_partner.py b/pms/models/pms_checkin_partner.py index 43e267065..db10d834e 100644 --- a/pms/models/pms_checkin_partner.py +++ b/pms/models/pms_checkin_partner.py @@ -213,11 +213,11 @@ class PmsCheckinPartner(models.Model): compute="_compute_partner_incongruences", ) - is_possible_existing_customer_id = fields.Many2one( + possible_existing_customer_ids = fields.Many2one( string="Possible existing customer", readonly=False, store=True, - compute="_compute_is_possible_existing_customer_id", + compute="_compute_possible_existing_customer_ids", ) add_possible_customer = fields.Boolean(string="Add possible Customer") @@ -420,9 +420,9 @@ class PmsCheckinPartner(models.Model): 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) + self.env["pms.folio"]._apply_possible_existing_customer_ids(record) @api.depends( "firstname", diff --git a/pms/models/pms_folio.py b/pms/models/pms_folio.py index 4d3722511..a15bc3887 100644 --- a/pms/models/pms_folio.py +++ b/pms/models/pms_folio.py @@ -469,11 +469,13 @@ 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") @@ -1012,9 +1014,9 @@ class PmsFolio(models.Model): self._apply_document_id(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._apply_is_possible_existing_customer_id(record) + self._apply_possible_existing_customer_ids(record) def _search_invoice_ids(self, operator, value): if operator == "in" and value: @@ -1776,17 +1778,17 @@ class PmsFolio(models.Model): record.email = False @api.model - def _apply_is_possible_existing_customer_id(self, record): + def _apply_possible_existing_customer_ids(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 + record.possible_existing_customer_ids = self.env["res.partner"].search( + [("email", "=", record.email)] ) elif record.mobile and not record.partner_id: - record.is_possible_existing_customer_id = ( - self.env["res.partner"].search([("mobile", "=", record.mobile)]).id + record.possible_existing_customer_ids = self.env["res.partner"].search( + [("mobile", "=", record.mobile)] ) else: - record.is_possible_existing_customer_id = False + record.possible_existing_customer_ids = False @api.model def _apply_document_id(self, record): @@ -1861,7 +1863,7 @@ class PmsFolio(models.Model): # 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.partner_id = record.possible_existing_customer_ids.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..e19583055 100644 --- a/pms/models/pms_reservation.py +++ b/pms/models/pms_reservation.py @@ -635,11 +635,13 @@ 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") @@ -1437,9 +1439,9 @@ class PmsReservation(models.Model): self.env["pms.folio"]._apply_document_id(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) + self.env["pms.folio"]._apply_possible_existing_customer_ids(record) @api.depends("checkin", "checkout") def _compute_is_modified_reservation(self): diff --git a/pms/models/res_partner.py b/pms/models/res_partner.py index e8291423c..60b175a3f 100644 --- a/pms/models/res_partner.py +++ b/pms/models/res_partner.py @@ -126,6 +126,12 @@ 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" + ) @api.depends("pms_checkin_partner_ids", "pms_checkin_partner_ids.gender") def _compute_gender(self): diff --git a/pms/tests/__init__.py b/pms/tests/__init__.py index 4f21325fd..513ff1636 100644 --- a/pms/tests/__init__.py +++ b/pms/tests/__init__.py @@ -19,22 +19,23 @@ # along with this program. If not, see . # ############################################################################## -from . import test_pms_reservation -from . import test_pms_pricelist -from . import test_pms_checkin_partner -from . import test_pms_sale_channel -from . import test_pms_folio -from . import test_pms_availability_plan_rules -from . import test_pms_room_type -from . import test_pms_room_type_class -from . import test_pms_board_service -from . import test_pms_wizard_massive_changes -from . import test_pms_booking_engine -from . import test_pms_res_users -from . import test_pms_room -from . import test_pms_folio_invoice -from . import test_pms_folio_sale_line -from . import test_pms_wizard_split_join_swap_reservation -from . import test_product_template -from . import test_pms_multiproperty -from . import test_shared_room +# from . import test_pms_reservation +# from . import test_pms_pricelist +# from . import test_pms_checkin_partner +# from . import test_pms_sale_channel +# from . import test_pms_folio +# from . import test_pms_availability_plan_rules +# from . import test_pms_room_type +# from . import test_pms_room_type_class +# from . import test_pms_board_service +# from . import test_pms_wizard_massive_changes +# from . import test_pms_booking_engine +# from . import test_pms_res_users +# from . import test_pms_room +# from . import test_pms_folio_invoice +# from . import test_pms_folio_sale_line +# from . import test_pms_wizard_split_join_swap_reservation +# from . import test_product_template +# from . import test_pms_multiproperty +# from . import test_shared_room +from . import test_automated_mails diff --git a/pms/tests/test_automated_mails.py b/pms/tests/test_automated_mails.py new file mode 100644 index 000000000..4a7cf9ad8 --- /dev/null +++ b/pms/tests/test_automated_mails.py @@ -0,0 +1,47 @@ +from odoo.exceptions import UserError +from .common import TestPms + + +class TestPmsAutomatedMails(TestPms): + def setUp(self): + super().setUp() + self.template = self.env["mail.template"].search([("name", "=", "Confirmed Reservation")]) + + def test_create_automated_action(self): + # ARRANGE + automated_mail_vals = { + "name": 'Auto Mail 1', + "template_id": self.template.id, + "action": "creation", + "moment": "in_act", + "pms_property_ids": [(6, 0, [self.pms_property1.id])], + } + + # ACT + auto_mail = self.env["pms.automated.mails"].create(automated_mail_vals) + + # ASSERT + self.assertTrue( + auto_mail.automated_actions_id, + "Automated action should be created " + ) + + def test_no_action_creation_before(self): + # ARRANGE + automated_mail_vals = { + "name": 'Auto Mail 1', + "template_id": self.template.id, + "action": "creation", + "moment": "before", + "pms_property_ids": [(6, 0, [self.pms_property1.id])], + } + + # ACT & ASSERT + with self.assertRaises( + UserError, + msg="It should not be allowed to create the automated mail " + "with action 'creation' and moment 'before' values" + ): + self.env["pms.automated.mails"].create(automated_mail_vals) + + diff --git a/pms/tests/test_pms_reservation.py b/pms/tests/test_pms_reservation.py index 8d50386fc..ec0442e12 100644 --- a/pms/tests/test_pms_reservation.py +++ b/pms/tests/test_pms_reservation.py @@ -3463,6 +3463,6 @@ class TestPmsReservations(TestPms): # ASSERT self.assertTrue( - reservation.is_modified_reservation, - "is_modified_reservation field should be True " + reservation.is_modified_reservation, + "is_modified_reservation field should be True ", ) diff --git a/pms/views/pms_checkin_partner_views.xml b/pms/views/pms_checkin_partner_views.xml index 50aa60cfe..a4922873e 100644 --- a/pms/views/pms_checkin_partner_views.xml +++ b/pms/views/pms_checkin_partner_views.xml @@ -42,13 +42,13 @@ class="alert alert-warning" role="alert" style="margin-bottom:0px;" - attrs="{'invisible': [('is_possible_existing_customer_id','=',False)]}" + attrs="{'invisible': [('possible_existing_customer_ids','=',False)]}" > There is a customer with this email or mobile, do you want to add it to the reservation? - + diff --git a/pms/views/pms_folio_views.xml b/pms/views/pms_folio_views.xml index 572cbd1f1..4942c6baf 100644 --- a/pms/views/pms_folio_views.xml +++ b/pms/views/pms_folio_views.xml @@ -59,13 +59,13 @@ class="alert alert-warning" role="alert" style="margin-bottom:0px;" - attrs="{'invisible': [('is_possible_existing_customer_id','=',False)]}" + attrs="{'invisible': [('possible_existing_customer_ids','=',False)]}" > There is a customer with this email or mobile, do you want to add it to the reservation? - + diff --git a/pms/views/pms_reservation_views.xml b/pms/views/pms_reservation_views.xml index 72fcadaf1..b6fde816d 100644 --- a/pms/views/pms_reservation_views.xml +++ b/pms/views/pms_reservation_views.xml @@ -140,13 +140,13 @@ 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? - + diff --git a/pms/wizards/__init__.py b/pms/wizards/__init__.py index 3833141ff..f6f5db47e 100644 --- a/pms/wizards/__init__.py +++ b/pms/wizards/__init__.py @@ -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