From bfea6322ae629db6558fe72af150b6e0859c2c1b Mon Sep 17 00:00:00 2001 From: miguelpadin Date: Mon, 10 Jun 2024 17:27:36 +0100 Subject: [PATCH] [FIX] pms-l10n_es: fix percentages @ ine report --- ...PRE_SGSICS.SES.MIR.ES.cer => ses_cert.pem} | 0 pms_l10n_es/tests/test_wizard_ine.py | 10 +++--- pms_l10n_es/wizards/traveller_report.py | 31 ++++++++++--------- pms_l10n_es/wizards/wizard_ine.py | 28 ++++++++++++----- 4 files changed, 42 insertions(+), 27 deletions(-) rename pms_l10n_es/static/{PRE_SGSICS.SES.MIR.ES.cer => ses_cert.pem} (100%) diff --git a/pms_l10n_es/static/PRE_SGSICS.SES.MIR.ES.cer b/pms_l10n_es/static/ses_cert.pem similarity index 100% rename from pms_l10n_es/static/PRE_SGSICS.SES.MIR.ES.cer rename to pms_l10n_es/static/ses_cert.pem diff --git a/pms_l10n_es/tests/test_wizard_ine.py b/pms_l10n_es/tests/test_wizard_ine.py index cb3f8305f..df15c71c9 100644 --- a/pms_l10n_es/tests/test_wizard_ine.py +++ b/pms_l10n_es/tests/test_wizard_ine.py @@ -652,7 +652,7 @@ class TestWizardINE(TestPms): }, } # ACT - nationalities = self.env["pms.ine.wizard"].ine_nationalities( + nationalities = self.env["pms.ine.wizard"].ine_countries( start_date, end_date, self.pms_property1.id ) # ASSERT @@ -778,7 +778,7 @@ class TestWizardINE(TestPms): } } # ACT - nationalities = self.env["pms.ine.wizard"].ine_nationalities( + nationalities = self.env["pms.ine.wizard"].ine_countries( start_date, end_date, self.pms_property1.id ) # ASSERT @@ -910,7 +910,7 @@ class TestWizardINE(TestPms): }, } # ACT - nationalities = self.env["pms.ine.wizard"].ine_nationalities( + nationalities = self.env["pms.ine.wizard"].ine_countries( start_date, end_date, self.pms_property1.id ) # ASSERT @@ -956,7 +956,7 @@ class TestWizardINE(TestPms): ValidationError, msg="Cannot generate INE if some checkin partner has no nationality", ): - self.env["pms.ine.wizard"].ine_nationalities( + self.env["pms.ine.wizard"].ine_countries( start_date, end_date, self.pms_property1.id ) @@ -1042,6 +1042,6 @@ class TestWizardINE(TestPms): ValidationError, msg="Cannot generate INE if some checkin partner from Spain has no nationality", ): - self.env["pms.ine.wizard"].ine_nationalities( + self.env["pms.ine.wizard"].ine_countries( start_date, end_date, self.pms_property1.id ) diff --git a/pms_l10n_es/wizards/traveller_report.py b/pms_l10n_es/wizards/traveller_report.py index 96ec55a2a..94ecd91a8 100644 --- a/pms_l10n_es/wizards/traveller_report.py +++ b/pms_l10n_es/wizards/traveller_report.py @@ -12,7 +12,6 @@ import zipfile import requests from bs4 import BeautifulSoup as bs from dateutil.relativedelta import relativedelta -from requests.packages.urllib3.exceptions import InsecureRequestWarning from odoo import _, api, fields, models from odoo.exceptions import MissingError, ValidationError @@ -34,7 +33,7 @@ CREATE_OPERATION_CODE = "A" DELETE_OPERATION_CODE = "B" # Disable insecure request warnings -requests.packages.urllib3.disable_warnings(InsecureRequestWarning) +# requests.packages.urllib3.disable_warnings(InsecureRequestWarning) def _string_to_zip_to_base64(string_data): @@ -304,15 +303,21 @@ def _handle_request_exception(communication, e): if isinstance(e, requests.exceptions.RequestException): if isinstance(e, requests.exceptions.ConnectionError): if communication.state == "to_send": - communication.sending_result = "Cannot establish the connection." - else: - communication.processing_result = "Cannot establish the connection." - elif isinstance(e, requests.exceptions.Timeout): - if communication.state == "to_send": - communication.sending_result = "The request took too long to complete." + communication.sending_result = ( + f"Cannot establish the connection. ({e.args})" + ) else: communication.processing_result = ( - "The request took too long to complete." + f"Cannot establish the connection. ({e.args})" + ) + elif isinstance(e, requests.exceptions.Timeout): + if communication.state == "to_send": + communication.sending_result = ( + f"The request took too long to complete. ({e.args})" + ) + else: + communication.processing_result = ( + f"The request took too long to complete. ({e.args})" ) else: if communication.state == "to_send": @@ -1027,9 +1032,7 @@ class TravellerReport(models.TransientModel): communication.reservation_id.pms_property_id.ses_url, headers=_get_auth_headers(communication), data=payload, - verify=get_module_resource( - "pms_l10n_es", "static", "PRE_SGSICS.SES.MIR.ES.cer" - ), + verify=get_module_resource("pms_l10n_es", "static", "ses_cert.pem"), ) root = ET.fromstring(soap_response.text) communication.sending_result = root.find(".//descripcion").text @@ -1077,9 +1080,7 @@ class TravellerReport(models.TransientModel): communication.reservation_id.pms_property_id.ses_url, headers=_get_auth_headers(communication), data=payload, - verify=get_module_resource( - "pms_l10n_es", "static", "PRE_SGSICS.SES.MIR.ES.cer" - ), + verify=get_module_resource("pms_l10n_es", "static", "cert.pem"), ) root = ET.fromstring(soap_response.text) communication.response_communication_soap = soap_response.text diff --git a/pms_l10n_es/wizards/wizard_ine.py b/pms_l10n_es/wizards/wizard_ine.py index b113382bc..e69a36f88 100644 --- a/pms_l10n_es/wizards/wizard_ine.py +++ b/pms_l10n_es/wizards/wizard_ine.py @@ -1,6 +1,7 @@ import base64 import calendar import datetime +import math import xml.etree.cElementTree as ET from odoo import _, api, fields, models @@ -239,18 +240,18 @@ class WizardIne(models.TransientModel): for entry in read_group_result: if not entry["residence_country_id"]: - guests_with_no_nationality = self.env["pms.checkin.partner"].search( - entry["__domain"] - ) - guests_with_no_nationality = ( - str(guests_with_no_nationality.mapped("name")) + guests_with_no_residence_country = self.env[ + "pms.checkin.partner" + ].search(entry["__domain"]) + guests_with_no_residence_country = ( + str(guests_with_no_residence_country.mapped("name")) .replace("[", "") .replace("]", "") ) raise ValidationError( _( - "The following guests have no residence nationality set :%s.", - guests_with_no_nationality, + "The following guests have no residence country set :%s.", + guests_with_no_residence_country, ) ) # get residence_country_id from group set read_group results @@ -739,8 +740,21 @@ class WizardIne(models.TransientModel): # so at least I will feel that the effort made some sense :) total_percent = sum([val for val in percents.values()]) + sum_percentages = 0 for group in total_groups_domains.keys(): percents[group] = round(percents[group] * 100 / (total_percent or 1), 2) + sum_percentages += percents[group] + + if sum_percentages < 100: + for group in total_groups_domains.keys(): + if percents[group] > 0: + percents[group] += math.ceil((100 - sum_percentages) * 100) / 100 + break + elif sum_percentages > 100: + for group in total_groups_domains.keys(): + if percents[group] > 0: + percents[group] -= math.ceil((sum_percentages - 100) * 100) / 100 + break ET.SubElement(prices_tag, "ADR_TOUROPERADOR_TRADICIONAL").text = str( adrs["tour_operator_offline"]