From 5fd5a5008a7ebbc179b18c114021130b4f972630 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Lodeiros?= Date: Tue, 19 Oct 2021 08:16:35 +0200 Subject: [PATCH 01/27] [IMP]pms: compute precheckin partner mandatory state --- pms/models/pms_checkin_partner.py | 13 ++++------ pms_l10n_es/models/__init__.py | 1 + pms_l10n_es/models/pms_checkin_partner.py | 30 +++++++++++++++++++++++ 3 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 pms_l10n_es/models/pms_checkin_partner.py diff --git a/pms/models/pms_checkin_partner.py b/pms/models/pms_checkin_partner.py index a44a21b1b..074c31625 100644 --- a/pms/models/pms_checkin_partner.py +++ b/pms/models/pms_checkin_partner.py @@ -325,10 +325,12 @@ class PmsCheckinPartner(models.Model): record.state = "draft" if record.reservation_id.state == "cancel": record.state = "cancel" - elif record.state in ("draft", "cancel"): + elif record.state in ("draft", "precheckin", "cancel"): if any( not getattr(record, field) - for field in record._checkin_mandatory_fields() + for field in record._checkin_mandatory_fields( + country=record.nationality_id + ) ): record.state = "draft" else: @@ -610,14 +612,9 @@ class PmsCheckinPartner(models.Model): return res @api.model - def _checkin_mandatory_fields(self, depends=False): + def _checkin_mandatory_fields(self, country=False, depends=False): mandatory_fields = [ "name", - "birthdate_date", - "gender", - "document_number", - "document_type", - "document_expedition_date", ] # api.depends need "reservation_id.state" in the lambda function if depends: diff --git a/pms_l10n_es/models/__init__.py b/pms_l10n_es/models/__init__.py index 57f5a9944..a49c8ae2d 100644 --- a/pms_l10n_es/models/__init__.py +++ b/pms_l10n_es/models/__init__.py @@ -6,3 +6,4 @@ from . import res_country_state from . import pms_ine_tourism_type_category from . import pms_room from . import res_partner +from . import pms_checkin_partner diff --git a/pms_l10n_es/models/pms_checkin_partner.py b/pms_l10n_es/models/pms_checkin_partner.py new file mode 100644 index 000000000..191c5e9f9 --- /dev/null +++ b/pms_l10n_es/models/pms_checkin_partner.py @@ -0,0 +1,30 @@ +import logging + +from odoo import api, models + +CODE_SPAIN = "ES" + +_logger = logging.getLogger(__name__) + + +class PmsCheckinParnert(models.Model): + _inherit = "pms.checkin.partner" + + @api.model + def _checkin_mandatory_fields(self, country=False, depends=False): + mandatory_fields = super(PmsCheckinParnert, self)._checkin_mandatory_fields( + depends + ) + mandatory_fields.extend( + [ + "birthdate_date", + "gender", + "document_number", + "document_type", + "document_expedition_date", + "nationality_id", + ] + ) + if depends or (country and country.code == CODE_SPAIN): + mandatory_fields.append("state_id") + return mandatory_fields From 674b72b4fe35169e28aaafbe42ced1eeb4ee27b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Lodeiros?= Date: Sat, 23 Oct 2021 18:19:10 +0200 Subject: [PATCH 02/27] [IMP]pms: add default quota & max_avail to room type view form --- pms/views/pms_room_type_views.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pms/views/pms_room_type_views.xml b/pms/views/pms_room_type_views.xml index e88714a4b..4002aad35 100644 --- a/pms/views/pms_room_type_views.xml +++ b/pms/views/pms_room_type_views.xml @@ -39,6 +39,8 @@ + + Date: Sat, 23 Oct 2021 19:33:20 +0200 Subject: [PATCH 03/27] [IMP]pms: improvements availability compute --- pms/models/pms_property.py | 28 +++++++++++++-- pms/models/pms_reservation.py | 36 ++++++++++++++----- pms/models/pms_reservation_line.py | 6 +++- pms/models/pms_room_type.py | 4 +++ pms/models/pms_room_type_class.py | 5 +++ pms/views/pms_room_type_class_views.xml | 1 + .../wizard_split_join_swap_reservation.py | 6 ++++ 7 files changed, 74 insertions(+), 12 deletions(-) diff --git a/pms/models/pms_property.py b/pms/models/pms_property.py index 27dcfcb56..9f031cec0 100644 --- a/pms/models/pms_property.py +++ b/pms/models/pms_property.py @@ -151,16 +151,20 @@ class PmsProperty(models.Model): @api.depends_context( "checkin", "checkout", + "real_avail", "room_type_id", "ubication_id", "capacity", "amenity_ids", "pricelist_id", + "class_id", + "overnight_rooms", "current_lines", ) def _compute_free_room_ids(self): checkin = self._context["checkin"] checkout = self._context["checkout"] + if isinstance(checkin, str): checkin = datetime.datetime.strptime( checkin, DEFAULT_SERVER_DATE_FORMAT @@ -175,11 +179,14 @@ class PmsProperty(models.Model): pricelist_id = self.env.context.get("pricelist_id", False) room_type_id = self.env.context.get("room_type_id", False) + class_id = self._context.get("class_id", False) + real_avail = self._context.get("real_avail", False) + overnight_rooms = self._context.get("overnight_rooms", False) for pms_property in self: free_rooms = pms_property.get_real_free_rooms( checkin, checkout, current_lines ) - if pricelist_id: + if pricelist_id and not real_avail: # TODO: only closed_departure take account checkout date! domain_rules = [ ("date", ">=", checkin), @@ -208,6 +215,14 @@ class PmsProperty(models.Model): free_rooms = free_rooms.filtered( lambda x: x.room_type_id.id not in room_types_to_remove ) + if class_id: + free_rooms = free_rooms.filtered( + lambda x: x.room_type_id.class_id.id == class_id + ) + if overnight_rooms: + free_rooms = free_rooms.filtered( + lambda x: x.room_type_id.overnight_room + ) if len(free_rooms) > 0: pms_property.free_room_ids = free_rooms.ids else: @@ -261,11 +276,14 @@ class PmsProperty(models.Model): @api.depends_context( "checkin", "checkout", + "real_avail", "room_type_id", "ubication_id", "capacity", "amenity_ids", "pricelist_id", + "class_id", + "overnight_rooms", "current_lines", ) def _compute_availability(self): @@ -283,12 +301,18 @@ class PmsProperty(models.Model): room_type_id = self.env.context.get("room_type_id", False) pricelist_id = self.env.context.get("pricelist_id", False) current_lines = self.env.context.get("current_lines", []) + class_id = self._context.get("class_id", False) + real_avail = self._context.get("real_avail", False) + overnight_rooms = self._context.get("overnight_rooms", False) pms_property = record.with_context( checkin=checkin, checkout=checkout, room_type_id=room_type_id, current_lines=current_lines, pricelist_id=pricelist_id, + class_id=class_id, + real_avail=real_avail, + overnight_rooms=overnight_rooms, ) count_free_rooms = len(pms_property.free_room_ids) if current_lines and not isinstance(current_lines, list): @@ -305,7 +329,7 @@ class PmsProperty(models.Model): pricelist = False if pricelist_id: pricelist = self.env["product.pricelist"].browse(pricelist_id) - if pricelist and pricelist.availability_plan_id: + if pricelist and pricelist.availability_plan_id and not real_avail: domain_rules.append( ("availability_plan_id", "=", pricelist.availability_plan_id.id) ) diff --git a/pms/models/pms_reservation.py b/pms/models/pms_reservation.py index afeefcf4e..40c3d116d 100644 --- a/pms/models/pms_reservation.py +++ b/pms/models/pms_reservation.py @@ -643,7 +643,6 @@ class PmsReservation(models.Model): comodel_name="res.partner", inverse_name="reservation_possible_customer_id", ) - is_mail_send = fields.Boolean(string="Mail Sent", default=False) is_modified_reservation = fields.Boolean( @@ -652,7 +651,10 @@ class PmsReservation(models.Model): readonly=False, store=True, ) - + overnight_room = fields.Boolean( + related="room_type_id.overnight_room", + store=True, + ) lang = fields.Many2one( string="Language", comodel_name="res.lang", compute="_compute_lang" ) @@ -804,6 +806,7 @@ class PmsReservation(models.Model): "reservation_line_ids.room_id", "reservation_line_ids.occupies_availability", "preferred_room_id", + "room_type_id", "pricelist_id", "pms_property_id", ) @@ -812,7 +815,9 @@ class PmsReservation(models.Model): if reservation.checkin and reservation.checkout: if reservation.overbooking or reservation.state in ("cancel"): reservation.allowed_room_ids = self.env["pms.room"].search( - [("active", "=", True)] + [ + ("active", "=", True), + ] ) return pms_property = reservation.pms_property_id @@ -822,9 +827,12 @@ class PmsReservation(models.Model): room_type_id=False, # Allows to choose any available room current_lines=reservation.reservation_line_ids.ids, pricelist_id=reservation.pricelist_id.id, + class_id=reservation.room_type_id.class_id + if reservation.room_type_id + else False, + real_avail=True, ) reservation.allowed_room_ids = pms_property.free_room_ids - else: reservation.allowed_room_ids = False @@ -1045,6 +1053,7 @@ class PmsReservation(models.Model): True if ( record.reservation_type != "out" + and record.overnight_room and record.state in ["draft", "confirm", "arrival_delayed"] and record.checkin <= fields.Date.today() ) @@ -1197,9 +1206,11 @@ class PmsReservation(models.Model): reservation.commission_amount = 0 # REVIEW: Dont run with set room_type_id -> room_id(compute)-> No set adults¿? - @api.depends("preferred_room_id", "reservation_type") + @api.depends("preferred_room_id", "reservation_type", "overnight_room") def _compute_adults(self): for reservation in self: + if not reservation.overnight_room: + reservation.adults = 0 if reservation.preferred_room_id and reservation.reservation_type != "out": if reservation.adults == 0: reservation.adults = reservation.preferred_room_id.capacity @@ -1384,7 +1395,7 @@ class PmsReservation(models.Model): def _compute_checkin_partner_count(self): for record in self: - if record.reservation_type != "out": + if record.reservation_type != "out" and record.overnight_room: record.checkin_partner_count = len(record.checkin_partner_ids) record.checkin_partner_pending_count = record.adults - len( record.checkin_partner_ids @@ -1488,6 +1499,7 @@ class PmsReservation(models.Model): return [ ("state", "in", ("draft", "confirm", "arrival_delayed")), ("checkin", "<=", today), + ("adults", ">", 0), ] def _search_allowed_checkout(self, operator, value): @@ -1505,6 +1517,7 @@ class PmsReservation(models.Model): return [ ("state", "in", ("onboard", "departure_delayed")), ("checkout", ">=", today), + ("adults", ">", 0), ] def _search_allowed_cancel(self, operator, value): @@ -2014,7 +2027,9 @@ class PmsReservation(models.Model): ("checkin", "<", fields.Date.today()), ] ) - arrival_delayed_reservations.state = "arrival_delayed" + for record in arrival_delayed_reservations: + if record.overnight_room: + record.state = "arrival_delayed" @api.model def auto_departure_delayed(self): @@ -2026,8 +2041,11 @@ class PmsReservation(models.Model): ] ) for reservation in reservations: - if reservation.checkout_datetime <= fields.Datetime.now(): - reservations.state = "departure_delayed" + if reservation.overnight_room: + if reservation.checkout_datetime <= fields.Datetime.now(): + reservations.state = "departure_delayed" + else: + reservation.state = "done" def preview_reservation(self): self.ensure_one() diff --git a/pms/models/pms_reservation_line.py b/pms/models/pms_reservation_line.py index f9152badb..4eae1780c 100644 --- a/pms/models/pms_reservation_line.py +++ b/pms/models/pms_reservation_line.py @@ -112,7 +112,10 @@ class PmsReservationLine(models.Model): store=True, compute="_compute_impacts_quota", ) - + overnight_room = fields.Boolean( + related="reservation_id.overnight_room", + store=True, + ) _sql_constraints = [ ( "rule_availability", @@ -184,6 +187,7 @@ class PmsReservationLine(models.Model): else False, current_lines=reservation.reservation_line_ids.ids, pricelist_id=reservation.pricelist_id.id, + real_avail=True, ) rooms_available = pms_property.free_room_ids diff --git a/pms/models/pms_room_type.py b/pms/models/pms_room_type.py index 116b00caa..b97cb1fa1 100644 --- a/pms/models/pms_room_type.py +++ b/pms/models/pms_room_type.py @@ -86,6 +86,10 @@ class PmsRoomType(models.Model): "Use `-1` for managing no quota.", default=-1, ) + overnight_room = fields.Boolean( + related="class_id.overnight", + store=True, + ) def name_get(self): result = [] diff --git a/pms/models/pms_room_type_class.py b/pms/models/pms_room_type_class.py index 179315ec7..6c4a07e65 100644 --- a/pms/models/pms_room_type_class.py +++ b/pms/models/pms_room_type_class.py @@ -57,6 +57,11 @@ class PmsRoomTypeClass(models.Model): help="Room type class identification code", required=True, ) + overnight = fields.Boolean( + string="Use for overnight stays", + help="Set False if if these types of spaces are not used for overnight stays", + default=True, + ) @api.model def get_unique_by_property_code(self, pms_property_id, default_code=None): diff --git a/pms/views/pms_room_type_class_views.xml b/pms/views/pms_room_type_class_views.xml index fc13f2bad..e5bcec16d 100644 --- a/pms/views/pms_room_type_class_views.xml +++ b/pms/views/pms_room_type_class_views.xml @@ -29,6 +29,7 @@ /> + diff --git a/pms/wizards/wizard_split_join_swap_reservation.py b/pms/wizards/wizard_split_join_swap_reservation.py index 77cce5867..d11220db6 100644 --- a/pms/wizards/wizard_split_join_swap_reservation.py +++ b/pms/wizards/wizard_split_join_swap_reservation.py @@ -179,6 +179,7 @@ class ReservationSplitJoinSwapWizard(models.TransientModel): room_type_id=False, # Allows to choose any available room current_lines=record.reservation_id.reservation_line_ids.ids, pricelist_id=record.reservation_id.pricelist_id.id, + real_avail=True, ) rooms_available = pms_property.free_room_ids @@ -224,6 +225,8 @@ class ReservationSplitJoinSwapWizard(models.TransientModel): ).date(), current_lines=reservation.reservation_line_ids.ids, pricelist_id=reservation.pricelist_id.id, + real_avail=True, + class_id=reservation.room_type_id.class_id, ) rooms_available = pms_property.free_room_ids @@ -242,6 +245,7 @@ class ReservationSplitJoinSwapWizard(models.TransientModel): checkout=reservation.checkout, current_lines=reservation.reservation_line_ids.ids, pricelist_id=reservation.pricelist_id.id, + real_avail=True, ) rooms_available = pms_property.free_room_ids @@ -360,6 +364,8 @@ class ReservationLinesToSplit(models.TransientModel): checkout=line.date + datetime.timedelta(days=1), room_type_id=False, # Allows to choose any available room pricelist_id=reservation.pricelist_id.id, + real_avail=True, + class_id=reservation.room_type_id.class_id, ) rooms_available = pms_property.free_room_ids rooms_available += line.room_id From 312a27f0be846307ce252763c5f30b175542877c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Lodeiros?= Date: Sun, 24 Oct 2021 10:52:14 +0200 Subject: [PATCH 04/27] [FIX]pms: tests availability --- pms/models/pms_reservation.py | 2 +- pms/models/pms_reservation_line.py | 4 +- pms/tests/test_pms_reservation.py | 41 +++++++++++++++++-- .../wizard_split_join_swap_reservation.py | 4 +- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/pms/models/pms_reservation.py b/pms/models/pms_reservation.py index 40c3d116d..b4132fcfd 100644 --- a/pms/models/pms_reservation.py +++ b/pms/models/pms_reservation.py @@ -827,7 +827,7 @@ class PmsReservation(models.Model): room_type_id=False, # Allows to choose any available room current_lines=reservation.reservation_line_ids.ids, pricelist_id=reservation.pricelist_id.id, - class_id=reservation.room_type_id.class_id + class_id=reservation.room_type_id.class_id.id if reservation.room_type_id else False, real_avail=True, diff --git a/pms/models/pms_reservation_line.py b/pms/models/pms_reservation_line.py index 4eae1780c..eb2495402 100644 --- a/pms/models/pms_reservation_line.py +++ b/pms/models/pms_reservation_line.py @@ -178,6 +178,8 @@ class PmsReservationLine(models.Model): free_room_select = True if reservation.preferred_room_id else False # we get the rooms available for the entire stay + # (real_avail if True if the reservation was created with + # specific room selected) pms_property = line.pms_property_id pms_property = pms_property.with_context( checkin=reservation.checkin, @@ -187,7 +189,7 @@ class PmsReservationLine(models.Model): else False, current_lines=reservation.reservation_line_ids.ids, pricelist_id=reservation.pricelist_id.id, - real_avail=True, + real_avail=free_room_select, ) rooms_available = pms_property.free_room_ids diff --git a/pms/tests/test_pms_reservation.py b/pms/tests/test_pms_reservation.py index 35c729cee..939df2aae 100644 --- a/pms/tests/test_pms_reservation.py +++ b/pms/tests/test_pms_reservation.py @@ -29,6 +29,15 @@ class TestPmsReservations(TestPms): } ) + self.room_type_triple = self.env["pms.room.type"].create( + { + "pms_property_ids": [self.pms_property1.id], + "name": "Triple Test", + "default_code": "TRP_Test", + "class_id": self.room_type_class1.id, + } + ) + # create rooms self.room1 = self.env["pms.room"].create( { @@ -59,6 +68,16 @@ class TestPmsReservations(TestPms): "extra_beds_allowed": 1, } ) + + self.room4 = self.env["pms.room"].create( + { + "pms_property_id": self.pms_property1.id, + "name": "Triple 104", + "room_type_id": self.room_type_triple.id, + "capacity": 3, + "extra_beds_allowed": 1, + } + ) self.partner1 = self.env["res.partner"].create( { "firstname": "Jaime", @@ -1645,6 +1664,7 @@ class TestPmsReservations(TestPms): "checkin": fields.date.today(), "checkout": fields.date.today() + datetime.timedelta(days=3), "partner_id": self.partner1.id, + "room_type_id": self.room_type_double.id, } ) @@ -1678,6 +1698,7 @@ class TestPmsReservations(TestPms): "checkin": fields.date.today() + datetime.timedelta(days=300), "checkout": fields.date.today() + datetime.timedelta(days=305), "partner_id": self.partner1.id, + "room_type_id": self.room_type_double.id, } ) r = reservation.checkin @@ -1695,8 +1716,8 @@ class TestPmsReservations(TestPms): Check available rooms after creating a reservation. ----------- Create an availability rule, create a reservation, - and then check that the allopwed_room_ids field of the - reservation and the room_type_id.room_ids field of the + and then check that the allowed_room_ids field filtered by room + type of the reservation and the room_type_id.room_ids field of the availability rule match. """ availability_rule = self.env["pms.availability.plan.rule"].create( @@ -1718,8 +1739,10 @@ class TestPmsReservations(TestPms): } ) self.assertEqual( - reservation.allowed_room_ids, - availability_rule.room_type_id.room_ids, + reservation.allowed_room_ids.filtered( + lambda r: r.room_type_id.id == availability_rule.room_type_id.id + ).ids, + availability_rule.room_type_id.room_ids.ids, "Rooms allowed don't match", ) @@ -1750,6 +1773,7 @@ class TestPmsReservations(TestPms): "checkin": fields.date.today() + datetime.timedelta(days=150), "checkout": fields.date.today() + datetime.timedelta(days=152), "agency_id": agency.id, + "room_type_id": self.room_type_double.id, } ) @@ -1794,6 +1818,7 @@ class TestPmsReservations(TestPms): "checkin": fields.date.today() + datetime.timedelta(days=150), "checkout": fields.date.today() + datetime.timedelta(days=152), "agency_id": agency.id, + "room_type_id": self.room_type_double.id, } ) self.assertEqual( @@ -1815,6 +1840,7 @@ class TestPmsReservations(TestPms): "checkin": fields.date.today() + datetime.timedelta(days=150), "checkout": fields.date.today() + datetime.timedelta(days=152), "partner_id": self.partner1.id, + "room_type_id": self.room_type_double.id, } ) @@ -1873,6 +1899,7 @@ class TestPmsReservations(TestPms): "allowed_checkin": True, "pms_property_id": self.pms_property1.id, "adults": 3, + "room_type_id": self.room_type_triple.id, } ) self.checkin1 = self.env["pms.checkin.partner"].create( @@ -1916,6 +1943,7 @@ class TestPmsReservations(TestPms): "checkout": fields.date.today(), "pms_property_id": self.pms_property1.id, "partner_id": self.host1.id, + "room_type_id": self.room_type_double.id, } ) @@ -2294,6 +2322,7 @@ class TestPmsReservations(TestPms): "partner_id": self.host1.id, "pms_property_id": self.pms_property1.id, "adults": 3, + "room_type_id": self.room_type_triple.id, } ) self.checkin1 = self.env["pms.checkin.partner"].create( @@ -2351,6 +2380,7 @@ class TestPmsReservations(TestPms): "checkout": "2014-01-17", "partner_id": self.host1.id, "pms_property_id": self.pms_property1.id, + "room_type_id": self.room_type_triple.id, "adults": 3, } ) @@ -2404,6 +2434,7 @@ class TestPmsReservations(TestPms): "partner_id": host.id, "allowed_checkout": True, "pms_property_id": self.pms_property1.id, + "room_type_id": self.room_type_double.id, } ) @@ -2435,6 +2466,7 @@ class TestPmsReservations(TestPms): "checkout": "2014-01-17", "pms_property_id": self.pms_property1.id, "folio_id": self.folio1.id, + "room_type_id": self.room_type_double.id, } ) # ACT AND ASSERT @@ -2472,6 +2504,7 @@ class TestPmsReservations(TestPms): "checkin": fields.date.today() + datetime.timedelta(days=150), "checkout": fields.date.today() + datetime.timedelta(days=152), "agency_id": agency.id, + "room_type_id": self.room_type_double.id, } ) diff --git a/pms/wizards/wizard_split_join_swap_reservation.py b/pms/wizards/wizard_split_join_swap_reservation.py index d11220db6..575faaf9b 100644 --- a/pms/wizards/wizard_split_join_swap_reservation.py +++ b/pms/wizards/wizard_split_join_swap_reservation.py @@ -226,7 +226,7 @@ class ReservationSplitJoinSwapWizard(models.TransientModel): current_lines=reservation.reservation_line_ids.ids, pricelist_id=reservation.pricelist_id.id, real_avail=True, - class_id=reservation.room_type_id.class_id, + class_id=reservation.room_type_id.class_id.id, ) rooms_available = pms_property.free_room_ids @@ -365,7 +365,7 @@ class ReservationLinesToSplit(models.TransientModel): room_type_id=False, # Allows to choose any available room pricelist_id=reservation.pricelist_id.id, real_avail=True, - class_id=reservation.room_type_id.class_id, + class_id=reservation.room_type_id.class_id.id, ) rooms_available = pms_property.free_room_ids rooms_available += line.room_id From e1c5a4347aa50a718a816eb3e5ac8c7620d47f18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Lodeiros?= Date: Sun, 24 Oct 2021 20:08:48 +0200 Subject: [PATCH 05/27] [WIP]pms: wizard massive changes save&continue --- pms/wizards/wizard_massive_changes.py | 280 +++++++++++++------------ pms/wizards/wizard_massive_changes.xml | 10 +- 2 files changed, 156 insertions(+), 134 deletions(-) diff --git a/pms/wizards/wizard_massive_changes.py b/pms/wizards/wizard_massive_changes.py index 95fe47258..45507e674 100644 --- a/pms/wizards/wizard_massive_changes.py +++ b/pms/wizards/wizard_massive_changes.py @@ -1,6 +1,6 @@ import datetime -from odoo import api, fields, models +from odoo import _, api, fields, models from odoo.osv import expression @@ -872,145 +872,161 @@ class AvailabilityWizard(models.TransientModel): return new_items + def continue_massive_changes(self): + self.apply_massive_changes() + return { + "name": _("Massive changes on Pricelist and Availability Plans"), + "res_model": "pms.massive.changes.wizard", + "type": "ir.actions.act_window", + "view_id": self.env.ref("pms.massive_changes_wizard").id, + "target": "new", + "view_mode": "form", + "context": { + "default_massive_changes_on": self.massive_changes_on, + "default_start_date": self.start_date, + "default_end_date": self.end_date, + "default_pms_property_ids": [(6, 0, self.pms_property_ids.ids)], + "default_pricelist_ids": [(6, 0, self.pricelist_ids.ids)], + "default_availability_plan_ids": [ + (6, 0, self.availability_plan_ids.ids) + ], + }, + } + + def save_and_close(self): + items = self.apply_massive_changes() + if self.massive_changes_on == "pricelist" and not self.pricelist_readonly: + action = { + "view": self.env.ref("pms.product_pricelist_item_action2").read()[0] + } + action["view"]["domain"] = [("id", "in", items)] + return action["view"] + + if self.massive_changes_on == "availability_plan" and not self.avail_readonly: + action = { + "view": self.env.ref( + "pms.availability_plan_rule_view_tree_action" + ).read()[0] + } + action["view"]["domain"] = [("id", "in", items)] + return action["view"] + def apply_massive_changes(self): + self.ensure_one() + self.pricelist_items_to_overwrite.unlink() + week_days_to_apply = ( + self.apply_on_monday, + self.apply_on_tuesday, + self.apply_on_wednesday, + self.apply_on_thursday, + self.apply_on_friday, + self.apply_on_saturday, + self.apply_on_sunday, + ) - for record in self: - record.pricelist_items_to_overwrite.unlink() - week_days_to_apply = ( - record.apply_on_monday, - record.apply_on_tuesday, - record.apply_on_wednesday, - record.apply_on_thursday, - record.apply_on_friday, - record.apply_on_saturday, - record.apply_on_sunday, - ) + # dates between start and end (both included) + items = [] + for date in [ + self.start_date + datetime.timedelta(days=x) + for x in range(0, (self.end_date - self.start_date).days + 1) + ]: - # dates between start and end (both included) - items = [] - for date in [ - record.start_date + datetime.timedelta(days=x) - for x in range(0, (record.end_date - record.start_date).days + 1) - ]: + if ( + not self.apply_on_all_week + and not week_days_to_apply[date.timetuple()[6]] + ): + continue + if not self.room_type_ids: + room_types = self.env["pms.room.type"].search( + [ + "|", + ("pms_property_ids", "=", False), + ("pms_property_ids", "in", self.pms_property_ids.ids), + ] + ) + else: + room_types = self.room_type_ids + + for pms_property in self.pms_property_ids: if ( - not record.apply_on_all_week - and not week_days_to_apply[date.timetuple()[6]] + self.massive_changes_on == "pricelist" + and self.apply_pricelists_on == "room_types" ): - continue - - if not record.room_type_ids: - room_types = self.env["pms.room.type"].search( - [ - "|", - ("pms_property_ids", "=", False), - ("pms_property_ids", "in", record.pms_property_ids.ids), - ] + new_items = self.create_pricelists_items_room_types( + room_types, + self.pricelist_ids, + self.price, + self.min_quantity, + pms_property, + date, + self.date_types, ) - else: - room_types = record.room_type_ids + items = items + new_items if new_items else items - for pms_property in record.pms_property_ids: - if ( - record.massive_changes_on == "pricelist" - and record.apply_pricelists_on == "room_types" - ): - new_items = self.create_pricelists_items_room_types( - room_types, - record.pricelist_ids, - record.price, - record.min_quantity, - pms_property, - date, - record.date_types, - ) - items = items + new_items if new_items else items + elif ( + self.massive_changes_on == "pricelist" + and self.apply_pricelists_on == "board_services" + ): + new_items = self.create_pricelists_items_board_services( + self.board_service_room_type_ids, + self.pricelist_ids, + self.board_service, + self.price, + self.min_quantity, + pms_property, + self.date_types, + date, + ) + items = items + new_items if new_items else items - elif ( - record.massive_changes_on == "pricelist" - and record.apply_pricelists_on == "board_services" - ): - new_items = self.create_pricelists_items_board_services( - record.board_service_room_type_ids, - record.pricelist_ids, - record.board_service, - record.price, - record.min_quantity, - pms_property, - record.date_types, - date, - ) - items = items + new_items if new_items else items + elif ( + self.massive_changes_on == "pricelist" + and self.apply_pricelists_on == "service" + ): + for pricelist in self.pricelist_ids: + if self.service: + vals = { + "pricelist_id": pricelist.id, + "compute_price": "fixed", + "applied_on": "0_product_variant", + "product_id": self.service.id, + "fixed_price": self.price, + "min_quantity": self.min_quantity, + "pms_property_ids": [pms_property.id], + } + vals = self.generate_dates_vals(self.date_types, vals, date) - elif ( - record.massive_changes_on == "pricelist" - and record.apply_pricelists_on == "service" - ): - for pricelist in record.pricelist_ids: - if record.service: - vals = { - "pricelist_id": pricelist.id, - "compute_price": "fixed", - "applied_on": "0_product_variant", - "product_id": record.service.id, - "fixed_price": record.price, - "min_quantity": record.min_quantity, - "pms_property_ids": [pms_property.id], - } - vals = self.generate_dates_vals( - record.date_types, vals, date - ) + pricelist_item = self.env["product.pricelist.item"].create( + vals + ) + items.append(pricelist_item.id) + elif self.massive_changes_on == "availability_plan": - pricelist_item = self.env[ - "product.pricelist.item" - ].create(vals) - items.append(pricelist_item.id) - elif record.massive_changes_on == "availability_plan": - - new_items = self.create_availability_plans_rules( - room_types, - record.availability_plan_ids, - record.min_stay, - record.apply_min_stay, - record.min_stay_arrival, - record.apply_min_stay_arrival, - record.max_stay, - record.apply_max_stay, - record.max_stay_arrival, - record.apply_max_stay_arrival, - record.quota, - record.apply_quota, - record.max_avail, - record.apply_max_avail, - record.closed, - record.apply_closed, - record.closed_arrival, - record.apply_closed_arrival, - record.closed_departure, - record.apply_closed_departure, - date, - record.rules_to_overwrite, - pms_property, - ) - items = items + new_items if new_items else items - if ( - record.massive_changes_on == "pricelist" - and not record.pricelist_readonly - ): - action = { - "view": self.env.ref("pms.product_pricelist_item_action2").read()[0] - } - action["view"]["domain"] = [("id", "in", items)] - return action["view"] - - if ( - record.massive_changes_on == "availability_plan" - and not record.avail_readonly - ): - action = { - "view": self.env.ref( - "pms.availability_plan_rule_view_tree_action" - ).read()[0] - } - action["view"]["domain"] = [("id", "in", items)] - return action["view"] + new_items = self.create_availability_plans_rules( + room_types, + self.availability_plan_ids, + self.min_stay, + self.apply_min_stay, + self.min_stay_arrival, + self.apply_min_stay_arrival, + self.max_stay, + self.apply_max_stay, + self.max_stay_arrival, + self.apply_max_stay_arrival, + self.quota, + self.apply_quota, + self.max_avail, + self.apply_max_avail, + self.closed, + self.apply_closed, + self.closed_arrival, + self.apply_closed_arrival, + self.closed_departure, + self.apply_closed_departure, + date, + self.rules_to_overwrite, + pms_property, + ) + items = items + new_items if new_items else items + return items diff --git a/pms/wizards/wizard_massive_changes.xml b/pms/wizards/wizard_massive_changes.xml index dc87d505a..a8762827e 100644 --- a/pms/wizards/wizard_massive_changes.xml +++ b/pms/wizards/wizard_massive_changes.xml @@ -474,8 +474,14 @@