From 72d502aee7e6a3f5ae908ad56aba27dacd51acae Mon Sep 17 00:00:00 2001 From: Sara Lago Date: Fri, 25 Mar 2022 13:48:08 +0100 Subject: [PATCH] [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, } )