diff --git a/payment_acquirer_multi_pms_properties/controllers/portal.py b/payment_acquirer_multi_pms_properties/controllers/portal.py index 66872f8c7..60e434dc4 100644 --- a/payment_acquirer_multi_pms_properties/controllers/portal.py +++ b/payment_acquirer_multi_pms_properties/controllers/portal.py @@ -11,13 +11,15 @@ class PortalAccount(PortalAccount): values = super(PortalAccount, self)._invoice_get_page_view_values( invoice, access_token, **kwargs ) - for acquirer in values["acquirers"]: + acquirers = values.get("acquirers") + for acquirer in acquirers: if ( acquirer.pms_property_ids and invoice.pms_property_id.id not in acquirer.pms_property_ids.ids ): values["acquirers"] -= acquirer - for pms in values["pms"]: + payment_tokens = values.get("payment_tokens") + for pms in payment_tokens: if pms.acquirer_id not in values["acquirers"].ids: values["pms"] -= pms return values diff --git a/pms/models/pms_folio.py b/pms/models/pms_folio.py index e001d971f..f4b5f9a11 100644 --- a/pms/models/pms_folio.py +++ b/pms/models/pms_folio.py @@ -982,31 +982,30 @@ class PmsFolio(models.Model): automatic_included=True ) paid_out = 0 - for journal in journals: - paid_out += sum( - self.env["account.move.line"] - .search( - [ - ("folio_ids", "in", record.id), - ( - "account_id", - "in", - tuple( - journal.default_account_id.ids - + journal.payment_debit_account_id.ids - + journal.payment_credit_account_id.ids - ), + paid_out += sum( + self.env["account.move.line"] + .search( + [ + ("folio_ids", "in", record.id), + ( + "account_id", + "in", + tuple( + journals.default_account_id.ids + + journals.payment_debit_account_id.ids + + journals.payment_credit_account_id.ids ), - ( - "display_type", - "not in", - ("line_section", "line_note"), - ), - ("move_id.state", "!=", "cancel"), - ] - ) - .mapped("balance") + ), + ( + "display_type", + "not in", + ("line_section", "line_note"), + ), + ("move_id.state", "!=", "cancel"), + ] ) + .mapped("balance") + ) total = record.amount_total # REVIEW: Must We ignored services in cancelled folios # pending amount? @@ -1641,9 +1640,13 @@ class PmsFolio(models.Model): (making sure to call super() to establish a clean extension chain). """ self.ensure_one() + journal = ( self.env["account.move"] - .with_context(default_move_type="out_invoice") + .with_context( + default_move_type="out_invoice", + default_company_id=self.company_id.id, + ) ._get_default_journal() ) if not journal: 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/models/pms_reservation_line.py b/pms/models/pms_reservation_line.py index eb2495402..48cc4177d 100644 --- a/pms/models/pms_reservation_line.py +++ b/pms/models/pms_reservation_line.py @@ -248,7 +248,9 @@ class PmsReservationLine(models.Model): ): if self.env.context.get("force_overbooking"): reservation.overbooking = True - line.room_id = reservation.room_type_id.room_ids[0] + line.room_id = reservation.room_type_id.room_ids.filtered( + lambda r: r.pms_property_id == line.pms_property_id + )[0] else: raise ValidationError( _("%s: No room type available") diff --git a/pms/wizards/wizard_massive_changes.py b/pms/wizards/wizard_massive_changes.py index 47f9e9fc0..860d220a4 100644 --- a/pms/wizards/wizard_massive_changes.py +++ b/pms/wizards/wizard_massive_changes.py @@ -380,6 +380,7 @@ class AvailabilityWizard(models.TransientModel): def _rules_to_overwrite_by_plans(self, availability_plans): self.ensure_one() domain = [ + ("pms_property_id", "in", self.pms_property_ids.ids), ("availability_plan_id", "in", availability_plans.ids), ] @@ -806,7 +807,9 @@ class AvailabilityWizard(models.TransientModel): "date" ) and room_type in rules_to_overwrite.mapped("room_type_id"): overwrite = rules_to_overwrite.filtered( - lambda x: x.room_type_id == room_type and x.date == date + lambda x: x.room_type_id == room_type + and x.date == date + 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 2d824dcf8..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 @@ -21,12 +20,19 @@ class TravellerReport(models.TransientModel): txt_filename = fields.Text() txt_binary = fields.Binary(string="File Download") txt_message = fields.Char(string="File Preview") + date_target = fields.Date( + string="Date", required=True, default=lambda self: fields.Date.today() + ) + pms_property_id = fields.Many2one( + comodel_name="pms.property", + string="Property", + required=True, + default=lambda self: self.env.user.get_active_property_ids()[0], + ) def generate_file_from_user_action(self): - - # get the active property pms_property = self.env["pms.property"].search( - [("id", "=", self.env.user.get_active_property_ids()[0])] + [("id", "=", self.pms_property_id.id)] ) # check if there's institution settings properly established if ( @@ -40,7 +46,10 @@ class TravellerReport(models.TransientModel): ) # build content - content = self.generate_checkin_list(pms_property.id) + content = self.generate_checkin_list( + property_id=pms_property.id, + date_target=self.date_target, + ) if content: txt_binary = self.env["traveller.report.wizard"].create( @@ -61,25 +70,29 @@ class TravellerReport(models.TransientModel): "view_type": "form", } - def generate_checkin_list(self, property_id): - + 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.today()) + " 0:00:00"), + ("arrival", ">=", str(date_target) + " 0:00:00"), + ("pms_property_id", "=", property_id), ] ): - - # get the active property - pms_property = self.env["pms.property"].search([("id", "=", property_id)]) + pms_property = ( + self.env["pms.property"] + .with_context(lang="es_ES") + .search([("id", "=", property_id)]) + ) # get checkin partners info to send lines = self.env["pms.checkin.partner"].search( [ ("state", "=", "onboard"), - ("arrival", ">=", str(date.today()) + " 0:00:00"), - ("arrival", "<=", str(date.today()) + " 23:59:59"), - ("pms_property_id", "=", pms_property.id), + ("arrival", ">=", str(date_target) + " 0:00:00"), + ("arrival", "<=", str(date_target) + " 23:59:59"), + ("pms_property_id", "=", property_id), ] ) # build the property info record @@ -98,7 +111,7 @@ class TravellerReport(models.TransientModel): # build each checkin partner line's record # 2|DNI nÂș|Doc.number|doc.type|exp.date|lastname|lastname2|name|... # ...gender|birthdate|nation.|checkin - + lines = lines.with_context(lang="es_ES") for line in lines: content += "2" # [P|N|..] diff --git a/pms_l10n_es/wizards/traveller_report.xml b/pms_l10n_es/wizards/traveller_report.xml index 9f428c185..9dadfe3f9 100644 --- a/pms_l10n_es/wizards/traveller_report.xml +++ b/pms_l10n_es/wizards/traveller_report.xml @@ -8,6 +8,10 @@
+ + + +