diff --git a/pms_l10n_es/__manifest__.py b/pms_l10n_es/__manifest__.py index 1ff4d1fc9..27cdaf124 100644 --- a/pms_l10n_es/__manifest__.py +++ b/pms_l10n_es/__manifest__.py @@ -31,6 +31,7 @@ "views/pms_checkin_partner_views.xml", "views/pms_property_views.xml", "views/res_partner_views.xml", + "views/pms_log_institution_traveller_report_views.xml", "wizards/traveller_report.xml", ], "installable": True, diff --git a/pms_l10n_es/data/cron_jobs.xml b/pms_l10n_es/data/cron_jobs.xml index f99af664a..4aaa1853a 100644 --- a/pms_l10n_es/data/cron_jobs.xml +++ b/pms_l10n_es/data/cron_jobs.xml @@ -3,7 +3,7 @@ Automatic Send Traveller Report - + 1 days @@ -13,9 +13,9 @@ - model.send_file_gc_async() + model.send_file_institution_async() diff --git a/pms_l10n_es/data/queue_data.xml b/pms_l10n_es/data/queue_data.xml index 42bfe7236..44bbeb3a4 100644 --- a/pms_l10n_es/data/queue_data.xml +++ b/pms_l10n_es/data/queue_data.xml @@ -1,8 +1,8 @@ - - gc_file_send + + institution_file_send diff --git a/pms_l10n_es/data/queue_job_function_data.xml b/pms_l10n_es/data/queue_job_function_data.xml index c59467665..d3021bda8 100644 --- a/pms_l10n_es/data/queue_job_function_data.xml +++ b/pms_l10n_es/data/queue_job_function_data.xml @@ -6,7 +6,7 @@ > send_file_async - + diff --git a/pms_l10n_es/i18n/pms_l10n_es.pot b/pms_l10n_es/i18n/pms_l10n_es.pot index e05310a57..322b7a8de 100644 --- a/pms_l10n_es/i18n/pms_l10n_es.pot +++ b/pms_l10n_es/i18n/pms_l10n_es.pot @@ -28,7 +28,7 @@ msgstr "" #. module: pms_l10n_es #: code:addons/pms_l10n_es/wizards/traveller_report.py:0 #, python-format -msgid "Check the GC configuration to send the guests info" +msgid "Check the institution configuration to send the guests info" msgstr "" #. module: pms_l10n_es diff --git a/pms_l10n_es/models/__init__.py b/pms_l10n_es/models/__init__.py index ebd8614e3..c23c7b1fd 100644 --- a/pms_l10n_es/models/__init__.py +++ b/pms_l10n_es/models/__init__.py @@ -1,3 +1,4 @@ from . import res_partner from . import pms_checkin_partner from . import pms_property +from . import pms_log_institution_traveller_report diff --git a/pms_l10n_es/models/pms_log_institution_traveller_report.py b/pms_l10n_es/models/pms_log_institution_traveller_report.py new file mode 100644 index 000000000..2a3e7d76a --- /dev/null +++ b/pms_l10n_es/models/pms_log_institution_traveller_report.py @@ -0,0 +1,22 @@ +from odoo import fields, models + + +class PmsLogInstitutionTravellerReport(models.Model): + _name = "pms.log.institution.traveller.report" + _description = "Report of daily sending files of travellers to institutions." + + date = fields.Datetime( + string="Date and time", + default=fields.Datetime.now, + ) + error_sending_data = fields.Boolean( + string="Error sending data", + required=True, + ) + txt_incidencies_from_institution = fields.Text( + string="Detailed message", + ) + file_incidencies_from_institution = fields.Binary( + string="Detailed file", + ) + txt_filename = fields.Text() diff --git a/pms_l10n_es/models/pms_property.py b/pms_l10n_es/models/pms_property.py index 9a0fba218..e34f02843 100644 --- a/pms_l10n_es/models/pms_property.py +++ b/pms_l10n_es/models/pms_property.py @@ -14,7 +14,7 @@ class PmsProperty(models.Model): institution = fields.Selection( [ ("guardia_civil", "Guardia Civil"), - ("policia_nacional", "Policía Nacional (soon)"), + ("policia_nacional", "Policía Nacional"), ("ertxaintxa", "Ertxaintxa (soon)"), ("mossos", "Mossos_d'esquadra (soon)"), ], @@ -24,7 +24,6 @@ class PmsProperty(models.Model): ) institution_property_id = fields.Char( string="Institution property id", - size=10, help="Id provided by institution to send data from property.", ) institution_user = fields.Char( @@ -35,30 +34,27 @@ class PmsProperty(models.Model): help="Password provided by institution to send the data.", ) - def test_gc_connection(self): - for pms_property in self: + def test_connection(self): + headers = { + "User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 " + "Build/MRA58N) AppleWebKit/537.36 (KHTML, like " + "Gecko) Chrome/90.0.4430.93 Mobile Safari/537.36", + } + for record in self: if ( - pms_property.institution == "guardia_civil" - and pms_property.institution_property_id - and pms_property.institution_user - and pms_property.institution_password + record.institution == "guardia_civil" + and record.institution_property_id + and record.institution_user + and record.institution_password ): - url = "https://hospederias.guardiacivil.es/" login_route = "/hospederias/login.do" logout_route = "/hospederias/logout.do" - - headers = { - "User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 " - "Build/MRA58N) AppleWebKit/537.36 (KHTML, like " - "Gecko) Chrome/90.0.4430.93 Mobile Safari/537.36", - } session = requests.session() login_payload = { - "usuario": pms_property.institution_user, - "pswd": pms_property.institution_password, + "usuario": record.institution_user, + "pswd": record.institution_password, } - # login response_login = session.post( url + login_route, @@ -66,7 +62,7 @@ class PmsProperty(models.Model): data=login_payload, verify=get_module_resource("pms_l10n_es", "static", "cert.pem"), ) - time.sleep(1) + time.sleep(0.1) # logout session.get( url + logout_route, @@ -96,3 +92,62 @@ class PmsProperty(models.Model): return message else: raise ValidationError(_("Connection could not be established")) + elif ( + record.institution == "policia_nacional" + and record.institution_property_id + and record.institution_user + and record.institution_password + ): + url = "https://webpol.policia.es/e-hotel" + pre_login_route = "/login" + login_route = "/execute_login" + home_route = "/inicio" + logout_route = "/execute_logout" + session = requests.session() + response_pre_login = session.post( + url + pre_login_route, + headers=headers, + verify=False, + ) + soup = bs(response_pre_login.text, "html.parser") + token = soup.select("input[name='_csrf']")[0]["value"] + time.sleep(0.1) + login_payload = { + "username": record.institution_user, + "password": record.institution_password, + "_csrf": token, + } + session.post( + url + login_route, + headers=headers, + data=login_payload, + verify=False, + ) + time.sleep(0.1) + response_home = session.get( + url + home_route, + headers=headers, + verify=False, + ) + soup = bs(response_home.text, "html.parser") + login_correct = soup.select("#datosUsuarioBanner") + if login_correct: + session.post( + url + logout_route, + headers=headers, + verify=False, + data={"_csrf": token}, + ) + + message = { + "type": "ir.actions.client", + "tag": "display_notification", + "params": { + "title": _("Connection Established!"), + "message": _("Connection established succesfully"), + "sticky": False, + }, + } + return message + else: + raise ValidationError(_("Connection could not be established")) diff --git a/pms_l10n_es/security/ir.model.access.csv b/pms_l10n_es/security/ir.model.access.csv index d8d1060d6..36ef563cc 100644 --- a/pms_l10n_es/security/ir.model.access.csv +++ b/pms_l10n_es/security/ir.model.access.csv @@ -1,2 +1,3 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink user_access_traveller_report_wizard,user_access_traveller_report_wizard,model_traveller_report_wizard,pms.group_pms_user,1,1,1,1 +user_access_traveller_report_logs,user_access_traveller_report_logs,model_pms_log_institution_traveller_report,pms.group_pms_user,1,1,1,1 diff --git a/pms_l10n_es/views/pms_log_institution_traveller_report_views.xml b/pms_l10n_es/views/pms_log_institution_traveller_report_views.xml new file mode 100644 index 000000000..362167d3a --- /dev/null +++ b/pms_l10n_es/views/pms_log_institution_traveller_report_views.xml @@ -0,0 +1,61 @@ + + + + pms.log.institution.traveller.report.form + pms.log.institution.traveller.report + +
+ + + + + + + + + +
+
+
+ + pms.log.institution.traveller.report.tree + pms.log.institution.traveller.report + + + + + + + + + + + + Log of sending files to institutions + pms.log.institution.traveller.report + tree,form + + +
diff --git a/pms_l10n_es/views/pms_property_views.xml b/pms_l10n_es/views/pms_property_views.xml index 53a3f0e34..117bc16e5 100644 --- a/pms_l10n_es/views/pms_property_views.xml +++ b/pms_l10n_es/views/pms_property_views.xml @@ -27,7 +27,7 @@