From 3d027f7e961e519aae3c83efd0d2efdbc450385f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Lodeiros?= Date: Wed, 11 May 2022 14:06:38 +0200 Subject: [PATCH] [IMP]pms_l10n_es: INE adaptation groups --- pms_l10n_es/wizards/wizard_ine.py | 195 +++++++++++++----------------- 1 file changed, 83 insertions(+), 112 deletions(-) diff --git a/pms_l10n_es/wizards/wizard_ine.py b/pms_l10n_es/wizards/wizard_ine.py index 8b96e2ef5..308aeb4d3 100644 --- a/pms_l10n_es/wizards/wizard_ine.py +++ b/pms_l10n_es/wizards/wizard_ine.py @@ -658,139 +658,110 @@ class WizardIne(models.TransientModel): ) ) - # TODO: - # Evaluate how to get occupation & ADR for: - # -traditional/online tour-operator - # -traditional/online agency - # -companys + total_groups_domains = { + "tour_operator_offline": [ + ("reservation_id.agency_id.sale_channel_id.name", "ilike", "Operator"), + ("reservation_id.agency_id.sale_channel_id.is_on_line", "=", True), + ], + "tour_operator_online": [ + ("reservation_id.agency_id.sale_channel_id.name", "ilike", "Operator"), + ("reservation_id.agency_id.sale_channel_id.is_on_line", "=", False), + ], + "companies": [ + ("reservation_id.partner_id", "!=", False), + ("reservation_id.partner_id.is_company", "=", True), + ], + "agencies": [ + ("reservation_id.agency_id", "!=", False), + ("reservation_id.agency_id.sale_channel_id.is_on_line", "=", False), + ], + "percent_otas": [ + ("reservation_id.agency_id", "!=", False), + ("reservation_id.agency_id.sale_channel_id.is_on_line", "=", True), + ], + "persons": [ + "|", + ("reservation_id.partner_id", "=", False), + ("reservation_id.partner_id.is_company", "=", False), + ], + "groups": [("reservation_id.folio_id.number_of_rooms", ">=", 4)], + "internet": [("reservation_id.channel_type_id.is_on_line", "=", True)], + "others": [ + "|", + ("reservation_id.channel_type_id.is_on_line", "!=", True), + ("reservation_id.channel_type_id", "=", False), + ], + } - ET.SubElement(prices_tag, "ADR_TOUROPERADOR_TRADICIONAL").text = "0" + percents = {} + adrs = {} + for group, domain in total_groups_domains.items(): + percents[group] = self.ine_calculate_occupancy( + self.start_date, + self.end_date, + domain, + ) + adrs[group] = self.ine_calculate_adr( + self.start_date, + self.end_date, + domain, + ) + + # In this point, the groups adrs and percents are well calculated.... but, + # our statist friends want the total of the percentage groupings to add up = 100%, + # without conceiving that the groupings overlap, so they cannot receive real data + # and force us to pervert the original data so that it fits in their grid notebook. + # The purpose of the following lines of code is only to show the inefficiency + # of the state statistics, + # so at least I will feel that the effort made some sense :) + + total_percent = sum([val for val in percents.values()]) + for group in total_groups_domains.keys(): + percents[group] = round(percents[group] * 100 / total_percent, 2) + + ET.SubElement(prices_tag, "ADR_TOUROPERADOR_TRADICIONAL").text = str( + adrs["tour_operator_offline"] + ) ET.SubElement( prices_tag, "PCTN_HABITACIONES_OCUPADAS_TOUROPERADOR_TRADICIONAL" - ).text = "0" - ET.SubElement(prices_tag, "ADR_TOUROPERADOR_ONLINE").text = "0" + ).text = str(percents["tour_operator_offline"]) + ET.SubElement(prices_tag, "ADR_TOUROPERADOR_ONLINE").text = str( + adrs["tour_operator_online"] + ) ET.SubElement( prices_tag, "PCTN_HABITACIONES_OCUPADAS_TOUROPERADOR_ONLINE" - ).text = "0" - ET.SubElement(prices_tag, "ADR_EMPRESAS").text = str( - self.ine_calculate_adr( - self.start_date, - self.end_date, - [ - ("reservation_id.partner_id", "!=", False), - ("reservation_id.partner_id.is_company", "=", True), - ], - ) - ) + ).text = str(percents["tour_operator_online"]) + ET.SubElement(prices_tag, "ADR_EMPRESAS").text = str(adrs["companies"]) ET.SubElement(prices_tag, "PCTN_HABITACIONES_OCUPADAS_EMPRESAS").text = str( - self.ine_calculate_occupancy( - self.start_date, - self.end_date, - [ - ("reservation_id.partner_id", "!=", False), - ("reservation_id.partner_id.is_company", "=", True), - ], - ) + percents["companies"] ) ET.SubElement(prices_tag, "ADR_AGENCIA_DE_VIAJE_TRADICIONAL").text = str( - self.ine_calculate_adr( - self.start_date, - self.end_date, - [ - ("reservation_id.agency_id", "!=", False), - ("reservation_id.agency_id.sale_channel_id.is_on_line", "=", False), - ], - ) + adrs["agencies"] ) ET.SubElement( prices_tag, "PCTN_HABITACIONES_OCUPADAS_AGENCIA_TRADICIONAL" - ).text = str( - self.ine_calculate_occupancy( - self.start_date, - self.end_date, - [ - ("reservation_id.agency_id", "!=", False), - ("reservation_id.agency_id.sale_channel_id.is_on_line", "=", False), - ], - ) - ) + ).text = str(percents["agencies"]) ET.SubElement(prices_tag, "ADR_AGENCIA_DE_VIAJE_ONLINE").text = str( - self.ine_calculate_adr( - self.start_date, - self.end_date, - [ - ("reservation_id.agency_id", "!=", False), - ("reservation_id.agency_id.sale_channel_id.is_on_line", "=", True), - ], - ) + adrs["otas"] ) ET.SubElement( prices_tag, "PCTN_HABITACIONES_OCUPADAS_AGENCIA_ONLINE" - ).text = str( - self.ine_calculate_occupancy( - self.start_date, - self.end_date, - [ - ("reservation_id.agency_id", "!=", False), - ("reservation_id.agency_id.sale_channel_id.is_on_line", "=", True), - ], - ) - ) - ET.SubElement(prices_tag, "ADR_PARTICULARES").text = str( - self.ine_calculate_adr( - self.start_date, - self.end_date, - [ - "|", - ("reservation_id.partner_id", "=", False), - ("reservation_id.partner_id.is_company", "!=", False), - ], - ) - ) + ).text = str(percents["otas"]) + ET.SubElement(prices_tag, "ADR_PARTICULARES").text = str(adrs["persons"]) ET.SubElement(prices_tag, "PCTN_HABITACIONES_OCUPADAS_PARTICULARES").text = str( - self.ine_calculate_occupancy( - self.start_date, - self.end_date, - [ - "|", - ("reservation_id.partner_id", "=", False), - ("reservation_id.partner_id.is_company", "=", False), - ], - ) + percents["persons"] ) - ET.SubElement(prices_tag, "ADR_GRUPOS").text = "0" - ET.SubElement(prices_tag, "PCTN_HABITACIONES_OCUPADAS_GRUPOS").text = "0" - ET.SubElement(prices_tag, "ADR_INTERNET").text = str( - self.ine_calculate_adr( - self.start_date, - self.end_date, - [("reservation_id.channel_type_id.is_on_line", "=", True)], - ) + ET.SubElement(prices_tag, "ADR_GRUPOS").text = str(adrs["groups"]) + ET.SubElement(prices_tag, "PCTN_HABITACIONES_OCUPADAS_GRUPOS").text = str( + percents["groups"] ) + ET.SubElement(prices_tag, "ADR_INTERNET").text = str(adrs["internet"]) ET.SubElement(prices_tag, "PCTN_HABITACIONES_OCUPADAS_INTERNET").text = str( - self.ine_calculate_occupancy( - self.start_date, - self.end_date, - [("reservation_id.channel_type_id.is_on_line", "=", True)], - ) - ) - ET.SubElement(prices_tag, "ADR_OTROS").text = str( - self.ine_calculate_adr( - self.start_date, - self.end_date, - [("reservation_id.channel_type_id.is_on_line", "!=", True)], - ) + percents["internet"] ) + ET.SubElement(prices_tag, "ADR_OTROS").text = str(adrs["others"]) ET.SubElement(prices_tag, "PCTN_HABITACIONES_OCUPADAS_OTROS").text = str( - self.ine_calculate_occupancy( - self.start_date, - self.end_date, - [ - "|", - ("reservation_id.channel_type_id.is_on_line", "!=", True), - ("reservation_id.channel_type_id", "=", False), - ], - ) + percents["others"] ) staff_tag = ET.SubElement(survey_tag, "PERSONAL_OCUPADO")