From dc725d4a1eea239da12bf90943d288c8b5cba4ed Mon Sep 17 00:00:00 2001 From: braisab Date: Mon, 9 Aug 2021 19:39:00 +0200 Subject: [PATCH] [REF]pms: Change related reservation_type to compute in pms.reservation --- pms/models/pms_reservation.py | 13 +++- pms/models/pms_service.py | 67 ++++++++++---------- pms/tests/test_pms_folio.py | 98 ----------------------------- pms/views/pms_folio_views.xml | 20 +++++- pms/views/pms_reservation_views.xml | 23 ++++++- 5 files changed, 87 insertions(+), 134 deletions(-) diff --git a/pms/models/pms_reservation.py b/pms/models/pms_reservation.py index 33a54c5e0..aafc89f4d 100644 --- a/pms/models/pms_reservation.py +++ b/pms/models/pms_reservation.py @@ -342,9 +342,10 @@ class PmsReservation(models.Model): reservation_type = fields.Selection( string="Reservation Type", help="Type of reservations. It can be 'normal', 'staff' or 'out of service", - related="folio_id.reservation_type", store=True, readonly=False, + compute="_compute_reservation_type", + selection=[("normal", "Normal"), ("staff", "Staff"), ("out", "Out of Service")], ) splitted = fields.Boolean( string="Splitted", @@ -1352,6 +1353,14 @@ class PmsReservation(models.Model): else: reservation.rooms = reservation.preferred_room_id.name + @api.depends("folio_id", "folio_id.reservation_type") + def _compute_reservation_type(self): + for record in self: + if record.folio_id: + record.reservation_type = record.folio_id.reservation_type + else: + record.reservation_type = "normal" + def _search_allowed_checkin(self, operator, value): if operator not in ("=",): raise UserError( @@ -1644,6 +1653,8 @@ class PmsReservation(models.Model): raise ValidationError(_("Partner contact name is required")) # Create the folio in case of need # (To allow to create reservations direct) + if vals.get("reservation_type"): + folio_vals["reservation_type"] = vals.get("reservation_type") folio = self.env["pms.folio"].create(folio_vals) vals.update( { diff --git a/pms/models/pms_service.py b/pms/models/pms_service.py index af621271a..bd0c8492a 100644 --- a/pms/models/pms_service.py +++ b/pms/models/pms_service.py @@ -547,35 +547,38 @@ class PmsService(models.Model): def _get_price_unit_line(self, date=False): self.ensure_one() - folio = self.folio_id - reservation = self.reservation_id - origin = reservation if reservation else folio - if origin: - partner = origin.partner_id - pricelist = origin.pricelist_id - board_room_type = False - product_context = dict( - self.env.context, - lang=partner.lang, - partner=partner.id, - quantity=self.product_qty, - date=folio.date_order if folio else fields.Date.today(), - pricelist=pricelist.id, - board_service=board_room_type.id if board_room_type else False, - uom=self.product_id.uom_id.id, - fiscal_position=False, - property=self.reservation_id.pms_property_id.id, - ) - if date: - product_context["consumption_date"] = date - if reservation and self.is_board_service: - product_context["board_service"] = reservation.board_service_room_id.id - product = self.product_id.with_context(product_context) - return self.env["account.tax"]._fix_tax_included_price_company( - self._get_display_price(product), - product.taxes_id, - self.tax_ids, - origin.company_id, - ) - else: - return 0 + if self.reservation_id.reservation_type == "normal": + folio = self.folio_id + reservation = self.reservation_id + origin = reservation if reservation else folio + if origin: + partner = origin.partner_id + pricelist = origin.pricelist_id + board_room_type = False + product_context = dict( + self.env.context, + lang=partner.lang, + partner=partner.id, + quantity=self.product_qty, + date=folio.date_order if folio else fields.Date.today(), + pricelist=pricelist.id, + board_service=board_room_type.id if board_room_type else False, + uom=self.product_id.uom_id.id, + fiscal_position=False, + property=self.reservation_id.pms_property_id.id, + ) + if date: + product_context["consumption_date"] = date + if reservation and self.is_board_service: + product_context[ + "board_service" + ] = reservation.board_service_room_id.id + product = self.product_id.with_context(product_context) + return self.env["account.tax"]._fix_tax_included_price_company( + self._get_display_price(product), + product.taxes_id, + self.tax_ids, + origin.company_id, + ) + else: + return 0 diff --git a/pms/tests/test_pms_folio.py b/pms/tests/test_pms_folio.py index 08849b9c3..dc2911d33 100644 --- a/pms/tests/test_pms_folio.py +++ b/pms/tests/test_pms_folio.py @@ -371,104 +371,6 @@ class TestPmsFolio(TestPms): "The default reservation type of the folio should be 'normal'", ) - def test_staff_reservation_type_folio(self): - """ - Check that the reservation type field of a folio is equal - to 'staff', if your reservations also have this field - as 'staff'. - --------------- - A folio is created. A reservation is created to which the - value of the folio_id is the id of the previously created - folio and the field reservation_type equal to 'staff'. A - second reservation with the same folio_id and reservation_type - is created. Then it is verified that the value of the reservation_type - field of the folio is 'staff'. - """ - # ARRANGE AND ACT - self.partner1 = self.env["res.partner"].create({"name": "Ana"}) - folio1 = self.env["pms.folio"].create( - { - "pms_property_id": self.pms_property1.id, - "partner_id": self.partner1.id, - } - ) - - self.env["pms.reservation"].create( - { - "room_type_id": self.room_type_double.id, - "checkin": fields.date.today(), - "checkout": fields.date.today() + datetime.timedelta(days=1), - "folio_id": folio1.id, - "reservation_type": "staff", - } - ) - - self.env["pms.reservation"].create( - { - "room_type_id": self.room_type_double.id, - "checkin": fields.date.today(), - "checkout": fields.date.today() + datetime.timedelta(days=1), - "folio_id": folio1.id, - "reservation_type": "staff", - } - ) - - # ASSERT - self.assertEqual( - folio1.reservation_type, - "staff", - "The reservation type of the folio should be 'staff'", - ) - - def test_out_reservation_type_folio(self): - """ - Check that the reservation type field of a folio is equal - to 'out', if your reservations also have this field - as 'out'. - --------------- - A folio is created. A reservation is created to which the - value of the folio_id is the id of the previously created - folio and the field reservation_type equal to 'out'. A - second reservation with the same folio_id and reservation_type - is created. Then it is verified that the value of the reservation_type - field of the folio is 'out'. - """ - # ARRANGE AND ACT - self.partner1 = self.env["res.partner"].create({"name": "Ana"}) - folio1 = self.env["pms.folio"].create( - { - "pms_property_id": self.pms_property1.id, - "partner_id": self.partner1.id, - } - ) - - self.env["pms.reservation"].create( - { - "room_type_id": self.room_type_double.id, - "checkin": fields.date.today(), - "checkout": fields.date.today() + datetime.timedelta(days=1), - "folio_id": folio1.id, - "reservation_type": "out", - } - ) - - self.env["pms.reservation"].create( - { - "room_type_id": self.room_type_double.id, - "checkin": fields.date.today(), - "checkout": fields.date.today() + datetime.timedelta(days=1), - "folio_id": folio1.id, - "reservation_type": "out", - } - ) - - # ASSERT - self.assertEqual( - folio1.reservation_type, - "out", - "The reservation type of the folio should be 'out'", - ) - def test_invoice_status_staff_reservation(self): """ Check that the value of the invoice_status field is 'no' diff --git a/pms/views/pms_folio_views.xml b/pms/views/pms_folio_views.xml index a37bc388a..2dfb29d07 100644 --- a/pms/views/pms_folio_views.xml +++ b/pms/views/pms_folio_views.xml @@ -186,6 +186,19 @@ bg_color="bg-warning" attrs="{'invisible': [('payment_state', '!=', 'partial')]}" /> + + +

@@ -542,12 +555,17 @@ decoration-muted="state == 'cancel'" default_order="create_date desc" > - + + + + +
+ - +