From 4b291ff7419f0806ec63706aebc69ee3055dda22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Lodeiros?= Date: Sat, 8 Jan 2022 19:54:17 +0100 Subject: [PATCH] [ADD]pms: daily closed method --- pms/models/pms_property.py | 55 +++++++++++++++++++++++++ pms/wizards/wizard_massive_changes.py | 2 +- pms_l10n_es/wizards/traveller_report.py | 8 ++-- 3 files changed, 61 insertions(+), 4 deletions(-) diff --git a/pms/models/pms_property.py b/pms/models/pms_property.py index c3e7e70c4..31bf33bc3 100644 --- a/pms/models/pms_property.py +++ b/pms/models/pms_property.py @@ -490,3 +490,58 @@ class PmsProperty(models.Model): vals.update({"checkin_sequence_id": checkin_sequence.id}) record = super(PmsProperty, self).create(vals) return record + + @api.model + def daily_closing( + self, pms_property_ids, room_type_ids=False, availability_plan_ids=False + ): + """ + This method is used to close the daily availability of rooms + """ + pms_properties = self.browse(pms_property_ids) + for pms_property in pms_properties: + if not room_type_ids: + room_type_ids = self.env["pms.room.type"].search( + [ + "|", + ("pms_property_id", "=", pms_property.id), + ("pms_property_id", "=", False), + ] + ) + if not availability_plan_ids: + availability_plan_ids = self.env["pms.availability.plan"].search( + [ + "|", + ("pms_property_id", "=", pms_property.id), + ("pms_property_id", "=", False), + ] + ) + for room_type in self.env["pms.room.type"].browse(room_type_ids): + for availability_plan in self.env["pms.availability.plan"].browse( + availability_plan_ids + ): + rule = self.env["pms.availability.plan.rule"].search( + [ + ("pms_property_id", "=", pms_property.id), + ("room_type_id", "=", room_type.id), + ("availability_plan_id", "=", availability_plan.id), + ] + ) + if not rule: + rule = self.env["pms.availability.plan.rule"].create( + { + "pms_property_id": pms_property.id, + "room_type_id": room_type.id, + "availability_plan_id": availability_plan.id, + "date": fields.date.today(), + "closed": True, + } + ) + elif not rule.closed: + rule.write( + { + "closed": True, + } + ) + + return True diff --git a/pms/wizards/wizard_massive_changes.py b/pms/wizards/wizard_massive_changes.py index aa8dfeeb3..860d220a4 100644 --- a/pms/wizards/wizard_massive_changes.py +++ b/pms/wizards/wizard_massive_changes.py @@ -809,7 +809,7 @@ class AvailabilityWizard(models.TransientModel): overwrite = rules_to_overwrite.filtered( lambda x: x.room_type_id == room_type and x.date == date - and x.pms_propert_id.id == pms_property.id + and x.pms_property_id.id == pms_property.id ) overwrite.write(vals) new_items += overwrite.ids diff --git a/pms_l10n_es/wizards/traveller_report.py b/pms_l10n_es/wizards/traveller_report.py index 7bae34d2f..680602300 100644 --- a/pms_l10n_es/wizards/traveller_report.py +++ b/pms_l10n_es/wizards/traveller_report.py @@ -3,7 +3,6 @@ import datetime import io import json import time -from datetime import date import PyPDF2 import requests @@ -71,13 +70,15 @@ class TravellerReport(models.TransientModel): "view_type": "form", } - def generate_checkin_list(self, property_id, date_target: date.today()): - + def generate_checkin_list(self, property_id, date_target=False): + if not date_target: + date_target = fields.date.today() # check if there's guests info pending to send if self.env["pms.checkin.partner"].search_count( [ ("state", "=", "onboard"), ("arrival", ">=", str(date_target) + " 0:00:00"), + ("pms_property_id", "=", property_id), ] ): pms_property = ( @@ -91,6 +92,7 @@ class TravellerReport(models.TransientModel): ("state", "=", "onboard"), ("arrival", ">=", str(date_target) + " 0:00:00"), ("arrival", "<=", str(date_target) + " 23:59:59"), + ("pms_property_id", "=", property_id), ] ) # build the property info record