From 4f738141a4024b2144f3f7e0e4b861b24847c74d Mon Sep 17 00:00:00 2001 From: Sara Lago Date: Fri, 18 Mar 2022 15:34:21 +0100 Subject: [PATCH 01/23] [IMP] pms: add multiple sale channel in pms_folio, pms_reservation and pms_reservation_line --- pms/models/pms_folio.py | 81 ++++++++++++----- pms/models/pms_reservation.py | 134 +++++++++++++++++++++++++--- pms/models/pms_reservation_line.py | 10 +++ pms/views/pms_folio_views.xml | 32 ++++--- pms/views/pms_reservation_views.xml | 50 ++++++----- 5 files changed, 242 insertions(+), 65 deletions(-) diff --git a/pms/models/pms_folio.py b/pms/models/pms_folio.py index 5ec54f9c0..d7949ffa2 100644 --- a/pms/models/pms_folio.py +++ b/pms/models/pms_folio.py @@ -204,17 +204,32 @@ class PmsFolio(models.Model): ondelete="restrict", check_pms_properties=True, ) - channel_type_id = fields.Many2one( - string="Direct Sale Channel", - help="Only allowed if the field of sale channel channel_type is 'direct'", - readonly=False, + # channel_type_id = fields.Many2one( + # string="Direct Sale Channel", + # help="Only allowed if the field of sale channel channel_type is 'direct'", + # readonly=False, + # store=True, + # comodel_name="pms.sale.channel", + # domain=[("channel_type", "=", "direct")], + # ondelete="restrict", + # compute="_compute_channel_type_id", + # check_pms_properties=True, + # ) + sale_channel_ids = fields.Many2many( + string="Sale Channels", + help="Sale Channels through which reservations were managed", store=True, + compute="_compute_sale_channel_ids", comodel_name="pms.sale.channel", - domain=[("channel_type", "=", "direct")], - ondelete="restrict", - compute="_compute_channel_type_id", - check_pms_properties=True, ) + sale_channel_origin_id = fields.Many2one( + string="Sale Channel Origin", + help="Sale Channel through which folio was created, the original", + comodel_name="pms.sale.channel", + store=True, + compute="_compute_sale_channel_origin_id", + ) + transaction_ids = fields.Many2many( string="Transactions", help="Payments made through payment acquirer", @@ -1049,10 +1064,17 @@ class PmsFolio(models.Model): folio.commission = folio.commission + reservation.commission_amount @api.depends("agency_id") - def _compute_channel_type_id(self): + def _compute_sale_channel_origin_id(self): for folio in self: if folio.agency_id: - folio.channel_type_id = folio.agency_id.sale_channel_id.id + folio.sale_channel_origin_id = folio.agency_id.sale_channel_id.id + + @api.depends("reservation_ids", "reservation_ids.sale_channel_ids") + def _compute_sale_channel_ids(self): + for record in self: + record.sale_channel_ids = [ + (6, 0, record.mapped("reservation_ids.sale_channel_origin_id.id")) + ] @api.depends("sale_line_ids.invoice_lines") def _compute_get_invoiced(self): @@ -1491,17 +1513,17 @@ class PmsFolio(models.Model): ("sale_line_ids.invoice_lines.move_id", operator, value), ] - @api.constrains("agency_id", "channel_type_id") - def _check_only_one_channel(self): - for record in self: - if ( - record.agency_id - and record.channel_type_id.channel_type - != record.agency_id.sale_channel_id.channel_type - ): - raise models.ValidationError( - _("The Sale Channel does not correspond to the agency's") - ) + # @api.constrains("agency_id", "channel_type_id") + # def _check_only_one_channel(self): + # for record in self: + # if ( + # record.agency_id + # and record.channel_type_id.channel_type + # != record.agency_id.sale_channel_id.channel_type + # ): + # raise models.ValidationError( + # _("The Sale Channel does not correspond to the agency's") + # ) @api.constrains("name") def _check_required_partner_name(self): @@ -1523,6 +1545,23 @@ class PmsFolio(models.Model): result.access_token = result._portal_ensure_token() return result + def write(self, vals): + reservations_to_update = self.env["pms.reservation"] + if "sale_channel_origin_id" in vals: + for record in self: + for reservation in record.reservation_ids: + if ( + reservation.sale_channel_origin_id + == self.sale_channel_origin_id + ): + reservations_to_update += reservation + res = super(PmsFolio, self).write(vals) + if reservations_to_update: + reservations_to_update.sale_channel_origin_id = vals[ + "sale_channel_origin_id" + ] + return res + def action_pay(self): self.ensure_one() self.ensure_one() diff --git a/pms/models/pms_reservation.py b/pms/models/pms_reservation.py index 94ee17dd0..ade2a0447 100644 --- a/pms/models/pms_reservation.py +++ b/pms/models/pms_reservation.py @@ -124,13 +124,37 @@ class PmsReservation(models.Model): depends=["folio_id.agency_id"], tracking=True, ) - channel_type_id = fields.Many2one( - string="Channel Type", - help="Sales Channel through which the reservation was managed", - readonly=False, + sale_channel_ids = fields.Many2many( + string="Sale Channels", + help="Sale Channels through which reservation lines were managed", store=True, - related="folio_id.channel_type_id", - tracking=True, + compute="_compute_sale_channel_ids", + comodel_name="pms.sale.channel", + ) + sale_channel_origin_id = fields.Many2one( + string="Sale Channel Origin", + help="Sale Channel through which reservation was created, the original", + store=True, + readonly=False, + compute="_compute_sale_channel_origin_id", + default=lambda self: self._get_default_sale_channel_origin(), + comodel_name="pms.sale.channel", + ) + force_update_origin = fields.Boolean( + string="Update Sale Channel Origin", + help="This field is for force update in sale channel " + "origin of folio and another reservations", + store=True, + readonly=False, + compute="_compute_force_update_origin", + ) + is_origin_channel_check_visible = fields.Boolean( + string="Update Sale Channel Origin", + help="This field is for force update in sale channel " + "origin of folio and another reservations", + store=True, + readonly=False, + compute="_compute_is_origin_channel_check_visible", ) closure_reason_id = fields.Many2one( string="Closure Reason", @@ -1608,6 +1632,38 @@ class PmsReservation(models.Model): else: record.lang = self.env["res.lang"].get_installed() + + @api.depends("reservation_line_ids", "reservation_line_ids.sale_channel_id") + def _compute_sale_channel_ids(self): + for record in self: + record.sale_channel_ids = [ + (6, 0, record.mapped("reservation_line_ids.sale_channel_id.id")) + ] + + @api.depends("agency_id") + def _compute_sale_channel_origin_id(self): + for record in self: + # if record.folio_id.sale_channel_origin_id and not record.sale_channel_origin_id: + # record.sale_channel_origin_id = record.folio_id.sale_channel_origin_id + if record.agency_id: + record.sale_channel_origin_id = record.agency_id.sale_channel_id + + @api.depends("sale_channel_origin_id") + def _compute_is_origin_channel_check_visible(self): + for record in self: + if ( + record.sale_channel_origin_id != record.folio_id.sale_channel_origin_id + and record.folio_id + ): + record.is_origin_channel_check_visible = True + else: + record.is_origin_channel_check_visible = False + + @api.depends("sale_channel_origin_id") + def _compute_force_update_origin(self): + for record in self: + record.force_update_origin = True + def _search_allowed_checkin(self, operator, value): if operator not in ("=",): raise UserError( @@ -1674,6 +1730,17 @@ class PmsReservation(models.Model): segmentation_ids = folio.segmentation_ids return segmentation_ids + def _get_default_sale_channel_origin(self): + folio = False + sale_channel_origin_id = False + if "default_folio_id" in self._context: + folio = self.env["pms.folio"].search( + [("id", "=", self._context["default_folio_id"])] + ) + if folio and folio.sale_channel_origin_id: + sale_channel_origin_id = folio.sale_channel_origin_id + return sale_channel_origin_id + def check_in_out_dates(self): """ 1.-When date_order is less then checkin date or @@ -1943,12 +2010,18 @@ class PmsReservation(models.Model): elif vals.get("reservation_type") != "out": raise ValidationError(_("Partner contact name is required")) vals.update(default_vals) - elif "pms_property_id" in vals and ( - "partner_name" in vals or "partner_id" in vals or "agency_id" in vals + elif ( + "pms_property_id" in vals + and ("sale_channel_origin_id" in vals or "agency_id" in vals) + and ("partner_name" in vals or "partner_id" in vals or "agency_id" in vals) ): folio_vals = { "pms_property_id": vals["pms_property_id"], } + if vals.get("sale_channel_origin_id"): + folio_vals["sale_channel_origin_id"] = vals.get( + "sale_channel_origin_id" + ) if vals.get("partner_id"): folio_vals["partner_id"] = vals.get("partner_id") elif vals.get("agency_id"): @@ -1981,7 +2054,11 @@ class PmsReservation(models.Model): ) else: - raise ValidationError(_("The Property are mandatory in the reservation")) + raise ValidationError( + _( + "The Property and Sale Channel Origin are mandatory in the reservation" + ) + ) if vals.get("name", _("New")) == _("New") or "name" not in vals: folio_sequence = ( max(folio.mapped("reservation_ids.folio_sequence")) + 1 @@ -2004,13 +2081,24 @@ class PmsReservation(models.Model): return record def write(self, vals): - asset = super(PmsReservation, self).write(vals) + folios_to_update_channel = self.env["pms.folio"] + lines_to_update_channel = self.env["pms.reservation.line"] + if "sale_channel_origin_id" in vals: + folios_to_update_channel = self.get_folios_to_update_channel(vals) + lines_to_update_channel = self.get_lines_to_update_channel(vals) + res = super(PmsReservation, self).write(vals) + if folios_to_update_channel: + folios_to_update_channel.sale_channel_origin_id = vals[ + "sale_channel_origin_id" + ] + if lines_to_update_channel: + lines_to_update_channel.sale_channel_id = vals["sale_channel_origin_id"] self._check_services(vals) # Only check if adult to avoid to check capacity in intermediate states (p.e. flush) # that not take access to possible extra beds service in vals if "adults" in vals: self._check_capacity() - return asset + return res def _check_services(self, vals): # If we create a reservation with board service and other service at the same time, @@ -2019,6 +2107,30 @@ class PmsReservation(models.Model): if "board_service_room_id" in vals and "service_ids" in vals: self._compute_service_ids() + def get_folios_to_update_channel(self, vals): + folios_to_update_channel = self.env["pms.folio"] + for folio in self.mapped("folio_id"): + if ( + any( + res.sale_channel_origin_id == folio.sale_channel_origin_id + for res in self.filtered(lambda r: r.folio_id == folio) + ) + and vals["sale_channel_origin_id"] != folio.sale_channel_origin_id.id + and ("force_update_origin" in vals and vals.get("force_update_origin")) + ): + folios_to_update_channel += folio + return folios_to_update_channel + + def get_lines_to_update_channel(self, vals): + lines_to_update_channel = self.env["pms.reservation.line"] + for record in self: + for line in record.reservation_line_ids: + if line.sale_channel_id == record.sale_channel_origin_id and ( + vals["sale_channel_origin_id"] != line.sale_channel_id.id + ): + lines_to_update_channel += line + return lines_to_update_channel + def update_prices(self): self.ensure_one() for line in self.reservation_line_ids: diff --git a/pms/models/pms_reservation_line.py b/pms/models/pms_reservation_line.py index aa64e0d1b..367c95fcf 100644 --- a/pms/models/pms_reservation_line.py +++ b/pms/models/pms_reservation_line.py @@ -112,6 +112,12 @@ class PmsReservationLine(models.Model): store=True, readonly=False, compute="_compute_overbooking", + sale_channel_id = fields.Many2one( + string="Sale Channel", + help="Sale Channel through which reservation line was created", + comodel_name="pms.sale.channel", + ondelete="restrict", + check_pms_properties=True, ) _sql_constraints = [ ( @@ -483,6 +489,10 @@ class PmsReservationLine(models.Model): records = super().create(vals_list) for line in records: reservation = line.reservation_id + # Set default channel + if not line.sale_channel_id: + line.sale_channel_id = reservation.sale_channel_origin_id.id + # Update quota self.env["pms.availability.plan"].update_quota( pricelist_id=reservation.pricelist_id.id, room_type_id=reservation.room_type_id.id, diff --git a/pms/views/pms_folio_views.xml b/pms/views/pms_folio_views.xml index c835bdda5..72a5bd734 100644 --- a/pms/views/pms_folio_views.xml +++ b/pms/views/pms_folio_views.xml @@ -348,10 +348,16 @@ name="agency_id" attrs="{'invisible': [('reservation_type', 'not in', 'normal')]}" /> + + - + + + + + + - + + + + + + + diff --git a/pms/views/pms_reservation_views.xml b/pms/views/pms_reservation_views.xml index b77a394fa..ce3db2d6b 100644 --- a/pms/views/pms_reservation_views.xml +++ b/pms/views/pms_reservation_views.xml @@ -441,17 +441,25 @@ options="{'no_create': True,'no_open': True}" attrs="{'invisible': [('reservation_type','in',('out'))]}" /> - + + + + @@ -491,6 +499,7 @@ name="cancel_discount" attrs="{'column_invisible': [('parent.state','!=','cancel')]}" /> + @@ -786,7 +795,8 @@ - + + @@ -1014,12 +1024,12 @@ name="agency" context="{'group_by':'agency_id'}" /> - + + + + + + - + + + + + + + From 4be7a309a5ef8c7d9025ba9e5b61f35bc6278957 Mon Sep 17 00:00:00 2001 From: Sara Lago Date: Tue, 22 Mar 2022 12:24:07 +0100 Subject: [PATCH 02/23] [IMP] pms: add required sale_channel_origin in the already created tests --- pms/models/pms_reservation.py | 2 +- pms/models/pms_reservation_line.py | 1 + pms/tests/test_pms_availability_plan_rules.py | 13 +- pms/tests/test_pms_checkin_partner.py | 13 ++ pms/tests/test_pms_folio.py | 13 ++ pms/tests/test_pms_folio_invoice.py | 24 +++ pms/tests/test_pms_folio_sale_line.py | 34 ++++ pms/tests/test_pms_multiproperty.py | 7 + pms/tests/test_pms_pricelist.py | 22 +++ pms/tests/test_pms_reservation.py | 155 +++++++++--------- pms/tests/test_pms_sale_channel.py | 60 ------- ..._pms_wizard_split_join_swap_reservation.py | 41 +++++ pms/tests/test_product_template.py | 13 ++ pms/tests/test_shared_room.py | 22 +++ pms/wizards/pms_booking_engine.py | 2 +- 15 files changed, 284 insertions(+), 138 deletions(-) diff --git a/pms/models/pms_reservation.py b/pms/models/pms_reservation.py index ade2a0447..0c03053f6 100644 --- a/pms/models/pms_reservation.py +++ b/pms/models/pms_reservation.py @@ -2085,7 +2085,7 @@ class PmsReservation(models.Model): lines_to_update_channel = self.env["pms.reservation.line"] if "sale_channel_origin_id" in vals: folios_to_update_channel = self.get_folios_to_update_channel(vals) - lines_to_update_channel = self.get_lines_to_update_channel(vals) + lines_to_update_channel = self.get_lines_to_update_channel(vals) res = super(PmsReservation, self).write(vals) if folios_to_update_channel: folios_to_update_channel.sale_channel_origin_id = vals[ diff --git a/pms/models/pms_reservation_line.py b/pms/models/pms_reservation_line.py index 367c95fcf..0b547b6cd 100644 --- a/pms/models/pms_reservation_line.py +++ b/pms/models/pms_reservation_line.py @@ -112,6 +112,7 @@ class PmsReservationLine(models.Model): store=True, readonly=False, compute="_compute_overbooking", + ) sale_channel_id = fields.Many2one( string="Sale Channel", help="Sale Channel through which reservation line was created", diff --git a/pms/tests/test_pms_availability_plan_rules.py b/pms/tests/test_pms_availability_plan_rules.py index 3bb5c2c62..58fc94ab6 100644 --- a/pms/tests/test_pms_availability_plan_rules.py +++ b/pms/tests/test_pms_availability_plan_rules.py @@ -25,7 +25,13 @@ class TestPmsRoomTypeAvailabilityRules(TestPms): ], } ) - + # pms.sale.channel + self.sale_channel_direct1 = self.env["pms.sale.channel"].create( + { + "name": "Door", + "channel_type": "direct", + } + ) # pms.availability.plan self.test_room_type_availability1 = self.env["pms.availability.plan"].create( { @@ -164,6 +170,7 @@ class TestPmsRoomTypeAvailabilityRules(TestPms): "checkout": checkout, "partner_id": self.partner1.id, "room_type_id": room_type.id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) result = self.test_room_type_availability_rule1.plan_avail @@ -209,6 +216,7 @@ class TestPmsRoomTypeAvailabilityRules(TestPms): "checkout": checkout, "partner_id": self.partner1.id, "room_type_id": room_type.id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) self.env["pms.reservation"].create( @@ -218,6 +226,7 @@ class TestPmsRoomTypeAvailabilityRules(TestPms): "checkout": checkout, "partner_id": self.partner1.id, "room_type_id": room_type.id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) result = self.test_room_type_availability_rule1.plan_avail @@ -258,6 +267,7 @@ class TestPmsRoomTypeAvailabilityRules(TestPms): "checkin": checkin, "checkout": checkout, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -586,6 +596,7 @@ class TestPmsRoomTypeAvailabilityRules(TestPms): "room_type_id": self.test_room_type_double.id, "pricelist_id": self.pricelist2.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r1.flush() diff --git a/pms/tests/test_pms_checkin_partner.py b/pms/tests/test_pms_checkin_partner.py index 1db2b4ac1..cc0e9d414 100644 --- a/pms/tests/test_pms_checkin_partner.py +++ b/pms/tests/test_pms_checkin_partner.py @@ -68,6 +68,12 @@ class TestPmsCheckinPartner(TestPms): "partner_id": self.host1.id, } ) + self.sale_channel_direct1 = self.env["pms.sale.channel"].create( + { + "name": "Door", + "channel_type": "direct", + } + ) reservation_vals = { "checkin": datetime.date.today(), "checkout": datetime.date.today() + datetime.timedelta(days=3), @@ -75,6 +81,7 @@ class TestPmsCheckinPartner(TestPms): "partner_id": self.host1.id, "adults": 3, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } self.reservation_1 = self.env["pms.reservation"].create(reservation_vals) self.checkin1 = self.env["pms.checkin.partner"].create( @@ -1091,6 +1098,7 @@ class TestPmsCheckinPartner(TestPms): "pms_property_id": self.pms_property1.id, "partner_name": partner.name, "email": partner.email, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) # ACT @@ -1133,6 +1141,7 @@ class TestPmsCheckinPartner(TestPms): "room_type_id": self.room_type1.id, "pms_property_id": self.pms_property1.id, "partner_name": partner.name, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) # ACT @@ -1178,6 +1187,7 @@ class TestPmsCheckinPartner(TestPms): "room_type_id": self.room_type1.id, "pms_property_id": self.pms_property1.id, "partner_name": partner.name, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) checkin = self.env["pms.checkin.partner"].create( @@ -1239,6 +1249,7 @@ class TestPmsCheckinPartner(TestPms): "room_type_id": self.room_type1.id, "pms_property_id": self.pms_property1.id, "partner_name": partner1.name, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) @@ -1286,6 +1297,7 @@ class TestPmsCheckinPartner(TestPms): "room_type_id": self.room_type1.id, "pms_property_id": self.pms_property1.id, "partner_name": "Rosa Costa", + "sale_channel_origin_id": self.sale_channel_direct1.id } ) checkin = self.env["pms.checkin.partner"].create( @@ -1539,6 +1551,7 @@ class TestPmsCheckinPartner(TestPms): "partner_id": self.host1.id, "adults": 1, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) checkin_partner_id = self.reservation.checkin_partner_ids[0] diff --git a/pms/tests/test_pms_folio.py b/pms/tests/test_pms_folio.py index 52704bfc8..ba72a4c4a 100644 --- a/pms/tests/test_pms_folio.py +++ b/pms/tests/test_pms_folio.py @@ -55,6 +55,15 @@ class TestPmsFolio(TestPms): ) journals.allowed_pms_payments = True + # create sale channel direct + self.sale_channel_direct1 = self.env["pms.sale.channel"].create( + { + "name": "Door", + "channel_type": "direct", + } + ) + + def create_sale_channel_scenario(self): """ Method to simplified scenario on sale channel tests: @@ -410,6 +419,7 @@ class TestPmsFolio(TestPms): "adults": 2, "partner_id": self.env.ref("base.res_partner_12").id, "room_type_id": self.demo_room_type_double.id, + "sale_channel_origin_id":self.sale_channel_direct1.id, } ) @@ -456,6 +466,7 @@ class TestPmsFolio(TestPms): "adults": 2, "partner_id": self.env.ref("base.res_partner_12").id, "room_type_id": self.demo_room_type_double.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) @@ -542,6 +553,7 @@ class TestPmsFolio(TestPms): "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist1.id, "reservation_type": "staff", + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) # ASSERT @@ -582,6 +594,7 @@ class TestPmsFolio(TestPms): "pricelist_id": self.pricelist1.id, "reservation_type": "out", "closure_reason_id": closure_reason.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) # ASSERT diff --git a/pms/tests/test_pms_folio_invoice.py b/pms/tests/test_pms_folio_invoice.py index c5d509a7e..1db34077f 100644 --- a/pms/tests/test_pms_folio_invoice.py +++ b/pms/tests/test_pms_folio_invoice.py @@ -135,6 +135,14 @@ class TestPmsFolioInvoice(TestPms): ) journals.allowed_pms_payments = True + # create a sale channel + self.sale_channel_direct1 = self.env["pms.sale.channel"].create( + { + "name": "Door", + "channel_type": "direct", + } + ) + def test_invoice_full_folio(self): """ Check that when launching the create_invoices() method for a full folio, @@ -153,6 +161,7 @@ class TestPmsFolioInvoice(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner_id.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) state_expected = "invoiced" @@ -183,6 +192,7 @@ class TestPmsFolioInvoice(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner_id.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) dict_lines = dict() @@ -208,6 +218,7 @@ class TestPmsFolioInvoice(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner_id.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) dict_lines = dict() @@ -260,6 +271,7 @@ class TestPmsFolioInvoice(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) tcs = [-1, 0, 3] @@ -294,6 +306,7 @@ class TestPmsFolioInvoice(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner_id.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) @@ -321,6 +334,7 @@ class TestPmsFolioInvoice(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner_id.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) qty_to_invoice_expected = sum( @@ -348,6 +362,7 @@ class TestPmsFolioInvoice(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner_id.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r1.folio_id._create_invoices() @@ -376,6 +391,8 @@ class TestPmsFolioInvoice(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner_id.id, + "service_ids": [(6, 0, [self.service1.id])], + "sale_channel_origin_id": self.sale_channel_direct1.id } ) @@ -418,6 +435,8 @@ class TestPmsFolioInvoice(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner_id.id, + "service_ids": [(6, 0, [self.service1.id])], + "sale_channel_origin_id": self.sale_channel_direct1.id } ) @@ -461,6 +480,8 @@ class TestPmsFolioInvoice(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner_id.id, + "service_ids": [(6, 0, [self.service1.id])], + "sale_channel_origin_id": self.sale_channel_direct1.id } ) @@ -523,6 +544,7 @@ class TestPmsFolioInvoice(TestPms): "room_type_id": self.room_type_double.id, "partner_id": self.partner_id.id, "board_service_room_id": self.board_service_room_type1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) dict_lines = dict() @@ -578,6 +600,7 @@ class TestPmsFolioInvoice(TestPms): "room_type_id": self.room_type_double.id, "partner_id": self.partner_id.id, "board_service_room_id": self.board_service_room_type1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) dict_lines = dict() @@ -634,6 +657,7 @@ class TestPmsFolioInvoice(TestPms): "room_type_id": self.room_type_double.id, "partner_id": self.partner_id.id, "board_service_room_id": self.board_service_room_type1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) dict_lines = dict() diff --git a/pms/tests/test_pms_folio_sale_line.py b/pms/tests/test_pms_folio_sale_line.py index b329d93f1..df733b2f4 100644 --- a/pms/tests/test_pms_folio_sale_line.py +++ b/pms/tests/test_pms_folio_sale_line.py @@ -81,6 +81,12 @@ class TestPmsFolioSaleLine(TestPms): } ) + self.sale_channel_direct1 = self.env["pms.sale.channel"].create( + { + "name": "Door", + "channel_type": "direct", + } + ) # RESERVATION LINES def test_comp_fsl_rooms_all_same_group(self): """ @@ -129,6 +135,7 @@ class TestPmsFolioSaleLine(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -160,6 +167,7 @@ class TestPmsFolioSaleLine(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -196,6 +204,7 @@ class TestPmsFolioSaleLine(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -234,6 +243,7 @@ class TestPmsFolioSaleLine(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -268,6 +278,7 @@ class TestPmsFolioSaleLine(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -304,6 +315,7 @@ class TestPmsFolioSaleLine(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r_test.flush() @@ -342,6 +354,7 @@ class TestPmsFolioSaleLine(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r_test.flush() @@ -383,6 +396,7 @@ class TestPmsFolioSaleLine(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r_test.flush() @@ -426,6 +440,7 @@ class TestPmsFolioSaleLine(TestPms): "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, "board_service_room_id": self.board_service_room_type.id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -464,6 +479,7 @@ class TestPmsFolioSaleLine(TestPms): "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, "board_service_room_id": self.board_service_room_type.id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r_test.service_ids[0].service_line_ids[0].price_unit = 1.0 @@ -503,6 +519,7 @@ class TestPmsFolioSaleLine(TestPms): "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, "board_service_room_id": self.board_service_room_type.id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -545,6 +562,7 @@ class TestPmsFolioSaleLine(TestPms): "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, "board_service_room_id": self.board_service_room_type.id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -586,6 +604,7 @@ class TestPmsFolioSaleLine(TestPms): "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, "board_service_room_id": self.board_service_room_type.id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -628,6 +647,7 @@ class TestPmsFolioSaleLine(TestPms): "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, "board_service_room_id": self.board_service_room_type.id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) previous_folio_board_service_sale_line = r_test.folio_id.sale_line_ids.filtered( @@ -670,6 +690,7 @@ class TestPmsFolioSaleLine(TestPms): "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, "board_service_room_id": self.board_service_room_type.id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -713,6 +734,7 @@ class TestPmsFolioSaleLine(TestPms): "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, "board_service_room_id": self.board_service_room_type.id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -756,6 +778,7 @@ class TestPmsFolioSaleLine(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) # ACT @@ -797,6 +820,7 @@ class TestPmsFolioSaleLine(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r_test.service_ids = [(4, self.extra_service.id)] @@ -841,6 +865,7 @@ class TestPmsFolioSaleLine(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r_test.service_ids = [(4, self.extra_service.id)] @@ -886,6 +911,7 @@ class TestPmsFolioSaleLine(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r_test.service_ids = [(4, self.extra_service.id)] @@ -929,6 +955,7 @@ class TestPmsFolioSaleLine(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r_test.service_ids = [(4, self.extra_service.id)] @@ -973,6 +1000,7 @@ class TestPmsFolioSaleLine(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r_test.service_ids = [(4, self.extra_service.id)] @@ -1016,6 +1044,7 @@ class TestPmsFolioSaleLine(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r_test.service_ids = [(4, self.extra_service.id)] @@ -1066,6 +1095,7 @@ class TestPmsFolioSaleLine(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r_test.service_ids = [(4, self.extra_service.id)] @@ -1114,6 +1144,7 @@ class TestPmsFolioSaleLine(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -1160,6 +1191,7 @@ class TestPmsFolioSaleLine(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -1212,6 +1244,7 @@ class TestPmsFolioSaleLine(TestPms): "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist1.id, "reservation_type": "staff", + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) # ASSERT @@ -1251,6 +1284,7 @@ class TestPmsFolioSaleLine(TestPms): "pricelist_id": self.pricelist1.id, "reservation_type": "out", "closure_reason_id": closure_reason.id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) # ASSERT diff --git a/pms/tests/test_pms_multiproperty.py b/pms/tests/test_pms_multiproperty.py index e040491a6..6f74d82f7 100644 --- a/pms/tests/test_pms_multiproperty.py +++ b/pms/tests/test_pms_multiproperty.py @@ -828,12 +828,19 @@ class TestPmsMultiproperty(TestPms): "email": "miguel@example.com", } ) + self.sale_channel_direct1 = self.env["pms.sale.channel"].create( + { + "name": "Door", + "channel_type": "direct", + } + ) self.reservation1 = self.env["pms.reservation"].create( { "checkin": fields.date.today(), "checkout": fields.date.today() + datetime.timedelta(days=1), "pms_property_id": self.pms_property1.id, "partner_id": host1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) diff --git a/pms/tests/test_pms_pricelist.py b/pms/tests/test_pms_pricelist.py index 9a034ccf4..d03f78e5a 100644 --- a/pms/tests/test_pms_pricelist.py +++ b/pms/tests/test_pms_pricelist.py @@ -83,6 +83,14 @@ class TestPmsPricelist(TestPms): self.partner1 = self.env["res.partner"].create({"name": "Carles"}) + # create a sale channel + self.sale_channel_direct1 = self.env["pms.sale.channel"].create( + { + "name": "Door", + "channel_type": "direct", + } + ) + @freeze_time("2000-01-01") def test_board_service_pricelist_item_apply_sale_dates(self): """ @@ -120,6 +128,7 @@ class TestPmsPricelist(TestPms): "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist2.id, "board_service_room_id": self.board_service_room_type1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) # ASSERT @@ -167,6 +176,7 @@ class TestPmsPricelist(TestPms): "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist2.id, "board_service_room_id": self.board_service_room_type1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) # ASSERT @@ -211,6 +221,7 @@ class TestPmsPricelist(TestPms): "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist2.id, "board_service_room_id": self.board_service_room_type1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) # ASSERT @@ -259,6 +270,7 @@ class TestPmsPricelist(TestPms): "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist2.id, "board_service_room_id": self.board_service_room_type1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) # ASSERT @@ -305,6 +317,7 @@ class TestPmsPricelist(TestPms): "preferred_room_id": self.room1.id, "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist2.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) # ASSERT @@ -351,6 +364,7 @@ class TestPmsPricelist(TestPms): "preferred_room_id": self.room1.id, "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist2.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) # ASSERT @@ -393,6 +407,7 @@ class TestPmsPricelist(TestPms): "preferred_room_id": self.room1.id, "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist2.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) # ASSERT @@ -439,6 +454,7 @@ class TestPmsPricelist(TestPms): "preferred_room_id": self.room1.id, "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist2.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) # ASSERT @@ -485,6 +501,7 @@ class TestPmsPricelist(TestPms): "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist2.id, "service_ids": [(0, 0, {"product_id": self.product1.id})], + "sale_channel_origin_id": self.sale_channel_direct1.id } ) # ASSERT @@ -531,6 +548,7 @@ class TestPmsPricelist(TestPms): "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist2.id, "service_ids": [(0, 0, {"product_id": self.product1.id})], + "sale_channel_origin_id": self.sale_channel_direct1.id } ) # ASSERT @@ -573,6 +591,7 @@ class TestPmsPricelist(TestPms): "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist2.id, "service_ids": [(0, 0, {"product_id": self.product1.id})], + "sale_channel_origin_id": self.sale_channel_direct1.id } ) # ASSERT @@ -619,6 +638,7 @@ class TestPmsPricelist(TestPms): "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist2.id, "service_ids": [(0, 0, {"product_id": self.product1.id})], + "sale_channel_origin_id": self.sale_channel_direct1.id } ) # ASSERT @@ -782,6 +802,7 @@ class TestPmsPricelist(TestPms): "preferred_room_id": self.room.id, "pms_property_id": self.pms_property1.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) # ACT @@ -1230,6 +1251,7 @@ class TestPmsPricelist(TestPms): "preferred_room_id": self.room.id, "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) reservation_price = reservation.price_subtotal diff --git a/pms/tests/test_pms_reservation.py b/pms/tests/test_pms_reservation.py index f7c6e0f10..1e138da78 100644 --- a/pms/tests/test_pms_reservation.py +++ b/pms/tests/test_pms_reservation.py @@ -90,6 +90,9 @@ class TestPmsReservations(TestPms): self.id_category = self.env["res.partner.id_category"].create( {"name": "DNI", "code": "D"} ) + self.sale_channel_direct = self.env["pms.sale.channel"].create( + {"name": "sale channel direct", "channel_type": "direct"} + ) self.sale_channel1 = self.env["pms.sale.channel"].create( {"name": "saleChannel1", "channel_type": "indirect"} ) @@ -155,6 +158,7 @@ class TestPmsReservations(TestPms): "room_type_id": self.room_type_double.id, "partner_id": self.partner1.id, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, "reservation_line_ids": [ (0, False, {"date": today}), (0, False, {"date": tomorrow}), @@ -197,6 +201,7 @@ class TestPmsReservations(TestPms): "room_type_id": self.room_type_double.id, "partner_id": self.partner1.id, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } # ACT @@ -226,6 +231,7 @@ class TestPmsReservations(TestPms): "room_type_id": self.room_type_double.id, "partner_id": self.partner1.id, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } # ACT @@ -262,6 +268,7 @@ class TestPmsReservations(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) r_test.flush() @@ -300,6 +307,7 @@ class TestPmsReservations(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) r_test.flush() @@ -331,6 +339,7 @@ class TestPmsReservations(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) r1.reservation_line_ids[0].room_id = self.room2.id @@ -344,6 +353,7 @@ class TestPmsReservations(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) r2.reservation_line_ids[0].room_id = self.room3.id @@ -357,6 +367,7 @@ class TestPmsReservations(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) r3.reservation_line_ids[0].room_id = self.room1.id @@ -370,6 +381,7 @@ class TestPmsReservations(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) r4.reservation_line_ids[0].room_id = self.room3.id @@ -385,6 +397,7 @@ class TestPmsReservations(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) r_test.flush() @@ -419,6 +432,7 @@ class TestPmsReservations(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) r1.reservation_line_ids[0].room_id = self.room2.id @@ -432,6 +446,7 @@ class TestPmsReservations(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) r2.reservation_line_ids[0].room_id = self.room3.id @@ -445,6 +460,7 @@ class TestPmsReservations(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) r3.reservation_line_ids[0].room_id = self.room1.id @@ -458,6 +474,7 @@ class TestPmsReservations(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) r4.reservation_line_ids[0].room_id = self.room3.id @@ -471,6 +488,7 @@ class TestPmsReservations(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) r5.reservation_line_ids[0].room_id = self.room2.id @@ -485,6 +503,7 @@ class TestPmsReservations(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) r_test.flush() @@ -524,6 +543,7 @@ class TestPmsReservations(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) r1.reservation_line_ids[0].room_id = self.room1 @@ -566,6 +586,7 @@ class TestPmsReservations(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) r1.reservation_line_ids[0].room_id = self.room1 @@ -608,6 +629,7 @@ class TestPmsReservations(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) r1.reservation_line_ids[0].room_id = self.room1 @@ -623,6 +645,7 @@ class TestPmsReservations(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) r2.reservation_line_ids[0].room_id = self.room2 @@ -638,6 +661,7 @@ class TestPmsReservations(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) r3.reservation_line_ids[0].room_id = self.room3 @@ -722,6 +746,7 @@ class TestPmsReservations(TestPms): "room_type_id": self.room_type_double.id, "partner_id": self.partner1.id, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) computed_priority = res.priority @@ -758,6 +783,7 @@ class TestPmsReservations(TestPms): "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) @@ -860,6 +886,7 @@ class TestPmsReservations(TestPms): "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) @@ -902,6 +929,7 @@ class TestPmsReservations(TestPms): "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) host1 = self.env["res.partner"].create( @@ -971,6 +999,7 @@ class TestPmsReservations(TestPms): "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) host1 = self.env["res.partner"].create( @@ -1032,6 +1061,7 @@ class TestPmsReservations(TestPms): "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) computed_priority = res.priority @@ -1069,6 +1099,7 @@ class TestPmsReservations(TestPms): "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) host1 = self.env["res.partner"].create( @@ -1134,6 +1165,7 @@ class TestPmsReservations(TestPms): "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) host1 = self.env["res.partner"].create( @@ -1209,6 +1241,7 @@ class TestPmsReservations(TestPms): "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) computed_priority = res.priority @@ -1247,6 +1280,7 @@ class TestPmsReservations(TestPms): "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) computed_priority = res.priority @@ -1288,6 +1322,7 @@ class TestPmsReservations(TestPms): "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) host1 = self.env["res.partner"].create( @@ -1366,6 +1401,7 @@ class TestPmsReservations(TestPms): "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) host1 = self.env["res.partner"].create( @@ -1444,6 +1480,7 @@ class TestPmsReservations(TestPms): "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) host1 = self.env["res.partner"].create( @@ -1514,6 +1551,7 @@ class TestPmsReservations(TestPms): "room_type_id": self.room_type_double.id, "partner_id": self.partner1.id, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) # ACT @@ -1539,6 +1577,7 @@ class TestPmsReservations(TestPms): "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) @@ -1568,6 +1607,7 @@ class TestPmsReservations(TestPms): "room_type_id": self.room_type_double.id, "partner_id": self.partner1.id, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) @@ -1596,6 +1636,7 @@ class TestPmsReservations(TestPms): "room_type_id": self.room_type_double.id, "partner_id": self.partner1.id, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) # ACT @@ -1618,6 +1659,7 @@ class TestPmsReservations(TestPms): "room_type_id": self.room_type_double.id, "partner_id": self.partner1.id, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) # ACT @@ -1660,6 +1702,7 @@ class TestPmsReservations(TestPms): "room_type_id": self.room_type_double.id, "partner_id": host.id, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) r1.flush() @@ -1729,6 +1772,7 @@ class TestPmsReservations(TestPms): "checkout": fields.date.today() + datetime.timedelta(days=305), "partner_id": self.partner1.id, "room_type_id": self.room_type_double.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) r = reservation.checkin @@ -1766,6 +1810,7 @@ class TestPmsReservations(TestPms): "partner_id": self.partner1.id, "room_type_id": self.room_type_double.id, "pricelist_id": self.pricelist1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) self.assertEqual( @@ -1804,6 +1849,7 @@ class TestPmsReservations(TestPms): "checkout": fields.date.today() + datetime.timedelta(days=152), "agency_id": agency.id, "room_type_id": self.room_type_double.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) @@ -1871,6 +1917,7 @@ class TestPmsReservations(TestPms): "checkout": fields.date.today() + datetime.timedelta(days=152), "partner_id": self.partner1.id, "room_type_id": self.room_type_double.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) @@ -1931,6 +1978,7 @@ class TestPmsReservations(TestPms): "pms_property_id": self.pms_property1.id, "adults": 3, "room_type_id": self.room_type_triple.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) self.checkin1 = self.env["pms.checkin.partner"].create( @@ -2112,6 +2160,7 @@ class TestPmsReservations(TestPms): "checkout": fields.date.today() + datetime.timedelta(days=65), "pms_property_id": self.pms_property1.id, "partner_id": self.host1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) self.reservation2 = self.env["pms.reservation"].create( @@ -2121,6 +2170,7 @@ class TestPmsReservations(TestPms): "pms_property_id": self.pms_property1.id, "partner_id": self.host1.id, "folio_id": self.reservation.folio_id.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) self.assertTrue( @@ -2145,6 +2195,7 @@ class TestPmsReservations(TestPms): "checkout": fields.date.today() + datetime.timedelta(days=65), "pms_property_id": self.pms_property1.id, "partner_id": self.host1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) self.assertFalse( @@ -2175,6 +2226,7 @@ class TestPmsReservations(TestPms): "room_type_id": self.room_type_double.id, "partner_id": self.host1.id, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) @@ -2223,6 +2275,7 @@ class TestPmsReservations(TestPms): "partner_id": self.host1.id, "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) @@ -2276,6 +2329,7 @@ class TestPmsReservations(TestPms): "partner_id": self.host1.id, "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) @@ -2327,6 +2381,7 @@ class TestPmsReservations(TestPms): "partner_id": self.host1.id, "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) reservation.action_cancel() @@ -2365,6 +2420,7 @@ class TestPmsReservations(TestPms): "pms_property_id": self.pms_property1.id, "adults": 3, "room_type_id": self.room_type_triple.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) self.checkin1 = self.env["pms.checkin.partner"].create( @@ -2425,6 +2481,7 @@ class TestPmsReservations(TestPms): "pms_property_id": self.pms_property1.id, "room_type_id": self.room_type_triple.id, "adults": 3, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) self.checkin1 = self.env["pms.checkin.partner"].create( @@ -2479,6 +2536,7 @@ class TestPmsReservations(TestPms): "allowed_checkout": True, "pms_property_id": self.pms_property1.id, "room_type_id": self.room_type_double.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) @@ -2512,6 +2570,7 @@ class TestPmsReservations(TestPms): "pms_property_id": self.pms_property1.id, "folio_id": self.folio1.id, "room_type_id": self.room_type_double.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) # ACT AND ASSERT @@ -2605,6 +2664,7 @@ class TestPmsReservations(TestPms): "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist1.id, "service_ids": [self.board_service.id], + "sale_channel_origin_id": self.sale_channel_direct.id, } ) # ACTION @@ -2649,6 +2709,7 @@ class TestPmsReservations(TestPms): "partner_id": self.partner1.id, "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) @@ -2705,6 +2766,7 @@ class TestPmsReservations(TestPms): "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist1.id, "service_ids": [self.service.id], + "sale_channel_origin_id": self.sale_channel_direct.id, } ) @@ -2766,6 +2828,7 @@ class TestPmsReservations(TestPms): "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist1.id, "service_ids": [self.board_service.id], + "sale_channel_origin_id": self.sale_channel_direct.id, } ) @@ -2842,6 +2905,7 @@ class TestPmsReservations(TestPms): "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist1.id, "service_ids": [self.service.id, self.board_service.id], + "sale_channel_origin_id": self.sale_channel_direct.id, } ) @@ -2916,6 +2980,7 @@ class TestPmsReservations(TestPms): "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist1.id, "service_ids": [self.service.id, self.board_service.id], + "sale_channel_origin_id": self.sale_channel_direct.id, } ) @@ -2965,6 +3030,7 @@ class TestPmsReservations(TestPms): "partner_id": self.partner1.id, "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) @@ -3045,6 +3111,7 @@ class TestPmsReservations(TestPms): "partner_id": self.partner1.id, "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) diff_days = (checkout - checkin).days @@ -3079,6 +3146,7 @@ class TestPmsReservations(TestPms): "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist1.id, "reservation_type": "staff", + "sale_channel_origin_id": self.sale_channel_direct.id, } ) # ASSERT @@ -3118,6 +3186,7 @@ class TestPmsReservations(TestPms): "pricelist_id": self.pricelist1.id, "reservation_type": "out", "closure_reason_id": closure_reason.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) # ASSERT @@ -3147,6 +3216,7 @@ class TestPmsReservations(TestPms): "partner_id": self.partner1.id, "pms_property_id": self.pms_property1.id, "reservation_type": "staff", + "sale_channel_origin_id": self.sale_channel_direct.id, } ) @@ -3183,6 +3253,7 @@ class TestPmsReservations(TestPms): "pms_property_id": self.pms_property1.id, "reservation_type": "out", "closure_reason_id": closure_reason.id, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) @@ -3260,6 +3331,7 @@ class TestPmsReservations(TestPms): "reservation_type": "out", "closure_reason_id": closure_reason.id, "partner_name": "Install furniture", + "sale_channel_origin_id": self.sale_channel_direct.id, } ) @@ -3296,6 +3368,7 @@ class TestPmsReservations(TestPms): "mobile": "61568547", "document_type": self.id_category.id, "document_number": "31640132K", + "sale_channel_origin_id": self.sale_channel_direct.id, } ) # ASSERT @@ -3347,6 +3420,7 @@ class TestPmsReservations(TestPms): "partner_name": partner.name, "document_type": self.document_id.category_id.id, "document_number": self.document_id.name, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) # ASSERT @@ -3402,6 +3476,7 @@ class TestPmsReservations(TestPms): "partner_name": partner.name, "document_type": self.document_id.category_id.id, "document_number": self.document_id.name, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) # ASSERT @@ -3440,6 +3515,7 @@ class TestPmsReservations(TestPms): "pms_property_id": self.pms_property1.id, "partner_name": partner.name, "email": partner.email, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) # ASSERT @@ -3477,6 +3553,7 @@ class TestPmsReservations(TestPms): "pms_property_id": self.pms_property1.id, "partner_name": partner.name, "mobile": partner.mobile, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) # ASSERT @@ -3517,6 +3594,7 @@ class TestPmsReservations(TestPms): "pms_property_id": self.pms_property1.id, "partner_name": partner.name, "email": partner.email, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) @@ -3535,81 +3613,6 @@ class TestPmsReservations(TestPms): "The partner was not added to the reservation ", ) - # def test_is_modified_reservation(self): - # """ - # Checked that the is_modified_reservation field is correctly set - # to True when the checkin or checkout fields are modified in a - # reservation. - # ---------------------- - # A reservation is created. The checkin and checkout fields of - # the reservation are modified. The state of the boolean - # to_send_mail is changed to False so that the compute of - # the is_modified_reservation field is activated correctly - # and it is verified that the state of this field is True. - # """ - # # ARRANGE - # checkin = fields.date.today() - # checkout = fields.date.today() + datetime.timedelta(days=2) - # reservation_vals = { - # "checkin": checkin, - # "checkout": checkout, - # "room_type_id": self.room_type_double.id, - # "partner_id": self.partner1.id, - # "pms_property_id": self.pms_property1.id, - # } - # - # reservation = self.env["pms.reservation"].create(reservation_vals) - # - # # ACT - # writed_checkin = fields.date.today() + datetime.timedelta(days=4) - # writed_checkout = fields.date.today() + datetime.timedelta(days=6) - # reservation.to_send_mail = False - # reservation.update( - # { - # "checkin": writed_checkin, - # "checkout": writed_checkout, - # } - # ) - # - # # ASSERT - # self.assertTrue( - # reservation.is_modified_reservation, - # "is_modified_reservation field should be True ", - # ) - - # @freeze_time("2012-01-14") - # def test_is_not_modified_reservation(self): - # """ - # Checked that the is_modified_reservation field is correctly set - # to False when the reservation is modified but not the checkin - # or checkout fields. - # ---------------------- - # A reservation is created. The adults, arrival_hour and departure_hours - # fields of the reservation are modified.The it is verified that the state - # of this field is False. - # """ - # # ARRANGE - # checkin = fields.date.today() - # checkout = fields.date.today() + datetime.timedelta(days=2) - # reservation_vals = { - # "checkin": checkin, - # "checkout": checkout, - # "room_type_id": self.room_type_double.id, - # "partner_id": self.partner1.id, - # "pms_property_id": self.pms_property1.id, - # } - - # reservation = self.env["pms.reservation"].create(reservation_vals) - # reservation.update( - # {"adults": 1, "arrival_hour": "18:00", "departure_hour": "08:00"} - # ) - - # # ASSERT - # self.assertFalse( - # reservation.is_modified_reservation, - # "is_modified_reservation field should be False ", - # ) - @freeze_time("2012-01-14") def test_not_add_several_possibles_customers(self): """ @@ -3648,6 +3651,7 @@ class TestPmsReservations(TestPms): "pms_property_id": self.pms_property1.id, "partner_name": partner1.name, "email": partner1.email, + "sale_channel_origin_id": self.sale_channel_direct.id, } ) @@ -3688,6 +3692,7 @@ class TestPmsReservations(TestPms): "room_type_id": self.room_type_double.id, "pms_property_id": self.pms_property1.id, "partner_name": "Rosa Costa", + "sale_channel_origin_id": self.sale_channel_direct.id, } ) diff --git a/pms/tests/test_pms_sale_channel.py b/pms/tests/test_pms_sale_channel.py index 70702b53a..af54d5198 100644 --- a/pms/tests/test_pms_sale_channel.py +++ b/pms/tests/test_pms_sale_channel.py @@ -66,66 +66,6 @@ class TestPmsSaleChannel(TestPms): "Reservation with a valid agency should be created.", ) - def test_reservation_with_partner_direct(self): - """ - Reservation create with partner (no agency) and sale channel - 'direct' must be set reservation sale channel to 'direct'. - A reservation with partner and sale channel as 'direct' - should be created. - """ - # ARRANGE - PmsReservation = self.env["pms.reservation"] - PmsSaleChannel = self.env["pms.sale.channel"] - # ACT - sale_channel1 = PmsSaleChannel.create({"channel_type": "direct"}) - partner1 = self.env["res.partner"].create({"name": "partner1"}) - reservation1 = PmsReservation.create( - { - "checkin": datetime.datetime.now(), - "checkout": datetime.datetime.now() + datetime.timedelta(days=3), - "channel_type_id": sale_channel1.id, - "partner_id": partner1.id, - "pms_property_id": self.pms_property1.id, - } - ) - # ASSERT - self.assertEqual( - reservation1.channel_type_id.channel_type, - "direct", - "A reservation with partner and sale channel as 'direct'" - "should be created a 'direct' reservation.", - ) - - def test_reservation_with_partner_indirect(self): - """ - Reservation create with partner (no agency) and sale channel - 'indirect' must be set reservation sale channel to 'direct'. - A reservation with partner and sale channel as 'direct' - should be created. - """ - # ARRANGE - PmsReservation = self.env["pms.reservation"] - PmsSaleChannel = self.env["pms.sale.channel"] - # ACT - sale_channel1 = PmsSaleChannel.create({"channel_type": "indirect"}) - partner1 = self.env["res.partner"].create({"name": "partner1"}) - reservation1 = PmsReservation.create( - { - "checkin": datetime.datetime.now(), - "checkout": datetime.datetime.now() + datetime.timedelta(days=3), - "channel_type_id": sale_channel1.id, - "partner_id": partner1.id, - "pms_property_id": self.pms_property1.id, - } - ) - # ASSERT - self.assertEqual( - reservation1.channel_type_id.channel_type, - "indirect", - "A reservation with partner and sale channel as 'direct'" - "should be created a 'indirect' reservation.", - ) - def test_create_agency_with_sale_channel_indirect(self): """ Agency should be created as partner setted as 'agency' diff --git a/pms/tests/test_pms_wizard_split_join_swap_reservation.py b/pms/tests/test_pms_wizard_split_join_swap_reservation.py index c1f6853ef..60f2f48da 100644 --- a/pms/tests/test_pms_wizard_split_join_swap_reservation.py +++ b/pms/tests/test_pms_wizard_split_join_swap_reservation.py @@ -56,6 +56,15 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): self.partner1 = self.env["res.partner"].create({"name": "Antón"}) + # create a sale channel + self.sale_channel_direct1 = self.env["pms.sale.channel"].create( + { + "name": "Door", + "channel_type": "direct", + } + ) + + # UNIFY TESTS # review def test_unify_reservation_avail_should(self): """ @@ -83,6 +92,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r1.flush() @@ -119,6 +129,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r2 = self.env["pms.reservation"].create( @@ -129,6 +140,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r1 = self.env["pms.reservation"].create( @@ -139,6 +151,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "room_type_id": self.test_room_type_double.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r2.flush() @@ -164,6 +177,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r2 = self.env["pms.reservation"].create( @@ -174,6 +188,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r2.flush() @@ -215,6 +230,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r2 = self.env["pms.reservation"].create( @@ -225,6 +241,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r1.flush() @@ -274,6 +291,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r2 = self.env["pms.reservation"].create( @@ -284,6 +302,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r1.flush() @@ -332,6 +351,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r2 = self.env["pms.reservation"].create( @@ -342,6 +362,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r1.flush() @@ -394,6 +415,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r2 = self.env["pms.reservation"].create( @@ -404,6 +426,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r1.flush() @@ -456,6 +479,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r2 = self.env["pms.reservation"].create( @@ -466,6 +490,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r1.flush() @@ -515,6 +540,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) @@ -561,6 +587,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) @@ -572,6 +599,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r2 = self.env["pms.reservation"].create( @@ -582,6 +610,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r1.flush() @@ -633,6 +662,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) @@ -644,6 +674,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r2 = self.env["pms.reservation"].create( @@ -654,6 +685,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r1.flush() @@ -699,6 +731,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) @@ -736,6 +769,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r1.flush() @@ -773,6 +807,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r1.flush() @@ -819,6 +854,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r1.flush() @@ -861,6 +897,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r1.flush() @@ -900,6 +937,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r1.flush() @@ -930,6 +968,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r1.flush() @@ -959,6 +998,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r1 = self.env["pms.reservation"].create( @@ -969,6 +1009,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r1.flush() diff --git a/pms/tests/test_product_template.py b/pms/tests/test_product_template.py index 730d77e5f..a2efbf624 100644 --- a/pms/tests/test_product_template.py +++ b/pms/tests/test_product_template.py @@ -31,6 +31,13 @@ class TestProductTemplate(TestPms): "default_code": "BST", } ) + # create a sale channel + self.sale_channel_direct1 = self.env["pms.sale.channel"].create( + { + "name": "Door", + "channel_type": "direct", + } + ) def test_bs_consumed_on_after(self): """ @@ -69,6 +76,7 @@ class TestProductTemplate(TestPms): "pms_property_id": self.pms_property1.id, "partner_id": self.partner.id, "board_service_room_id": board_service_room_type.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) # ASSERT @@ -115,6 +123,7 @@ class TestProductTemplate(TestPms): "pms_property_id": self.pms_property1.id, "partner_id": self.partner.id, "board_service_room_id": board_service_room_type.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) # ASSERT @@ -162,6 +171,7 @@ class TestProductTemplate(TestPms): "pms_property_id": self.pms_property1.id, "partner_id": self.partner.id, "board_service_room_id": board_service_room_type.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) reservation.flush() @@ -211,6 +221,7 @@ class TestProductTemplate(TestPms): "pms_property_id": self.pms_property1.id, "partner_id": self.partner.id, "board_service_room_id": board_service_room_type.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) reservation.flush() @@ -267,6 +278,7 @@ class TestProductTemplate(TestPms): "partner_id": self.partner.id, "board_service_room_id": board_service_room_type.id, "adults": 2, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) @@ -298,6 +310,7 @@ class TestProductTemplate(TestPms): "pms_property_id": self.pms_property1.id, "partner_id": self.partner.id, "service_ids": [extra_bed_service.id], + "sale_channel_origin_id": self.sale_channel_direct1.id } ) reservation._check_adults() diff --git a/pms/tests/test_shared_room.py b/pms/tests/test_shared_room.py index 2408805c4..d3061b3a0 100644 --- a/pms/tests/test_shared_room.py +++ b/pms/tests/test_shared_room.py @@ -85,6 +85,15 @@ class TestPmsSharedRoom(TestPms): } ) + # create a sale channel + self.sale_channel_direct1 = self.env["pms.sale.channel"].create( + { + "name": "Door", + "channel_type": "direct", + } + ) + + def test_count_avail_beds_with_room_occupied(self): """ Check that not allow to create a bed reservation with a room occupied @@ -104,6 +113,7 @@ class TestPmsSharedRoom(TestPms): "checkin": today, "checkout": tomorrow, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) @@ -137,6 +147,7 @@ class TestPmsSharedRoom(TestPms): "checkin": today, "checkout": tomorrow, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) @@ -182,6 +193,7 @@ class TestPmsSharedRoom(TestPms): "checkin": today, "checkout": tomorrow, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) @@ -217,6 +229,7 @@ class TestPmsSharedRoom(TestPms): "checkin": today, "checkout": tomorrow, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) res1.flush() @@ -250,6 +263,7 @@ class TestPmsSharedRoom(TestPms): "checkin": today, "checkout": tomorrow, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) @@ -285,6 +299,7 @@ class TestPmsSharedRoom(TestPms): "checkin": today, "checkout": tomorrow, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) @@ -321,6 +336,7 @@ class TestPmsSharedRoom(TestPms): "checkin": today, "checkout": tomorrow, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) @@ -355,6 +371,7 @@ class TestPmsSharedRoom(TestPms): "checkin": today, "checkout": tomorrow, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) @@ -370,6 +387,7 @@ class TestPmsSharedRoom(TestPms): "checkin": today, "checkout": tomorrow, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r_test.flush() @@ -394,6 +412,7 @@ class TestPmsSharedRoom(TestPms): "checkin": today, "checkout": tomorrow, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) @@ -410,6 +429,7 @@ class TestPmsSharedRoom(TestPms): "checkin": today, "checkout": tomorrow, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r_test.flush() @@ -435,6 +455,7 @@ class TestPmsSharedRoom(TestPms): "checkin": today, "checkout": tomorrow, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r1.action_cancel() @@ -471,6 +492,7 @@ class TestPmsSharedRoom(TestPms): "checkin": today, "checkout": tomorrow, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id } ) r1.action_cancel() diff --git a/pms/wizards/pms_booking_engine.py b/pms/wizards/pms_booking_engine.py index 937d9d79c..193135264 100644 --- a/pms/wizards/pms_booking_engine.py +++ b/pms/wizards/pms_booking_engine.py @@ -237,7 +237,7 @@ class BookingEngine(models.TransientModel): "partner_name": record.partner_name, "pms_property_id": record.pms_property_id.id, "agency_id": record.agency_id.id, - "channel_type_id": record.channel_type_id.id, + "sale_channel_origin_id": record.channel_type_id.id, "segmentation_ids": [(6, 0, record.segmentation_ids.ids)], "internal_comment": record.internal_comment, } From 95eb5bc7e0f0ef31f6dbced8b93e79832aa37182 Mon Sep 17 00:00:00 2001 From: Sara Lago Date: Wed, 23 Mar 2022 18:21:00 +0100 Subject: [PATCH 03/23] [IMP] pms: add tests for multi channel in reservations and folio, solve their problems and precommit --- pms/models/pms_reservation.py | 2 + pms/tests/test_pms_checkin_partner.py | 12 +- pms/tests/test_pms_folio.py | 423 +++++++++++++++++- pms/tests/test_pms_folio_invoice.py | 26 +- pms/tests/test_pms_folio_sale_line.py | 1 + pms/tests/test_pms_pricelist.py | 28 +- pms/tests/test_pms_reservation.py | 307 +++++++++++++ ..._pms_wizard_split_join_swap_reservation.py | 65 ++- pms/tests/test_product_template.py | 12 +- pms/tests/test_shared_room.py | 27 +- 10 files changed, 813 insertions(+), 90 deletions(-) diff --git a/pms/models/pms_reservation.py b/pms/models/pms_reservation.py index 0c03053f6..70f6625f9 100644 --- a/pms/models/pms_reservation.py +++ b/pms/models/pms_reservation.py @@ -2009,6 +2009,8 @@ class PmsReservation(models.Model): default_vals["email"] = folio.email elif vals.get("reservation_type") != "out": raise ValidationError(_("Partner contact name is required")) + if folio.sale_channel_origin_id and "sale_channel_origin_id" not in vals: + default_vals["sale_channel_origin_id"] = folio.sale_channel_origin_id.id vals.update(default_vals) elif ( "pms_property_id" in vals diff --git a/pms/tests/test_pms_checkin_partner.py b/pms/tests/test_pms_checkin_partner.py index cc0e9d414..e2831699c 100644 --- a/pms/tests/test_pms_checkin_partner.py +++ b/pms/tests/test_pms_checkin_partner.py @@ -1098,7 +1098,7 @@ class TestPmsCheckinPartner(TestPms): "pms_property_id": self.pms_property1.id, "partner_name": partner.name, "email": partner.email, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) # ACT @@ -1141,7 +1141,7 @@ class TestPmsCheckinPartner(TestPms): "room_type_id": self.room_type1.id, "pms_property_id": self.pms_property1.id, "partner_name": partner.name, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) # ACT @@ -1187,7 +1187,7 @@ class TestPmsCheckinPartner(TestPms): "room_type_id": self.room_type1.id, "pms_property_id": self.pms_property1.id, "partner_name": partner.name, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) checkin = self.env["pms.checkin.partner"].create( @@ -1249,7 +1249,7 @@ class TestPmsCheckinPartner(TestPms): "room_type_id": self.room_type1.id, "pms_property_id": self.pms_property1.id, "partner_name": partner1.name, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -1297,7 +1297,7 @@ class TestPmsCheckinPartner(TestPms): "room_type_id": self.room_type1.id, "pms_property_id": self.pms_property1.id, "partner_name": "Rosa Costa", - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) checkin = self.env["pms.checkin.partner"].create( @@ -1551,7 +1551,7 @@ class TestPmsCheckinPartner(TestPms): "partner_id": self.host1.id, "adults": 1, "pms_property_id": self.pms_property1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) checkin_partner_id = self.reservation.checkin_partner_ids[0] diff --git a/pms/tests/test_pms_folio.py b/pms/tests/test_pms_folio.py index ba72a4c4a..3d94959ac 100644 --- a/pms/tests/test_pms_folio.py +++ b/pms/tests/test_pms_folio.py @@ -63,7 +63,6 @@ class TestPmsFolio(TestPms): } ) - def create_sale_channel_scenario(self): """ Method to simplified scenario on sale channel tests: @@ -419,7 +418,7 @@ class TestPmsFolio(TestPms): "adults": 2, "partner_id": self.env.ref("base.res_partner_12").id, "room_type_id": self.demo_room_type_double.id, - "sale_channel_origin_id":self.sale_channel_direct1.id, + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -466,7 +465,7 @@ class TestPmsFolio(TestPms): "adults": 2, "partner_id": self.env.ref("base.res_partner_12").id, "room_type_id": self.demo_room_type_double.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -594,7 +593,7 @@ class TestPmsFolio(TestPms): "pricelist_id": self.pricelist1.id, "reservation_type": "out", "closure_reason_id": closure_reason.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) # ASSERT @@ -1121,3 +1120,419 @@ class TestPmsFolio(TestPms): folio1.partner_invoice_ids.ids, "A checkin partner was not added as a billing contact", ) + + @freeze_time("2001-10-10") + def test_folio_sale_channel_origin_in_reservation(self): + """ + Check that the reservation has sale_channel_origin_id + as the folio sale_channel_origin_id in + which reservation was created + + When a reservation is created on a folio + that already has a sale_channel_origin + that reservation will have the same sale_channel_origin + + """ + # ARRANGE + partner1 = self.env["res.partner"].create({"name": "partner1"}) + folio1 = self.env["pms.folio"].create( + { + "pms_property_id": self.pms_property1.id, + "partner_name": partner1.name, + "sale_channel_origin_id": self.sale_channel_direct1.id, + } + ) + # ACT + reservation1 = self.env["pms.reservation"].create( + { + "checkin": datetime.datetime.now(), + "checkout": datetime.datetime.now() + datetime.timedelta(days=1), + "adults": 2, + "room_type_id": self.room_type_double.id, + "folio_id": folio1.id, + } + ) + # ASSERT + self.assertEqual( + reservation1.sale_channel_origin_id.id, + folio1.sale_channel_origin_id.id, + "Sale channel of reservation must be the same that it folio", + ) + + @freeze_time("2001-10-19") + def test_folio_sale_channel_ids(self): + """ + Check if sale_channel_ids of folio correspond to + sale_channel_origin_id of its reservations at the + time of creating a new reservation in the folio + """ + # ARRANGE + sale_channel_phone = self.env["pms.sale.channel"].create( + { + "name": "phone", + "channel_type": "direct", + } + ) + partner1 = self.env["res.partner"].create({"name": "partner1"}) + folio1 = self.env["pms.folio"].create( + { + "pms_property_id": self.pms_property1.id, + "partner_name": partner1.name, + "sale_channel_origin_id": self.sale_channel_direct1.id, + } + ) + + self.env["pms.reservation"].create( + { + "checkin": datetime.datetime.now(), + "checkout": datetime.datetime.now() + datetime.timedelta(days=1), + "adults": 2, + "room_type_id": self.room_type_double.id, + "folio_id": folio1.id, + } + ) + self.env["pms.reservation"].create( + { + "checkin": datetime.datetime.now(), + "checkout": datetime.datetime.now() + datetime.timedelta(days=1), + "adults": 2, + "room_type_id": self.room_type_double.id, + "folio_id": folio1.id, + "sale_channel_origin_id": sale_channel_phone.id, + } + ) + # ACT + expected_sale_channels = [] + for reservation in folio1.reservation_ids: + expected_sale_channels.append(reservation.sale_channel_origin_id.id) + + # ASSERT + self.assertItemsEqual( + folio1.sale_channel_ids.ids, + list(set(expected_sale_channels)), + "Sale_channel_ids of folio must be the same as " + "sale_channel_origin of its reservation ", + ) + + @freeze_time("2001-10-22") + def test_folio_sale_channel_ids_reservations_several_origin(self): + """ + Check that sale_channel_ids of folio correspond to sale_channel_origin_id + of its reservations + + In this case, folio1 has two reservations(reservation1, reservation2) + with the same sale_channel_origin. + + sale_channel_origin_id sale_channel_ids + ------------------------- + Folio1 --------> sale_channel_direct1 || sale_channel_direct1 + reservation1 --> sale_channel_direct1 + reservation2 --> sale_channel_direct1 + + Then, reservation2 update sale_channel_origin_id for a diferent one. So the folio + has several reservations with different sale_channel_origin_id. + It should be noted that the check would force having to update + the folio sale_channel_origin_id (force_update_origin) isn't marked. + + Expected result: + + sale_channel_origin_id sale_channel_ids + ---------------------- + Folio1 --------> sale_channel_direct1 | (sale_channel_direct1, sale_channel_phone) + reservation1 --> sale_channel_direct1 + reservation2 --> sale_channel_phone + + In this test case, sale_channel_ids will be checked + """ + # ARRANGE + sale_channel_phone = self.env["pms.sale.channel"].create( + { + "name": "phone", + "channel_type": "direct", + } + ) + partner1 = self.env["res.partner"].create({"name": "partner1"}) + folio1 = self.env["pms.folio"].create( + { + "pms_property_id": self.pms_property1.id, + "partner_name": partner1.name, + "sale_channel_origin_id": self.sale_channel_direct1.id, + } + ) + + self.env["pms.reservation"].create( + { + "checkin": datetime.datetime.now(), + "checkout": datetime.datetime.now() + datetime.timedelta(days=1), + "adults": 2, + "room_type_id": self.room_type_double.id, + "folio_id": folio1.id, + } + ) + reservation2 = self.env["pms.reservation"].create( + { + "checkin": datetime.datetime.now(), + "checkout": datetime.datetime.now() + datetime.timedelta(days=1), + "adults": 2, + "room_type_id": self.room_type_double.id, + "folio_id": folio1.id, + } + ) + # ACT + reservation_vals = { + "sale_channel_origin_id": sale_channel_phone.id, + "force_update_origin": False, + } + + reservation2.write(reservation_vals) + expected_sale_channels = [] + for reservation in folio1.reservation_ids: + expected_sale_channels.append(reservation.sale_channel_origin_id.id) + + # ASSERT + self.assertItemsEqual( + folio1.sale_channel_ids.ids, + list(set(expected_sale_channels)), + "Sale_channel_ids of folio must be the same as " + "sale_channel_origin of its reservation ", + ) + + @freeze_time("2001-10-22") + def test_sale_channel_origin_id_reservation_not_update_origin(self): + """ + Check that sale_channel_origin_id of folio doesn't change + when sale_channel_origin_id of one of its reservations is updated + but the check isn't checked + + In this case, folio1 has two reservations(reservation1, reservation2) + with the same sale_channel_origin. + + sale_channel_origin_id + ------------------------- + Folio1 --------> sale_channel_direct1 + reservation1 --> sale_channel_direct1 + reservation2 --> sale_channel_direct1 + + Then, reservation2 update sale_channel_origin_id for a diferent one. So the folio + has several reservations with different sale_channel_origin_id. + And the check would force having to update + the folio sale_channel_origin_id (force_update_origin) isn't marked. + So sale_channel_origin_id of folio shouldn't change. + + Expected result: + + sale_channel_origin_id + ------------------------- + Folio1 --------> sale_channel_direct1 + reservation1 --> sale_channel_direct1 + reservation2 --> sale_channel_phone + + In this test case, sale_channel_origin_id of folio will be checked + """ + # ARRANGE + sale_channel_phone = self.env["pms.sale.channel"].create( + { + "name": "phone", + "channel_type": "direct", + } + ) + partner1 = self.env["res.partner"].create({"name": "partner1"}) + folio1 = self.env["pms.folio"].create( + { + "pms_property_id": self.pms_property1.id, + "partner_name": partner1.name, + "sale_channel_origin_id": self.sale_channel_direct1.id, + } + ) + + self.env["pms.reservation"].create( + { + "checkin": datetime.datetime.now(), + "checkout": datetime.datetime.now() + datetime.timedelta(days=1), + "adults": 2, + "room_type_id": self.room_type_double.id, + "folio_id": folio1.id, + } + ) + reservation2 = self.env["pms.reservation"].create( + { + "checkin": datetime.datetime.now(), + "checkout": datetime.datetime.now() + datetime.timedelta(days=1), + "adults": 2, + "room_type_id": self.room_type_double.id, + "folio_id": folio1.id, + } + ) + # ACT + reservation_vals = { + "sale_channel_origin_id": sale_channel_phone.id, + "force_update_origin": False, + } + reservation2.write(reservation_vals) + + # ASSERT + self.assertNotEqual( + folio1.sale_channel_origin_id, + reservation2.sale_channel_origin_id, + "Sale_channel_origin_id of folio shouldn't be the same as " + "sale_channel_origin of reservation2", + ) + + @freeze_time("2001-10-25") + def test_sale_channel_origin_id_reservation_update_origin(self): + """ + Check that sale_channel_origin_id of the folio changes when + you change sale_channel_origin_id of one of its reservations + and check that forces the update of sale_channel_origin_id of folio + + + sale_channel_origin_id + ------------------------- + Folio1 --------> sale_channel_direct1 + reservation1 --> sale_channel_direct1 + reservation2 --> sale_channel_direct1 + + Then, reservation2 update sale_channel_origin_id for a diferent one. So the folio + has several reservations with different sale_channel_origin_id. + And the check would force having to update + the folio sale_channel_origin_id (force_update_origin) is marked. + So sale_channel_origin_id of folio must change. + + Expected result: + + sale_channel_origin_id + ------------------------- + Folio1 --------> sale_channel_phone + reservation1 --> sale_channel_phone + reservation2 --> sale_channel_phone + + In this test case, sale_channel_origin_id of folio1 will be checked + """ + # ARRANGE + sale_channel_phone = self.env["pms.sale.channel"].create( + { + "name": "phone", + "channel_type": "direct", + } + ) + partner1 = self.env["res.partner"].create({"name": "partner1"}) + folio1 = self.env["pms.folio"].create( + { + "pms_property_id": self.pms_property1.id, + "partner_name": partner1.name, + "sale_channel_origin_id": self.sale_channel_direct1.id, + } + ) + + self.env["pms.reservation"].create( + { + "checkin": datetime.datetime.now(), + "checkout": datetime.datetime.now() + datetime.timedelta(days=1), + "adults": 2, + "room_type_id": self.room_type_double.id, + "folio_id": folio1.id, + } + ) + reservation2 = self.env["pms.reservation"].create( + { + "checkin": datetime.datetime.now(), + "checkout": datetime.datetime.now() + datetime.timedelta(days=1), + "adults": 2, + "room_type_id": self.room_type_double.id, + "folio_id": folio1.id, + } + ) + # ACT + reservation_vals = { + "sale_channel_origin_id": sale_channel_phone.id, + "force_update_origin": True, + } + reservation2.write(reservation_vals) + # ASSERT + self.assertEqual( + folio1.sale_channel_origin_id, + reservation2.sale_channel_origin_id, + "Sale_channel_origin_id of folio should be updated", + ) + + @freeze_time("2001-10-25") + def test_sale_channel_origin_id_reservation_update_reservations(self): + """ + Check that sale_channel_origin_id of a reservation changes when + another reservation of the same folio changes sale_channel_origin_id + and marks the check. + By changing sale_channel_origin_ id of a reservation and marking the check + that forces the update, changes both sale_channel_origin of folio and + sale_channel_origin of reservations that had the same + + + sale_channel_origin_id + ------------------------- + Folio1 --------> sale_channel_direct1 + reservation1 --> sale_channel_direct1 + reservation2 --> sale_channel_direct1 + + Then, reservation2 update sale_channel_origin_id for a diferent one. + And the check would force having to update + the folio sale_channel_origin_id (force_update_origin) is marked. + So sale_channel_origin_id of folio and other reservations with the same + sale_channel_origin must change. + + Expected result: + + sale_channel_origin_id + ------------------------- + Folio1 --------> sale_channel_phone + reservation1 --> sale_channel_phone + reservation2 --> sale_channel_phone + + In this test case, sale_channel_origin_id of reservation1 will be checked + """ + # ARRANGE + sale_channel_phone = self.env["pms.sale.channel"].create( + { + "name": "phone", + "channel_type": "direct", + } + ) + partner1 = self.env["res.partner"].create({"name": "partner1"}) + folio1 = self.env["pms.folio"].create( + { + "pms_property_id": self.pms_property1.id, + "partner_name": partner1.name, + "sale_channel_origin_id": self.sale_channel_direct1.id, + } + ) + + reservation1 = self.env["pms.reservation"].create( + { + "checkin": datetime.datetime.now(), + "checkout": datetime.datetime.now() + datetime.timedelta(days=1), + "adults": 2, + "room_type_id": self.room_type_double.id, + "folio_id": folio1.id, + } + ) + reservation2 = self.env["pms.reservation"].create( + { + "checkin": datetime.datetime.now(), + "checkout": datetime.datetime.now() + datetime.timedelta(days=1), + "adults": 2, + "room_type_id": self.room_type_double.id, + "folio_id": folio1.id, + } + ) + # ACT + reservation_vals = { + "sale_channel_origin_id": sale_channel_phone.id, + "force_update_origin": True, + } + reservation2.write(reservation_vals) + + # ASSERT + self.assertEqual( + reservation1.sale_channel_origin_id, + reservation2.sale_channel_origin_id, + "sale_channel_origin_id of reservations that coincided " + "with sale_channel_origin_id of folio de should be updated", + ) diff --git a/pms/tests/test_pms_folio_invoice.py b/pms/tests/test_pms_folio_invoice.py index 1db34077f..e768cd42e 100644 --- a/pms/tests/test_pms_folio_invoice.py +++ b/pms/tests/test_pms_folio_invoice.py @@ -161,7 +161,7 @@ class TestPmsFolioInvoice(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner_id.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) state_expected = "invoiced" @@ -192,7 +192,7 @@ class TestPmsFolioInvoice(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner_id.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) dict_lines = dict() @@ -218,7 +218,7 @@ class TestPmsFolioInvoice(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner_id.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) dict_lines = dict() @@ -271,7 +271,7 @@ class TestPmsFolioInvoice(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) tcs = [-1, 0, 3] @@ -306,7 +306,7 @@ class TestPmsFolioInvoice(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner_id.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -334,7 +334,7 @@ class TestPmsFolioInvoice(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner_id.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) qty_to_invoice_expected = sum( @@ -362,7 +362,7 @@ class TestPmsFolioInvoice(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.partner_id.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r1.folio_id._create_invoices() @@ -392,7 +392,7 @@ class TestPmsFolioInvoice(TestPms): "room_type_id": self.room_type_double.id, "partner_id": self.partner_id.id, "service_ids": [(6, 0, [self.service1.id])], - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -436,7 +436,7 @@ class TestPmsFolioInvoice(TestPms): "room_type_id": self.room_type_double.id, "partner_id": self.partner_id.id, "service_ids": [(6, 0, [self.service1.id])], - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -481,7 +481,7 @@ class TestPmsFolioInvoice(TestPms): "room_type_id": self.room_type_double.id, "partner_id": self.partner_id.id, "service_ids": [(6, 0, [self.service1.id])], - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -544,7 +544,7 @@ class TestPmsFolioInvoice(TestPms): "room_type_id": self.room_type_double.id, "partner_id": self.partner_id.id, "board_service_room_id": self.board_service_room_type1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) dict_lines = dict() @@ -600,7 +600,7 @@ class TestPmsFolioInvoice(TestPms): "room_type_id": self.room_type_double.id, "partner_id": self.partner_id.id, "board_service_room_id": self.board_service_room_type1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) dict_lines = dict() @@ -657,7 +657,7 @@ class TestPmsFolioInvoice(TestPms): "room_type_id": self.room_type_double.id, "partner_id": self.partner_id.id, "board_service_room_id": self.board_service_room_type1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) dict_lines = dict() diff --git a/pms/tests/test_pms_folio_sale_line.py b/pms/tests/test_pms_folio_sale_line.py index df733b2f4..140e1c159 100644 --- a/pms/tests/test_pms_folio_sale_line.py +++ b/pms/tests/test_pms_folio_sale_line.py @@ -87,6 +87,7 @@ class TestPmsFolioSaleLine(TestPms): "channel_type": "direct", } ) + # RESERVATION LINES def test_comp_fsl_rooms_all_same_group(self): """ diff --git a/pms/tests/test_pms_pricelist.py b/pms/tests/test_pms_pricelist.py index d03f78e5a..bebfd4ed4 100644 --- a/pms/tests/test_pms_pricelist.py +++ b/pms/tests/test_pms_pricelist.py @@ -128,7 +128,7 @@ class TestPmsPricelist(TestPms): "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist2.id, "board_service_room_id": self.board_service_room_type1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) # ASSERT @@ -176,7 +176,7 @@ class TestPmsPricelist(TestPms): "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist2.id, "board_service_room_id": self.board_service_room_type1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) # ASSERT @@ -221,7 +221,7 @@ class TestPmsPricelist(TestPms): "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist2.id, "board_service_room_id": self.board_service_room_type1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) # ASSERT @@ -270,7 +270,7 @@ class TestPmsPricelist(TestPms): "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist2.id, "board_service_room_id": self.board_service_room_type1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) # ASSERT @@ -317,7 +317,7 @@ class TestPmsPricelist(TestPms): "preferred_room_id": self.room1.id, "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist2.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) # ASSERT @@ -364,7 +364,7 @@ class TestPmsPricelist(TestPms): "preferred_room_id": self.room1.id, "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist2.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) # ASSERT @@ -407,7 +407,7 @@ class TestPmsPricelist(TestPms): "preferred_room_id": self.room1.id, "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist2.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) # ASSERT @@ -454,7 +454,7 @@ class TestPmsPricelist(TestPms): "preferred_room_id": self.room1.id, "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist2.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) # ASSERT @@ -501,7 +501,7 @@ class TestPmsPricelist(TestPms): "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist2.id, "service_ids": [(0, 0, {"product_id": self.product1.id})], - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) # ASSERT @@ -548,7 +548,7 @@ class TestPmsPricelist(TestPms): "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist2.id, "service_ids": [(0, 0, {"product_id": self.product1.id})], - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) # ASSERT @@ -591,7 +591,7 @@ class TestPmsPricelist(TestPms): "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist2.id, "service_ids": [(0, 0, {"product_id": self.product1.id})], - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) # ASSERT @@ -638,7 +638,7 @@ class TestPmsPricelist(TestPms): "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist2.id, "service_ids": [(0, 0, {"product_id": self.product1.id})], - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) # ASSERT @@ -802,7 +802,7 @@ class TestPmsPricelist(TestPms): "preferred_room_id": self.room.id, "pms_property_id": self.pms_property1.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) # ACT @@ -1251,7 +1251,7 @@ class TestPmsPricelist(TestPms): "preferred_room_id": self.room.id, "pms_property_id": self.pms_property1.id, "pricelist_id": self.pricelist1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) reservation_price = reservation.price_subtotal diff --git a/pms/tests/test_pms_reservation.py b/pms/tests/test_pms_reservation.py index 1e138da78..352693be8 100644 --- a/pms/tests/test_pms_reservation.py +++ b/pms/tests/test_pms_reservation.py @@ -3796,6 +3796,7 @@ class TestPmsReservations(TestPms): self.commission + service.price_total * self.agency1.default_commission / 100 ) + # ASSERT self.assertEqual( self.commission, reservation.commission_amount, @@ -3867,3 +3868,309 @@ class TestPmsReservations(TestPms): "The out of service reservation should be created properly with " "a closure reason.", ) + # tests for several sale channels in reservation + @freeze_time("2000-11-10") + def test_reservation_sale_channel_origin_in_reservation_lines(self): + """ + Check that reservation_lines have sale_channel_id + corresponding to sale_channel_origin_id of their reservation + + When a reservation was created with a sale channel, it corresponds + to the sale_channel_origin. + Reservation lines will have as sale_channel_id the sale_channel_origin_id + of reservation when creating them + + """ + # ARRANGE + checkin = fields.date.today() + checkout = checkin + datetime.timedelta(days=3) + reservation_vals = { + "checkin": checkin, + "checkout": checkout, + "room_type_id": self.room_type_double.id, + "partner_id": self.partner1.id, + "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, + } + + # ACT + reservation = self.env["pms.reservation"].create(reservation_vals) + + # ASSERT + self.assertEqual( + reservation.sale_channel_origin_id, + reservation.reservation_line_ids.mapped("sale_channel_id"), + "Sale channel of reservation lines must be the same that their reservation", + ) + + @freeze_time("2000-10-10") + def test_reservation_sale_channel_origin_in_folio(self): + """ + Check that folio have sale_channel_origin_id + corresponding to sale_channel_origin_id of the reservation + that was created before the folio + + When a reservation was created with a sale channel, it corresponds + to the sale_channel_origin. + If reservation didn't have folio previously, the folio to be created + will have the same sale_channel_origin as the reservation + + """ + # ARRANGE + checkin = fields.date.today() + checkout = checkin + datetime.timedelta(days=3) + reservation_vals = { + "checkin": checkin, + "checkout": checkout, + "room_type_id": self.room_type_double.id, + "partner_id": self.partner1.id, + "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, + } + + # ACT + reservation = self.env["pms.reservation"].create(reservation_vals) + + # ASSERT + self.assertEqual( + reservation.sale_channel_origin_id, + reservation.folio_id.sale_channel_origin_id, + "Sale channel of folio must be the same that it reservation", + ) + + @freeze_time("2001-10-15") + def test_reservation_sale_channel_origin_of_folio(self): + """ + Check that the reservation has sale_channel_origin_id + as the folio sale_channel_origin_id in + which reservation was created when a folio has already + another reservations. + + Testing whether it works when the folio sale_channel_origin_id + is given by a previously created reservation + + When a reservation is created on a folio + that already has a sale_channel_origin + that reservation will have the same sale_channel_origin + + """ + # ARRANGE + reservation_vals = { + "checkin": datetime.datetime.now(), + "checkout": datetime.datetime.now() + datetime.timedelta(days=1), + "room_type_id": self.room_type_double.id, + "partner_id": self.partner1.id, + "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, + } + reservation1 = self.env["pms.reservation"].create(reservation_vals) + # ACT + reservation2 = self.env["pms.reservation"].create( + { + "checkin": datetime.datetime.now(), + "checkout": datetime.datetime.now() + datetime.timedelta(days=1), + "adults": 2, + "room_type_id": self.room_type_double.id, + "partner_id": self.partner1.id, + "folio_id": reservation1.folio_id.id, + } + ) + # ASSERT + self.assertEqual( + reservation1.sale_channel_origin_id.id, + reservation2.sale_channel_origin_id.id, + "Sale channel of reservations must be the same", + ) + + @freeze_time("2000-10-19") + def test_reservation_lines_same_sale_channel(self): + """ + Check if sale_channel_ids of reservation correspond to + sale_channel_id of its reservation. + + In this case, the reservation has several reservation_lines + with the same sale_channel_id. Reservation lines are created + with sale_channel_origin_id of the reservation and haven't been + modified. + + """ + # ARRANGE + reservation_vals = { + "checkin": datetime.datetime.now(), + "checkout": datetime.datetime.now() + datetime.timedelta(days=4), + "room_type_id": self.room_type_double.id, + "partner_id": self.partner1.id, + "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, + } + # ACT + reservation1 = self.env["pms.reservation"].create(reservation_vals) + + # ASSERT + self.assertEqual( + reservation1.sale_channel_ids, + reservation1.reservation_line_ids.mapped("sale_channel_id"), + "Sale_channel_ids of reservation must be the same as " + "sale channels of its reservation lines", + ) + + @freeze_time("2000-10-24") + def test_reservation_sale_channel_origin_change_check_lines(self): + """ + Check that sale_channel_id of reservation_lines changes when + sale_channel_origin_id of its reservation has changed + """ + # ARRANGE + sale_channel_direct2 = self.env["pms.sale.channel"].create( + { + "name": "sale channel 2", + "channel_type": "direct", + } + ) + reservation_vals = { + "checkin": datetime.datetime.now(), + "checkout": datetime.datetime.now() + datetime.timedelta(days=4), + "room_type_id": self.room_type_double.id, + "partner_id": self.partner1.id, + "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, + } + reservation1 = self.env["pms.reservation"].create(reservation_vals) + + # ACT + reservation1.sale_channel_origin_id = sale_channel_direct2.id + + # ASSERT + self.assertEqual( + reservation1.sale_channel_origin_id, + reservation1.reservation_line_ids.mapped("sale_channel_id"), + "Sale_channel_id of reservation lines must also be changed", + ) + + @freeze_time("2000-10-29") + def test_reservation_lines_not_change_sale_channel(self): + """ + Check that when changing sale_channel_origin_id of a reservation, + reservation lines that didn't have the same sale_channel_id didn't + change it + + Reservation1: + --> sale_channel_origin_id : sale_channel1.id + --> reservation_lines: + --> 1: sale_channel_id: sale_channel1.id + --> 2: sale_channel_id: sale_channel1.id + --> 3: sale_channel_id: sale_channel1.id + --> 4: sale_channel_id: sale_channel_phone.id + + Change reservation1.sale_channel_origin_id = sale_channel_mail.id + + Expected result: + Reservation1: + --> sale_channel_origin_id : sale_channel_mail.id + --> reservation_lines: + --> 1: sale_channel_id: sale_channel_mail.id + --> 2: sale_channel_id: sale_channel_mail.id + --> 3: sale_channel_id: sale_channel_mail.id + --> 4: sale_channel_id: sale_channel_phone.id + + In short, sale channel of those reservations lines of the reservation + that didn't coincide with sale chanel origin that has been modified, + shouldn't be changed. That is, the last reservation_line must have + sale_channel_id = sale_channel_phone + """ + # ARRANGE + sale_channel_phone = self.env["pms.sale.channel"].create( + { + "name": "phone", + "channel_type": "direct", + } + ) + sale_channel_mail = self.env["pms.sale.channel"].create( + { + "name": "mail", + "channel_type": "direct", + } + ) + reservation_vals = { + "checkin": datetime.datetime.now(), + "checkout": datetime.datetime.now() + datetime.timedelta(days=4), + "room_type_id": self.room_type_double.id, + "partner_id": self.partner1.id, + "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, + } + reservation1 = self.env["pms.reservation"].create(reservation_vals) + + # ACT + reservation_lines = reservation1.reservation_line_ids + reservation_lines[ + len(reservation_lines) - 1 + ].sale_channel_id = sale_channel_phone.id + + reservation1.sale_channel_origin_id = sale_channel_mail + + # ASSERT + self.assertNotEqual( + reservation1.sale_channel_origin_id, + reservation_lines[len(reservation_lines) - 1].sale_channel_id, + "Sale_channel_id of that reservation line shouldn't have changed", + ) + + @freeze_time("2000-11-29") + def test_several_sale_channel_in_lines(self): + """ + Check that when a reservation has more than one sale_channel_id + in its reservation_lines, sale_channel_ids of reservation is well + calculated + """ + # ARRANGE + sale_channel_phone = self.env["pms.sale.channel"].create( + { + "name": "phone", + "channel_type": "direct", + } + ) + reservation_vals = { + "checkin": datetime.datetime.now(), + "checkout": datetime.datetime.now() + datetime.timedelta(days=4), + "room_type_id": self.room_type_double.id, + "partner_id": self.partner1.id, + "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, + } + reservation1 = self.env["pms.reservation"].create(reservation_vals) + + # ACT + reservation_lines = reservation1.reservation_line_ids + reservation_lines[0].sale_channel_id = sale_channel_phone.id + + expected_sale_channels = [] + for line in reservation_lines: + expected_sale_channels.append(line.sale_channel_id.id) + + # ASSERT + self.assertItemsEqual( + reservation1.sale_channel_ids.ids, + list(set(expected_sale_channels)), + "Sale_channel_ids of that reservation must match those of its lines", + ) + + @freeze_time("2000-12-01") + def test_reservation_no_sale_channel_origin(self): + """ + Check that you cann't create a reservation without sale_channel_origin + """ + # ACT & ASSERT + with self.assertRaises( + ValidationError, + msg="Error, it has been allowed to create a reservation without sale channel", + ): + self.env["pms.reservation"].create( + { + "room_type_id": self.room_type_double.id, + "partner_id": self.partner1.id, + "pms_property_id": self.pms_property1.id, + "checkin": datetime.datetime.now(), + "checkout": datetime.datetime.now() + datetime.timedelta(days=4), + } + ) diff --git a/pms/tests/test_pms_wizard_split_join_swap_reservation.py b/pms/tests/test_pms_wizard_split_join_swap_reservation.py index 60f2f48da..e91538492 100644 --- a/pms/tests/test_pms_wizard_split_join_swap_reservation.py +++ b/pms/tests/test_pms_wizard_split_join_swap_reservation.py @@ -64,7 +64,6 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): } ) - # UNIFY TESTS # review def test_unify_reservation_avail_should(self): """ @@ -92,7 +91,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r1.flush() @@ -129,7 +128,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r2 = self.env["pms.reservation"].create( @@ -140,7 +139,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r1 = self.env["pms.reservation"].create( @@ -151,7 +150,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "room_type_id": self.test_room_type_double.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r2.flush() @@ -177,7 +176,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r2 = self.env["pms.reservation"].create( @@ -188,7 +187,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r2.flush() @@ -230,7 +229,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r2 = self.env["pms.reservation"].create( @@ -241,7 +240,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r1.flush() @@ -291,7 +290,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r2 = self.env["pms.reservation"].create( @@ -302,7 +301,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r1.flush() @@ -351,7 +350,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r2 = self.env["pms.reservation"].create( @@ -362,7 +361,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r1.flush() @@ -415,7 +414,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r2 = self.env["pms.reservation"].create( @@ -426,7 +425,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r1.flush() @@ -479,7 +478,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r2 = self.env["pms.reservation"].create( @@ -490,7 +489,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r1.flush() @@ -540,7 +539,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -587,7 +586,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -599,7 +598,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r2 = self.env["pms.reservation"].create( @@ -610,7 +609,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r1.flush() @@ -662,7 +661,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -674,7 +673,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r2 = self.env["pms.reservation"].create( @@ -685,7 +684,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r1.flush() @@ -731,7 +730,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -769,7 +768,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r1.flush() @@ -807,7 +806,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r1.flush() @@ -854,7 +853,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r1.flush() @@ -897,7 +896,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r1.flush() @@ -937,7 +936,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r1.flush() @@ -968,7 +967,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r1.flush() @@ -998,7 +997,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room2.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r1 = self.env["pms.reservation"].create( @@ -1009,7 +1008,7 @@ class TestPmsWizardSplitJoinSwapReservation(TestPms): "adults": 2, "preferred_room_id": self.room1.id, "partner_id": self.partner1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r1.flush() diff --git a/pms/tests/test_product_template.py b/pms/tests/test_product_template.py index a2efbf624..eb61f894f 100644 --- a/pms/tests/test_product_template.py +++ b/pms/tests/test_product_template.py @@ -76,7 +76,7 @@ class TestProductTemplate(TestPms): "pms_property_id": self.pms_property1.id, "partner_id": self.partner.id, "board_service_room_id": board_service_room_type.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) # ASSERT @@ -123,7 +123,7 @@ class TestProductTemplate(TestPms): "pms_property_id": self.pms_property1.id, "partner_id": self.partner.id, "board_service_room_id": board_service_room_type.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) # ASSERT @@ -171,7 +171,7 @@ class TestProductTemplate(TestPms): "pms_property_id": self.pms_property1.id, "partner_id": self.partner.id, "board_service_room_id": board_service_room_type.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) reservation.flush() @@ -221,7 +221,7 @@ class TestProductTemplate(TestPms): "pms_property_id": self.pms_property1.id, "partner_id": self.partner.id, "board_service_room_id": board_service_room_type.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) reservation.flush() @@ -278,7 +278,7 @@ class TestProductTemplate(TestPms): "partner_id": self.partner.id, "board_service_room_id": board_service_room_type.id, "adults": 2, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -310,7 +310,7 @@ class TestProductTemplate(TestPms): "pms_property_id": self.pms_property1.id, "partner_id": self.partner.id, "service_ids": [extra_bed_service.id], - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) reservation._check_adults() diff --git a/pms/tests/test_shared_room.py b/pms/tests/test_shared_room.py index d3061b3a0..3bcb98b86 100644 --- a/pms/tests/test_shared_room.py +++ b/pms/tests/test_shared_room.py @@ -93,7 +93,6 @@ class TestPmsSharedRoom(TestPms): } ) - def test_count_avail_beds_with_room_occupied(self): """ Check that not allow to create a bed reservation with a room occupied @@ -113,7 +112,7 @@ class TestPmsSharedRoom(TestPms): "checkin": today, "checkout": tomorrow, "pms_property_id": self.pms_property1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -147,7 +146,7 @@ class TestPmsSharedRoom(TestPms): "checkin": today, "checkout": tomorrow, "pms_property_id": self.pms_property1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -193,7 +192,7 @@ class TestPmsSharedRoom(TestPms): "checkin": today, "checkout": tomorrow, "pms_property_id": self.pms_property1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -229,7 +228,7 @@ class TestPmsSharedRoom(TestPms): "checkin": today, "checkout": tomorrow, "pms_property_id": self.pms_property1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) res1.flush() @@ -263,7 +262,7 @@ class TestPmsSharedRoom(TestPms): "checkin": today, "checkout": tomorrow, "pms_property_id": self.pms_property1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -299,7 +298,7 @@ class TestPmsSharedRoom(TestPms): "checkin": today, "checkout": tomorrow, "pms_property_id": self.pms_property1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -336,7 +335,7 @@ class TestPmsSharedRoom(TestPms): "checkin": today, "checkout": tomorrow, "pms_property_id": self.pms_property1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -371,7 +370,7 @@ class TestPmsSharedRoom(TestPms): "checkin": today, "checkout": tomorrow, "pms_property_id": self.pms_property1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -387,7 +386,7 @@ class TestPmsSharedRoom(TestPms): "checkin": today, "checkout": tomorrow, "pms_property_id": self.pms_property1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r_test.flush() @@ -412,7 +411,7 @@ class TestPmsSharedRoom(TestPms): "checkin": today, "checkout": tomorrow, "pms_property_id": self.pms_property1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) @@ -429,7 +428,7 @@ class TestPmsSharedRoom(TestPms): "checkin": today, "checkout": tomorrow, "pms_property_id": self.pms_property1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r_test.flush() @@ -455,7 +454,7 @@ class TestPmsSharedRoom(TestPms): "checkin": today, "checkout": tomorrow, "pms_property_id": self.pms_property1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r1.action_cancel() @@ -492,7 +491,7 @@ class TestPmsSharedRoom(TestPms): "checkin": today, "checkout": tomorrow, "pms_property_id": self.pms_property1.id, - "sale_channel_origin_id": self.sale_channel_direct1.id + "sale_channel_origin_id": self.sale_channel_direct1.id, } ) r1.action_cancel() From cc03cc2d67f14d803c899a7f87c249fae03a85f9 Mon Sep 17 00:00:00 2001 From: Sara Lago Date: Thu, 24 Mar 2022 13:30:44 +0100 Subject: [PATCH 04/23] [IMP] pms: change sale_channel_origin of a folio when it has one reservation --- pms/models/pms_reservation.py | 5 ++++- pms/tests/test_pms_reservation.py | 36 ++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/pms/models/pms_reservation.py b/pms/models/pms_reservation.py index 70f6625f9..3cb39f257 100644 --- a/pms/models/pms_reservation.py +++ b/pms/models/pms_reservation.py @@ -2118,7 +2118,10 @@ class PmsReservation(models.Model): for res in self.filtered(lambda r: r.folio_id == folio) ) and vals["sale_channel_origin_id"] != folio.sale_channel_origin_id.id - and ("force_update_origin" in vals and vals.get("force_update_origin")) + and ( + ("force_update_origin" in vals and vals.get("force_update_origin")) + or len(folio.reservation_ids) == 1 + ) ): folios_to_update_channel += folio return folios_to_update_channel diff --git a/pms/tests/test_pms_reservation.py b/pms/tests/test_pms_reservation.py index 352693be8..44a706045 100644 --- a/pms/tests/test_pms_reservation.py +++ b/pms/tests/test_pms_reservation.py @@ -4158,7 +4158,7 @@ class TestPmsReservations(TestPms): @freeze_time("2000-12-01") def test_reservation_no_sale_channel_origin(self): """ - Check that you cann't create a reservation without sale_channel_origin + Check that you can't create a reservation without sale_channel_origin """ # ACT & ASSERT with self.assertRaises( @@ -4174,3 +4174,37 @@ class TestPmsReservations(TestPms): "checkout": datetime.datetime.now() + datetime.timedelta(days=4), } ) + + @freeze_time("2000-12-01") + def test_one_reservation_change_sale_channel_origin(self): + """ + Check that when changing the sale_channel_origin of a reservation, + sale_channel_origin of its folio changes if folio only has one reservation + """ + # ARRANGE + sale_channel_phone = self.env["pms.sale.channel"].create( + { + "name": "phone", + "channel_type": "direct", + } + ) + reservation_vals = { + "checkin": datetime.datetime.now(), + "checkout": datetime.datetime.now() + datetime.timedelta(days=4), + "room_type_id": self.room_type_double.id, + "partner_id": self.partner1.id, + "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, + } + reservation1 = self.env["pms.reservation"].create(reservation_vals) + + # ACT + reservation1.sale_channel_origin_id = sale_channel_phone.id + + # ASSERT + self.assertEqual( + reservation1.folio_id.sale_channel_origin_id, + reservation1.sale_channel_origin_id, + "Sale_channel_origin_id of folio must be the same as " + "sale_channel_origin of rservation", + ) From f98a467749697b64a4c478d7d42921adbc632ecc Mon Sep 17 00:00:00 2001 From: Sara Lago Date: Fri, 25 Mar 2022 10:32:47 +0100 Subject: [PATCH 05/23] [IMP] pms: restrict that reservation_lines haven't sale channels other than sales origin of reservation --- pms/models/pms_reservation.py | 12 +++++++++++ pms/tests/test_pms_reservation.py | 35 +++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/pms/models/pms_reservation.py b/pms/models/pms_reservation.py index 3cb39f257..ad11dd84f 100644 --- a/pms/models/pms_reservation.py +++ b/pms/models/pms_reservation.py @@ -1879,6 +1879,18 @@ class PmsReservation(models.Model): ) ) + @api.constrains("sale_channel_ids") + def _check_lines_with_sale_channel_id(self): + for record in self: + if record.reservation_line_ids: + if record.sale_channel_origin_id not in record.sale_channel_ids: + raise ValidationError( + _( + "Reservation must have one reservation line " + "with sale channel equal to sale channel origin of reservation." + "Change sale_channel_origin of reservation before" + ) + ) # Action methods def open_partner(self): """Utility method used to add an "View Customer" button in reservation views""" diff --git a/pms/tests/test_pms_reservation.py b/pms/tests/test_pms_reservation.py index 44a706045..4bb433280 100644 --- a/pms/tests/test_pms_reservation.py +++ b/pms/tests/test_pms_reservation.py @@ -1895,6 +1895,7 @@ class TestPmsReservations(TestPms): "checkout": fields.date.today() + datetime.timedelta(days=152), "agency_id": agency.id, "room_type_id": self.room_type_double.id, + "sale_channel_origin_id": self.sale_channel_direct.id } ) self.assertEqual( @@ -2610,6 +2611,7 @@ class TestPmsReservations(TestPms): "checkout": fields.date.today() + datetime.timedelta(days=152), "agency_id": agency.id, "room_type_id": self.room_type_double.id, + "sale_channel_origin_id": self.sale_channel_direct.id } ) @@ -3777,6 +3779,7 @@ class TestPmsReservations(TestPms): "pms_property_id": self.pms_property1.id, "agency_id": self.agency1.id, "service_ids": [self.service.id], + "sale_channel_origin_id": self.sale_channel_direct.id } # ACT reservation = self.env["pms.reservation"].create(reservation_vals) @@ -4208,3 +4211,35 @@ class TestPmsReservations(TestPms): "Sale_channel_origin_id of folio must be the same as " "sale_channel_origin of rservation", ) + + @freeze_time("2000-12-10") + def test_check_sale_channel_origin_in_reservation_lines(self): + """ + Check that a reservation has at least one reservation_line woth the + same sale_channel_id as its sale_channel_origin_id + """ + # ARRANGE + sale_channel_phone = self.env["pms.sale.channel"].create( + { + "name": "phone", + "channel_type": "direct", + } + ) + reservation_vals = { + "checkin": datetime.datetime.now(), + "checkout": datetime.datetime.now() + datetime.timedelta(days=1), + "room_type_id": self.room_type_double.id, + "partner_id": self.partner1.id, + "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": self.sale_channel_direct.id, + } + reservation1 = self.env["pms.reservation"].create(reservation_vals) + + # ACT & ASSERT + with self.assertRaises( + ValidationError, + msg="Error, there cannot be a reservation in which at least one of its reservation" + "lines doesn't have as sale_channel_id the sale_channel_origin_id of reservation", + ): + reservation1.reservation_line_ids.write({"sale_channel_id": sale_channel_phone}) + reservation1.flush() From 72d502aee7e6a3f5ae908ad56aba27dacd51acae Mon Sep 17 00:00:00 2001 From: Sara Lago Date: Fri, 25 Mar 2022 13:48:08 +0100 Subject: [PATCH 06/23] [IMP] pms: delete compute of sale_channel_origin through agency_id --- pms/models/pms_folio.py | 8 -------- pms/models/pms_reservation.py | 3 ++- pms/tests/test_pms_reservation.py | 12 +++++++----- pms/tests/test_pms_sale_channel.py | 1 + 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/pms/models/pms_folio.py b/pms/models/pms_folio.py index d7949ffa2..7dd29e38e 100644 --- a/pms/models/pms_folio.py +++ b/pms/models/pms_folio.py @@ -226,8 +226,6 @@ class PmsFolio(models.Model): string="Sale Channel Origin", help="Sale Channel through which folio was created, the original", comodel_name="pms.sale.channel", - store=True, - compute="_compute_sale_channel_origin_id", ) transaction_ids = fields.Many2many( @@ -1063,12 +1061,6 @@ class PmsFolio(models.Model): if reservation.commission_amount != 0: folio.commission = folio.commission + reservation.commission_amount - @api.depends("agency_id") - def _compute_sale_channel_origin_id(self): - for folio in self: - if folio.agency_id: - folio.sale_channel_origin_id = folio.agency_id.sale_channel_id.id - @api.depends("reservation_ids", "reservation_ids.sale_channel_ids") def _compute_sale_channel_ids(self): for record in self: diff --git a/pms/models/pms_reservation.py b/pms/models/pms_reservation.py index ad11dd84f..733134e44 100644 --- a/pms/models/pms_reservation.py +++ b/pms/models/pms_reservation.py @@ -1891,6 +1891,7 @@ class PmsReservation(models.Model): "Change sale_channel_origin of reservation before" ) ) + # Action methods def open_partner(self): """Utility method used to add an "View Customer" button in reservation views""" @@ -2026,7 +2027,7 @@ class PmsReservation(models.Model): vals.update(default_vals) elif ( "pms_property_id" in vals - and ("sale_channel_origin_id" in vals or "agency_id" in vals) + and "sale_channel_origin_id" in vals and ("partner_name" in vals or "partner_id" in vals or "agency_id" in vals) ): folio_vals = { diff --git a/pms/tests/test_pms_reservation.py b/pms/tests/test_pms_reservation.py index 4bb433280..85e7ad1d9 100644 --- a/pms/tests/test_pms_reservation.py +++ b/pms/tests/test_pms_reservation.py @@ -1895,7 +1895,7 @@ class TestPmsReservations(TestPms): "checkout": fields.date.today() + datetime.timedelta(days=152), "agency_id": agency.id, "room_type_id": self.room_type_double.id, - "sale_channel_origin_id": self.sale_channel_direct.id + "sale_channel_origin_id": self.sale_channel_direct.id, } ) self.assertEqual( @@ -2611,7 +2611,7 @@ class TestPmsReservations(TestPms): "checkout": fields.date.today() + datetime.timedelta(days=152), "agency_id": agency.id, "room_type_id": self.room_type_double.id, - "sale_channel_origin_id": self.sale_channel_direct.id + "sale_channel_origin_id": self.sale_channel_direct.id, } ) @@ -3779,7 +3779,7 @@ class TestPmsReservations(TestPms): "pms_property_id": self.pms_property1.id, "agency_id": self.agency1.id, "service_ids": [self.service.id], - "sale_channel_origin_id": self.sale_channel_direct.id + "sale_channel_origin_id": self.sale_channel_direct.id, } # ACT reservation = self.env["pms.reservation"].create(reservation_vals) @@ -4239,7 +4239,9 @@ class TestPmsReservations(TestPms): with self.assertRaises( ValidationError, msg="Error, there cannot be a reservation in which at least one of its reservation" - "lines doesn't have as sale_channel_id the sale_channel_origin_id of reservation", + "lines doesn't have as sale_channel_id the sale_channel_origin_id of reservation", ): - reservation1.reservation_line_ids.write({"sale_channel_id": sale_channel_phone}) + reservation1.reservation_line_ids.write( + {"sale_channel_id": sale_channel_phone} + ) reservation1.flush() diff --git a/pms/tests/test_pms_sale_channel.py b/pms/tests/test_pms_sale_channel.py index af54d5198..fc13ff813 100644 --- a/pms/tests/test_pms_sale_channel.py +++ b/pms/tests/test_pms_sale_channel.py @@ -56,6 +56,7 @@ class TestPmsSaleChannel(TestPms): "checkout": datetime.datetime.now() + datetime.timedelta(days=3), "agency_id": agency1.id, "pms_property_id": self.pms_property1.id, + "sale_channel_origin_id": sale_channel1.id, } ) From 2cb36f1a50f2a94002d935cfb56ec2bd425e941c Mon Sep 17 00:00:00 2001 From: Sara Lago Date: Fri, 25 Mar 2022 14:51:40 +0100 Subject: [PATCH 07/23] [IMP] pms: add demo data for multiple sale channels --- pms/demo/pms_folio.xml | 165 +++++++++++++++++------ pms/demo/pms_reservation.xml | 245 ++++++++++++++++++++++++++++------- 2 files changed, 320 insertions(+), 90 deletions(-) diff --git a/pms/demo/pms_folio.xml b/pms/demo/pms_folio.xml index f4630eebd..9846195a4 100644 --- a/pms/demo/pms_folio.xml +++ b/pms/demo/pms_folio.xml @@ -22,13 +22,17 @@ })]" /> - + + - + + + + Each guest pays his bill - + - + + out - + - + + Do not allow guests to pay anything. The company pays for everything. @@ -269,6 +300,7 @@ 'checkout': (DateTime.today() + timedelta(days=18)), 'adults': 1, 'state': 'confirm', + 'sale_channel_origin_id': ref('pms.main_pms_sale_channel_door') }), (0, 0, { 'pricelist_id': ref('product.list0'), @@ -285,6 +317,7 @@ 'checkout': (DateTime.today() + timedelta(days=18)), 'adults': 1, 'state': 'confirm', + 'sale_channel_origin_id': ref('pms.main_pms_sale_channel_mail') }), (0, 0, { 'pricelist_id': ref('product.list0'), @@ -309,6 +342,7 @@ 'checkout': (DateTime.today() + timedelta(days=18)), 'adults': 3, 'state': 'confirm', + 'sale_channel_origin_id': ref('pms.main_pms_sale_channel_mail') }), (0, 0, { 'pricelist_id': ref('product.list0'), @@ -325,6 +359,11 @@ + + out - + - + Each guest pays his bill - + Each guest pays his bill @@ -427,7 +474,7 @@ - + normal - + normal - + normal + cancel - - - - normal - - - - + + + + + + + + + + + + + + + + + + + + + + + + Each guest pays his bill @@ -571,7 +629,7 @@ - + Each guest pays his bill @@ -611,7 +670,7 @@ - + Each guest pays his bill + Each guest pays his bill - + - + - + - + + - + - + - + + Carpet replacement. + @@ -49,6 +50,7 @@ Wall painting. + @@ -65,7 +67,7 @@ ref="pms_board_service_room_eco_full_board" /> - + done - + done @@ -124,7 +126,7 @@ ref="pms_board_service_room_eco_full_board" /> - + done Breakfast at 5:00 am. @@ -158,7 +160,7 @@ ref="pms_board_service_room_eco_full_board" /> - + done @@ -185,7 +187,7 @@ ref="pms_board_service_room_eco_full_board" /> - + done @@ -212,7 +214,7 @@ ref="pms_board_service_room_eco_full_board" /> - + done Need lunchs to take away. @@ -255,6 +257,10 @@ /> + @@ -265,6 +271,10 @@ + Need 1 extra towel. @@ -275,7 +285,7 @@ - + @@ -285,7 +295,10 @@ - + Need 2 extra towel. @@ -297,6 +310,10 @@ + @@ -307,7 +324,7 @@ - + Need 2 extra towels. Friend of manager @@ -325,7 +342,7 @@ - + @@ -338,6 +355,10 @@ + Preferably street view. @@ -350,7 +371,10 @@ - + @@ -367,7 +391,7 @@ ref="pms_board_service_room_single_full_board" /> - + done Late for dinner. Cold dinner needed. @@ -395,7 +419,7 @@ ref="pms_board_service_room_single_full_board" /> - + done @@ -458,7 +482,7 @@ ref="pms_board_service_room_single_full_board" /> - + breakfast at 5:00 am @@ -484,6 +508,10 @@ /> + @@ -499,7 +527,7 @@ ref="pms_board_service_room_single_full_board" /> - + Breakfast to take away. @@ -517,6 +545,10 @@ /> + @@ -529,6 +561,10 @@ + preferably street view @@ -541,7 +577,10 @@ - + @@ -555,6 +594,10 @@ + Preferably street view. @@ -567,7 +610,10 @@ - + @@ -581,7 +627,7 @@ - + - + 1 bottle of champagne upon check-in @@ -620,7 +666,7 @@ - + @@ -637,6 +683,10 @@ /> + 3 extra towels @@ -649,7 +699,10 @@ - + @@ -666,6 +719,10 @@ /> + Vegan breakfast @@ -686,6 +743,10 @@ + @@ -701,7 +762,7 @@ ref="pms_board_service_room_double_half_board" /> - + Help needed with the luggage. @@ -719,7 +780,7 @@ ref="pms_board_service_room_double_breakfast" /> - + @@ -732,7 +793,10 @@ - + Need 1 extra set of bedclothes @@ -744,6 +808,10 @@ 2 + - + welcome cocktail @@ -785,7 +853,7 @@ ref="pms_board_service_room_triple_full_board" /> - + done @@ -828,6 +896,10 @@ /> + Vegetarian food for all guests. @@ -839,6 +911,10 @@ + @@ -858,7 +934,7 @@ - + 3 set of keys needed. @@ -879,7 +955,10 @@ - + @@ -902,7 +981,7 @@ ref="pms_board_service_room_triple_breakfast" /> - + Celiac breakfast @@ -919,7 +998,7 @@ ref="pms_board_service_room_triple_full_board" /> - + @@ -930,6 +1009,10 @@ + room with low noise 24x7 @@ -941,7 +1024,7 @@ - + done @@ -963,6 +1046,10 @@ + done - + done @@ -1008,6 +1098,10 @@ + Allergic to chemicals done @@ -1030,6 +1124,10 @@ + @@ -1039,8 +1137,25 @@ - + Hard mattress needed. + @@ -1050,7 +1165,7 @@ - + @@ -1065,7 +1180,7 @@ 0 paid - + done 2 bottles of water each 2 hours. @@ -1089,6 +1204,10 @@ + @@ -1099,8 +1218,21 @@ - + Projector needed + @@ -1111,7 +1243,10 @@ - + @@ -1122,7 +1257,10 @@ - + done @@ -1143,7 +1281,7 @@ - + Need 1 extra shampoo done @@ -1165,7 +1303,7 @@ - + done @@ -1186,7 +1324,10 @@ - + Welcome cocktail. @@ -1197,7 +1338,7 @@ - + @@ -1207,7 +1348,7 @@ - + Basket fruit at bedroom @@ -1219,7 +1360,10 @@ - + done @@ -1240,7 +1384,7 @@ - + allergic to chemicals done @@ -1262,7 +1406,7 @@ - + done @@ -1283,7 +1427,10 @@ - + Smoking room. @@ -1294,7 +1441,7 @@ - + @@ -1304,7 +1451,7 @@ - + two bottles of moët From 1d22a5c4e999c7afad5ee6880c0f9d3e2caac078 Mon Sep 17 00:00:00 2001 From: Sara Lago Date: Fri, 25 Mar 2022 17:04:16 +0100 Subject: [PATCH 08/23] [IMP] pms: add condition in which force_update_origin is hidden --- pms/models/pms_reservation.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pms/models/pms_reservation.py b/pms/models/pms_reservation.py index 733134e44..9775a21de 100644 --- a/pms/models/pms_reservation.py +++ b/pms/models/pms_reservation.py @@ -1654,6 +1654,7 @@ class PmsReservation(models.Model): if ( record.sale_channel_origin_id != record.folio_id.sale_channel_origin_id and record.folio_id + and isinstance(self.id, int) ): record.is_origin_channel_check_visible = True else: From a892096acacb0df10ebd13bec67708e83031b7f4 Mon Sep 17 00:00:00 2001 From: Sara Lago Date: Fri, 8 Apr 2022 18:16:43 +0200 Subject: [PATCH 09/23] [IMP] pms: add multiple sale channel in pms_service and pms_service_line --- pms/models/pms_service.py | 88 ++++++++++++++++++++++++---- pms/models/pms_service_line.py | 15 +++++ pms/views/pms_service_line_views.xml | 2 + pms/views/pms_service_views.xml | 9 +++ 4 files changed, 103 insertions(+), 11 deletions(-) diff --git a/pms/models/pms_service.py b/pms/models/pms_service.py index 36111a3e0..ed1e5902d 100644 --- a/pms/models/pms_service.py +++ b/pms/models/pms_service.py @@ -146,17 +146,19 @@ class PmsService(models.Model): ("no", "Nothing to Invoice"), ], ) - channel_type = fields.Selection( - string="Sales Channel", - help="sales channel through which the service was sold." - "It can be 'door', 'mail', 'phone', 'call' or 'web'", - selection=[ - ("door", "Door"), - ("mail", "Mail"), - ("phone", "Phone"), - ("call", "Call Center"), - ("web", "Web"), - ], + sale_channel_ids = fields.Many2many( + string="Sale Channels", + help="Sale Channels through which service lines were managed", + store=True, + compute="_compute_sale_channel_ids", + comodel_name="pms.sale.channel", + check_pms_properties=True, + ) + sale_channel_origin_id = fields.Many2one( + string="Sale Channel Origin", + help="Sale Channel through which service was created, the original", + comodel_name="pms.sale.channel", + check_pms_properties=True, ) price_subtotal = fields.Monetary( string="Subtotal", @@ -425,6 +427,13 @@ class PmsService(models.Model): line.discount = record.discount line.cancel_discount = 0 + @api.depends("service_line_ids", "service_line_ids.sale_channel_id") + def _compute_sale_channel_ids(self): + for record in self: + record.sale_channel_ids = [ + (6, 0, record.mapped("service_line_ids.sale_channel_id.id")) + ] + def name_get(self): result = [] for rec in self: @@ -534,3 +543,60 @@ class PmsService(models.Model): ) else: return 0 + + @api.model + def create(self, vals): + if vals.get("reservation_id") and not vals.get("sale_channel_origin_id"): + reservation = self.env["pms.reservation"].browse(vals["reservation_id"]) + if reservation.sale_channel_origin_id: + vals["sale_channel_origin_id"] = reservation.sale_channel_origin_id.id + elif ( + vals.get("folio_id") + and not vals.get("reservation_id") + and not vals.get("sale_channel_origin_id") + ): + folio = self.env["pms.folio"].browse(vals["folio_id"]) + if folio.sale_channel_origin_id: + vals["sale_channel_origin_id"] = folio.sale_channel_origin_id.id + record = super(PmsService, self).create(vals) + return record + + def write(self, vals): + folios_to_update_channel = self.env["pms.folio"] + lines_to_update_channel = self.env["pms.service.line"] + if "sale_channel_origin_id" in vals: + folios_to_update_channel = self.get_folios_to_update_channel(vals) + lines_to_update_channel = self.get_service_lines_to_update_channel(vals) + res = super(PmsService, self).write(vals) + if folios_to_update_channel: + folios_to_update_channel.sale_channel_origin_id = vals[ + "sale_channel_origin_id" + ] + if lines_to_update_channel: + lines_to_update_channel.sale_channel_id = vals["sale_channel_origin_id"] + return res + + def get_folios_to_update_channel(self, vals): + folios_to_update_channel = self.env["pms.folio"] + for folio in self.mapped("folio_id"): + if ( + any( + service.sale_channel_origin_id == folio.sale_channel_origin_id + for service in self.filtered(lambda r: r.folio_id == folio) + ) + and vals["sale_channel_origin_id"] != folio.sale_channel_origin_id.id + and (len(folio.reservation_ids) == 0) + and (len(folio.service_ids) == 1) + ): + folios_to_update_channel += folio + return folios_to_update_channel + + def get_service_lines_to_update_channel(self, vals): + lines_to_update_channel = self.env["pms.service.line"] + for record in self: + for service_line in record.service_line_ids: + if service_line.sale_channel_id == self.sale_channel_origin_id and ( + vals["sale_channel_origin_id"] != service_line.sale_channel_id.id + ): + lines_to_update_channel += service_line + return lines_to_update_channel diff --git a/pms/models/pms_service_line.py b/pms/models/pms_service_line.py index 11933b16d..1d8b4b5a7 100644 --- a/pms/models/pms_service_line.py +++ b/pms/models/pms_service_line.py @@ -126,6 +126,12 @@ class PmsServiceLine(models.Model): readonly=True, store=True, ) + sale_channel_id = fields.Many2one( + string="Sale Channel", + help="Sale Channel through which service line was created", + comodel_name="pms.sale.channel", + check_pms_properties=True, + ) auto_qty = fields.Boolean( string="Qty automated setted", help="Show if the day qty was calculated automatically", @@ -249,6 +255,15 @@ class PmsServiceLine(models.Model): % (record.service_id.product_id.name, record.date) ) + @api.model + def create(self, vals): + if vals.get("service_id") and not vals.get("sale_channel_id"): + service = self.env["pms.service"].browse(vals["service_id"]) + if service.sale_channel_origin_id: + vals["sale_channel_id"] = service.sale_channel_origin_id.id + record = super(PmsServiceLine, self).create(vals) + return record + # Business methods def _cancel_discount(self): for record in self: diff --git a/pms/views/pms_service_line_views.xml b/pms/views/pms_service_line_views.xml index 7480d5890..decce7e04 100644 --- a/pms/views/pms_service_line_views.xml +++ b/pms/views/pms_service_line_views.xml @@ -9,6 +9,7 @@ + + + + + @@ -35,6 +38,7 @@ + + @@ -85,6 +90,8 @@ attrs="{'readonly': [('per_day','=',True)]}" force_save="1" /> + +