diff --git a/pms_api_rest/services/ocr_document_service.py b/pms_api_rest/services/ocr_document_service.py index bb518e0ed..1d1424888 100644 --- a/pms_api_rest/services/ocr_document_service.py +++ b/pms_api_rest/services/ocr_document_service.py @@ -1,14 +1,4 @@ -from datetime import date, datetime - -from dateutil.relativedelta import relativedelta -from regula.documentreader.webclient import ( - DocumentReaderApi, - ProcessParams, - RecognitionRequest, - Result, - Scenario, - TextFieldType, -) +from datetime import datetime from odoo.addons.base_rest import restapi from odoo.addons.base_rest_datamodel.restapi import Datamodel @@ -35,225 +25,40 @@ class PmsOcr(Component): auth="jwt_api_pms", ) def process_ocr_document(self, input_param): - pms_property = self.env['pms.property'].browse(input_param.pmsPropertyId) - ocr_find_method_name = '_%s_document_process' % pms_property.ocr_checkin_supplier - checkin_data_dict = hasattr(self, ocr_find_method_name)( - input_param.imageBase64Front, - input_param.imageBase64Back + pms_property = self.env["pms.property"].browse(input_param.pmsPropertyId) + ocr_find_method_name = ( + "_%s_document_process" % pms_property.ocr_checkin_supplier ) + if hasattr(pms_property, ocr_find_method_name): + checkin_data_dict = getattr(pms_property, ocr_find_method_name)( + input_param.imageBase64Front, input_param.imageBase64Back + ) PmsOcrCheckinResult = self.env.datamodels["pms.ocr.checkin.result"] return PmsOcrCheckinResult( - nationality=checkin_data_dict.get('nationality') or None, - countryId=checkin_data_dict.get('country_id') or None, - firstname=checkin_data_dict.get('firstname') or None, - lastname=checkin_data_dict.get('lastname') or None, - lastname2=checkin_data_dict.get('lastname2') or None, - gender=checkin_data_dict.get('gender') or None, - birthdate=checkin_data_dict.get('gender') or None, - documentType=checkin_data_dict.get('document_type') or None, - documentExpeditionDate=checkin_data_dict.get('document_expedition_date') or None, - documentSupportNumber=checkin_data_dict.get('document_support_number') or None, - documentNumber=checkin_data_dict.get('document_number') or None, - residenceStreet=checkin_data_dict.get('residence_street') or None, - residenceCity=checkin_data_dict.get('residence_city') or None, - countryState=checkin_data_dict.get('country_state') or None, - documentCountryId=checkin_data_dict.get('document_country_id') or None, - zip=checkin_data_dict.get('zip') or None + nationality=checkin_data_dict.get("nationality") or None, + countryId=checkin_data_dict.get("country_id") or None, + firstname=checkin_data_dict.get("firstname") or None, + lastname=checkin_data_dict.get("lastname") or None, + lastname2=checkin_data_dict.get("lastname2") or None, + gender=checkin_data_dict.get("gender") or None, + birthdate=datetime.strftime( + checkin_data_dict.get("birthdate"), "%Y-%m-%dT%H:%M:%S" + ) + if checkin_data_dict.get("birthdate") + else None, + documentType=checkin_data_dict.get("document_type") or None, + documentExpeditionDate=datetime.strftime( + checkin_data_dict.get("document_expedition_date"), "%Y-%m-%dT%H:%M:%S" + ) + if checkin_data_dict.get("document_expedition_date") + else None, + documentSupportNumber=checkin_data_dict.get("document_support_number") + or None, + documentNumber=checkin_data_dict.get("document_number") or None, + residenceStreet=checkin_data_dict.get("residence_street") or None, + residenceCity=checkin_data_dict.get("residence_city") or None, + countryState=checkin_data_dict.get("country_state") or None, + documentCountryId=checkin_data_dict.get("document_country_id") or None, + zip=checkin_data_dict.get("zip") or None, ) - - def process_nationality( - self, nationality, nationality_code, nationality_code_numeric - ): - country_id = False - country = False - if nationality_code_numeric and nationality_code_numeric.value != "": - country = self.env["res.country"].search( - [("code_numeric", "=", nationality_code_numeric.value)] - ) - elif nationality_code and nationality_code.value != "": - country = self.env["res.country"].search( - [("code_alpha3", "=", nationality_code.value)] - ) - elif nationality and nationality.value != "": - country = self.env["res.country"].search([("name", "=", nationality.value)]) - - if country: - country_id = country.id - - return country_id - - def process_address( - self, - id_country_spain, - country_id, - address_street, - address_city, - address_area, - address, - ): - res_address_street = False - res_address_city = False - res_address_area = False - state = False - if country_id == id_country_spain: - if address_street and address_street.value != "": - res_address_street = address_street.value - if address_city and address_city.value != "": - res_address_city = address_city.value - if address_area and address_area.value != "": - res_address_area = address_area.value - if ( - address - and address != "" - and not (all([address_street, address_city, address_area])) - ): - address = address.value.replace("^", " ") - address_list = address.split(" ") - if not res_address_area: - res_address_area = address_list[-1] - if not res_address_city: - res_address_city = address_list[-2] - if not res_address_street: - res_address_street = address.replace( - res_address_area, "", 1 - ).replace(res_address_city, "", 1) - if res_address_area: - state = self.env["res.country.state"].search( - [("name", "ilike", res_address_area)] - ) - if state and len(state) == 1: - state = state.id - else: - if address and address.value != "": - res_address_street = address.value.replace("^", " ") - return res_address_street, res_address_city, state - - def process_name( - self, - id_country_spain, - country_id, - given_names, - first_surname, - second_surname, - surname, - surname_and_given_names, - ): - firstname = False - lastname = False - lastname2 = False - - if surname_and_given_names.value and surname_and_given_names.value != "": - surname_and_given_names = surname_and_given_names.value.replace("^", " ") - - if given_names and given_names.value != "": - firstname = given_names.value - - if first_surname and first_surname.value != "": - lastname = first_surname.value - - if second_surname and second_surname.value != "": - lastname2 = second_surname.value - - if country_id == id_country_spain and not ( - all([firstname, lastname, lastname2]) - ): - if surname and surname.value != "": - lastname = lastname if lastname else surname.value.split(" ")[0] - lastname2 = lastname2 if lastname2 else surname.value.split(" ")[1:][0] - if ( - surname_and_given_names - and surname_and_given_names != "" - and not firstname - ): - firstname = surname_and_given_names.replace( - lastname, "", 1 - ).replace(lastname2, "", 1) - elif surname_and_given_names and surname_and_given_names != "": - lastname = ( - lastname if lastname else surname_and_given_names.split(" ")[0] - ) - lastname2 = ( - lastname2 if lastname2 else surname_and_given_names.split(" ")[1] - ) - firstname = ( - firstname - if firstname - else surname_and_given_names.replace(lastname, "", 1).replace( - lastname2, "", 1 - ) - ) - elif ( - country_id - and country_id != id_country_spain - and not (all([firstname, lastname])) - ): - if surname and surname.value != "": - lastname = lastname if lastname else surname.value - if ( - surname_and_given_names - and surname_and_given_names != "" - and not firstname - ): - firstname = surname_and_given_names.replace(lastname, "", 1) - elif surname_and_given_names and surname_and_given_names != "": - lastname = ( - lastname if lastname else surname_and_given_names.split(" ")[0] - ) - firstname = ( - firstname - if firstname - else surname_and_given_names.replace(lastname, "", 1) - ) - return firstname, lastname, lastname2 - - def calc_expedition_date( - self, document_class_code, date_of_expiry, age, date_of_birth - ): - result = False - person_age = False - if age and age.value != "": - person_age = int(age.value) - elif date_of_birth and date_of_birth.value != "": - date_of_birth = datetime.strptime( - date_of_birth.value.replace("-", "/"), "%Y/%m/%d" - ).date() - person_age = relativedelta(date.today(), date_of_birth).years - if date_of_expiry and date_of_expiry.value != "" and person_age: - date_of_expiry = datetime.strptime( - date_of_expiry.value.replace("-", "/"), "%Y/%m/%d" - ).date() - if person_age < 30: - result = date_of_expiry - relativedelta(years=5) - elif ( - person_age >= 30 - and document_class_code - and document_class_code.value == "P" - ): - result = date_of_expiry - relativedelta(years=10) - elif 30 <= person_age < 70: - result = date_of_expiry - relativedelta(years=10) - return result.isoformat() if result else False - - def proccess_document_number( - self, - id_country_spain, - country_id, - document_class_code, - document_number, - personal_number, - ): - res_support_number = False - res_document_number = False - if personal_number and personal_number.value != "": - res_document_number = personal_number.value - if document_number and document_number.value != "": - res_support_number = document_number.value - if ( - country_id == id_country_spain - and document_class_code - and document_class_code.value != "P" - ): - return res_support_number, res_document_number - else: - return False, res_support_number diff --git a/pms_api_rest/views/pms_property_views.xml b/pms_api_rest/views/pms_property_views.xml index e0b528615..f419ad45e 100644 --- a/pms_api_rest/views/pms_property_views.xml +++ b/pms_api_rest/views/pms_property_views.xml @@ -91,7 +91,10 @@ - + + + + diff --git a/pms_api_rest/views/res_users_views.xml b/pms_api_rest/views/res_users_views.xml index c639349d5..39570f6b9 100644 --- a/pms_api_rest/views/res_users_views.xml +++ b/pms_api_rest/views/res_users_views.xml @@ -18,7 +18,7 @@ domain="['&',('model_id', '=', 'pms.availability.plan.rule'), ('name', 'in', ('min_stay', 'max_stay', 'quota', 'max_stay_arrival', 'closed_arrival', 'closed', 'closed_departure', 'min_stay_arrival', 'max_avail'))]" /> - + `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Commit [Sun] + +Contributors +~~~~~~~~~~~~ + +* Brais + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/pms `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/pms_ocr_klippa/__init__.py b/pms_ocr_klippa/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/pms_ocr_klippa/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/pms_ocr_klippa/__manifest__.py b/pms_ocr_klippa/__manifest__.py new file mode 100644 index 000000000..58d22ddd1 --- /dev/null +++ b/pms_ocr_klippa/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2020-21 Jose Luis Algara (Alda Hotels ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "OCR Klippa", + "version": "14.0.1.0.1", + "author": "Commit [Sun], Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": True, + "category": "Generic Modules/Property Management System", + "website": "https://github.com/OCA/pms", + "depends": [ + "pms_api_rest", + ], + "data": [ + "data/pms_ocr_klippa_data.xml", + "views/res_partner_id_category_views.xml", + ], + "installable": True, +} diff --git a/pms_ocr_klippa/data/pms_ocr_klippa_data.xml b/pms_ocr_klippa/data/pms_ocr_klippa_data.xml new file mode 100644 index 000000000..51274094d --- /dev/null +++ b/pms_ocr_klippa/data/pms_ocr_klippa_data.xml @@ -0,0 +1,32 @@ + + + + + ocr_klippa_api_key + False + + + ocr_klippa_url + https://custom-ocr.klippa.com/api/v1/parseDocument/identity + + + + + P + P + + + I + I + + + I + D + + + diff --git a/pms_ocr_klippa/models/__init__.py b/pms_ocr_klippa/models/__init__.py new file mode 100644 index 000000000..45a7df3f4 --- /dev/null +++ b/pms_ocr_klippa/models/__init__.py @@ -0,0 +1,2 @@ +from . import pms_property +from . import res_partner_id_category diff --git a/pms_ocr_klippa/models/pms_property.py b/pms_ocr_klippa/models/pms_property.py new file mode 100644 index 000000000..c1b9503db --- /dev/null +++ b/pms_ocr_klippa/models/pms_property.py @@ -0,0 +1,187 @@ +from datetime import date, datetime + +import requests +from dateutil.relativedelta import relativedelta + +from odoo import _, fields, models +from odoo.exceptions import ValidationError + + +class PmsProperty(models.Model): + _inherit = "pms.property" + + ocr_checkin_supplier = fields.Selection(selection_add=[("klippa", "Klippa")]) + + # flake8: noqa: C901 + def _klippa_document_process(self, image_base_64_front, image_base_64_back=False): + ocr_klippa_url = ( + self.env["ir.config_parameter"].sudo().get_param("ocr_klippa_url") + ) + ocr_klippa_api_key = ( + self.env["ir.config_parameter"].sudo().get_param("ocr_klippa_api_key") + ) + document = [] + if image_base_64_back: + document.append(image_base_64_front) + if image_base_64_back: + document.append(image_base_64_back) + if not document: + raise ValidationError(_("No document image found")) + + headers = { + "X-Auth-Key": ocr_klippa_api_key, + "Content-Type": "application/json", + } + payload = { + "document": document, + } + + # Call Klippa OCR API + result = requests.post( + ocr_klippa_url, + headers=headers, + json=payload, + ) + json_data = result.json() + if json_data.get("result") != "success": + raise ValidationError(_("Error calling Klippa OCR API")) + document_data = json_data["data"]["parsed"] + mapped_data = {} + for key, dict_value in document_data.items(): + if dict_value and isinstance(dict_value, dict): + value = dict_value.get("value", False) + else: + continue + # Residence Address -------------------------------------------------- + if key == "address" and value: + if "street_name" in value: + mapped_data["residence_street"] = value["street_name"] + ( + " " + value["house_number"] if "house_number" in value else "" + ) + if "city" in value: + mapped_data["residence_city"] = value["city"] + if "postcode" in value: + mapped_data["zip"] = value["postcode"] + if "province" in value: + mapped_data["residence_state_id"] = ( + self.env["res.country.state"] + .search( + [ + ("name", "ilike", value["province"]), + ( + "country_id", + "=", + self._get_country_id(value.get("country", False)), + ), + ] + ) + .id + or False + ) + + # Document Data -------------------------------------------------- + elif key == "issuing_country" and value: + mapped_data["document_country_id"] = self._get_country_id(value) + elif key == "document_number" and value: + mapped_data["document_support_number"] = value + elif key == "document_type" and value: + mapped_data["document_type"] = self._get_document_type( + klippa_type=value, + klippa_subtype=document_data.get("document_subtype", False), + ) + elif key == "personal_number" and value: + mapped_data["document_number"] = value + elif key == "date_of_issue" and value: + mapped_data["document_expedition_date"] = datetime.strptime( + value, "%Y-%m-%dT%H:%M:%S" + ).date() + elif ( + key == "date_of_expiry" + and value + and not document_data.get("date_of_issue", False) + ): + mapped_data["document_expiration_date"] = self._calc_expedition_date( + document_class_code=self._get_document_type( + klippa_type=document_data.get("document_class_code", False), + klippa_subtype=document_data.get("document_subtype", False), + ), + date_of_expiry=value, + age=False, + date_of_birth=document_data.get("date_of_birth", False), + ) + + # Personal Data -------------------------------------------------- + elif key == "gender" and value: + if value == "M": + mapped_data["gender"] = "male" + elif value == "F": + mapped_data["gender"] = "female" + else: + mapped_data["gender"] = "other" + elif key == "given_names" and value: + mapped_data["firstname"] = value + elif key == "surname" and value: + mapped_data["lastname"] = self._get_surnames( + origin_surname=value, + )[0] + mapped_data["lastname2"] = self._get_surnames( + origin_surname=value, + )[1] + elif key == "date_of_birth" and value: + mapped_data["birthdate"] = datetime.strptime( + value, "%Y-%m-%dT%H:%M:%S" + ).date() + elif key == "nationality" and value: + mapped_data["nationality"] = self._get_country_id(value) + return mapped_data + + def _calc_expedition_date(self, document_type, date_of_expiry, age, date_of_birth): + result = False + person_age = False + if age and age.value != "": + person_age = int(age.value) + elif date_of_birth and date_of_birth.value != "": + date_of_birth = datetime.strptime( + date_of_birth.value.replace("-", "/"), "%Y-%m-%dT%H:%M:%S" + ).date() + person_age = relativedelta(date.today(), date_of_birth).years + if date_of_expiry and date_of_expiry.value != "" and person_age: + date_of_expiry = datetime.strptime( + date_of_expiry.value.replace("-", "/"), "%Y-%m-%dT%H:%M:%S" + ).date() + if person_age < 30: + result = date_of_expiry - relativedelta(years=5) + elif person_age >= 30 and document_type and document_type.code == "P": + result = date_of_expiry - relativedelta(years=10) + elif 30 <= person_age < 70: + result = date_of_expiry - relativedelta(years=10) + return result.isoformat() if result else False + + def _get_document_type(self, klippa_type, klippa_subtype): + document_type_ids = self.env["res.partner.id_category"].search( + [ + ("klippa_code", "=", klippa_type), + ] + ) + if not document_type_ids: + raise ValidationError(_(f"Document type not found: {klippa_type}")) + document_type_id = document_type_ids[0] + if len(document_type_ids) > 1: + document_type_id = document_type_ids.filtered( + lambda r: r.klippa_subtype_code == klippa_subtype + ).id + return document_type_id + + def _get_country_id(self, country_code): + return ( + self.env["res.country"] + .search([("code_alpha3", "=", country_code)], limit=1) + .id + ) + + def _get_surnames(self, origin_surname): + # If origin surname has two or more surnames + if " " in origin_surname: + return origin_surname.split(" ") + else: + return [origin_surname, ""] diff --git a/pms_ocr_klippa/models/res_partner_id_category.py b/pms_ocr_klippa/models/res_partner_id_category.py new file mode 100644 index 000000000..ebcf7d021 --- /dev/null +++ b/pms_ocr_klippa/models/res_partner_id_category.py @@ -0,0 +1,12 @@ +from odoo import fields, models + + +class ResPartnerIdCategory(models.Model): + _inherit = "res.partner.id_category" + + klippa_code = fields.Char( + string="Klippa Code", + ) + klippa_subtype_code = fields.Char( + string="Klippa Subtype Code", + ) diff --git a/pms_ocr_klippa/readme/CONTRIBUTORS.rst b/pms_ocr_klippa/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..2401152c0 --- /dev/null +++ b/pms_ocr_klippa/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Brais diff --git a/pms_ocr_klippa/readme/DESCRIPTION.rst b/pms_ocr_klippa/readme/DESCRIPTION.rst new file mode 100644 index 000000000..bd81b811d --- /dev/null +++ b/pms_ocr_klippa/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Module to connect the OCR Klippa with the pms diff --git a/pms_ocr_klippa/readme/USAGE.rst b/pms_ocr_klippa/readme/USAGE.rst new file mode 100644 index 000000000..b556f7469 --- /dev/null +++ b/pms_ocr_klippa/readme/USAGE.rst @@ -0,0 +1 @@ +Set api key klippa and url parameters of the OCR service and select klippa provider ocr in pms_property diff --git a/pms_ocr_klippa/static/description/index.html b/pms_ocr_klippa/static/description/index.html new file mode 100644 index 000000000..959844b8b --- /dev/null +++ b/pms_ocr_klippa/static/description/index.html @@ -0,0 +1,426 @@ + + + + + + +OCR Klippa + + + +
+

OCR Klippa

+ + +

Beta License: AGPL-3 OCA/pms Translate me on Weblate Try me on Runboat

+

Module to connect the OCR Klippa with the pms

+

Table of contents

+ +
+

Usage

+

Set api key klippa and url parameters of the OCR service and select klippa provider ocr in pms_property

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Commit [Sun]
  • +
+
+ +
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/pms project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/pms_ocr_klippa/views/res_partner_id_category_views.xml b/pms_ocr_klippa/views/res_partner_id_category_views.xml new file mode 100644 index 000000000..99bb52068 --- /dev/null +++ b/pms_ocr_klippa/views/res_partner_id_category_views.xml @@ -0,0 +1,16 @@ + + + + res.partner.id_category + + + + + + + + + diff --git a/pms_ocr_regula/README.rst b/pms_ocr_regula/README.rst index 7f2338b2e..f9fe1e2f9 100644 --- a/pms_ocr_regula/README.rst +++ b/pms_ocr_regula/README.rst @@ -7,7 +7,7 @@ OCR Regula !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:b34369f690039d9865de6496bc7fd3d815f16fb385b83e1e7d3db0e35ebabeb7 + !! source digest: sha256:4db37aab9c7f834aaf48397c989242dd06463f3a2a4b652d4d7dc2def9584db4 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png @@ -38,7 +38,7 @@ Module to connect the OCR regula with the pms Usage ===== -Set api key regula and url parameters of the OCR service and activate the is_used_regula field in pms_property +Set api key klippa and url parameters of the OCR service and select regula provider ocr in pms_property Bug Tracker =========== diff --git a/pms_ocr_regula/__init__.py b/pms_ocr_regula/__init__.py index c82439595..0650744f6 100644 --- a/pms_ocr_regula/__init__.py +++ b/pms_ocr_regula/__init__.py @@ -1,3 +1 @@ from . import models -from . import services -from . import datamodels diff --git a/pms_ocr_regula/__manifest__.py b/pms_ocr_regula/__manifest__.py index 6bf93f99e..2bb0bbed0 100644 --- a/pms_ocr_regula/__manifest__.py +++ b/pms_ocr_regula/__manifest__.py @@ -15,6 +15,6 @@ "external_dependencies": { "python": ["regula.documentreader.webclient", "marshmallow"], }, - "data": ["views/pms_property_views.xml", "data/pms_ocr_regula_data.xml"], + "data": ["data/pms_ocr_regula_data.xml"], "installable": True, } diff --git a/pms_ocr_regula/models/pms_property.py b/pms_ocr_regula/models/pms_property.py index abd24850a..340d0d0e5 100644 --- a/pms_ocr_regula/models/pms_property.py +++ b/pms_ocr_regula/models/pms_property.py @@ -1,3 +1,6 @@ +from datetime import date, datetime + +from dateutil.relativedelta import relativedelta from regula.documentreader.webclient import ( DocumentReaderApi, ProcessParams, @@ -6,19 +9,14 @@ from regula.documentreader.webclient import ( Scenario, TextFieldType, ) -from datetime import date, datetime -from dateutil.relativedelta import relativedelta from odoo import fields, models - class PmsProperty(models.Model): _inherit = "pms.property" - ocr_checkin_supplier = fields.Selection( - selection_add=["regula", "Regula"] - ) + ocr_checkin_supplier = fields.Selection(selection_add=[("regula", "Regula")]) def _regula_document_process(self, image_base_64_front, image_base_64_back=False): ocr_regula_url = ( @@ -58,16 +56,16 @@ class PmsProperty(models.Model): ) pms_ocr_checkin_result = dict() if country_id: - pms_ocr_checkin_result['nationality'] = country_id + pms_ocr_checkin_result["nationality"] = country_id if firstname: - pms_ocr_checkin_result['firstname'] = firstname + pms_ocr_checkin_result["firstname"] = firstname if lastname: - pms_ocr_checkin_result['lastname'] = lastname + pms_ocr_checkin_result["lastname"] = lastname if lastname2: - pms_ocr_checkin_result['lastname2'] = lastname2 + pms_ocr_checkin_result["lastname2"] = lastname2 gender = response.text.get_field(TextFieldType.SEX) if gender and gender.value != "": - pms_ocr_checkin_result['gender'] = ( + pms_ocr_checkin_result["gender"] = ( "male" if gender.value == "M" else "female" @@ -76,7 +74,7 @@ class PmsProperty(models.Model): ) date_of_birth = response.text.get_field(TextFieldType.DATE_OF_BIRTH) if date_of_birth and date_of_birth.value != "": - pms_ocr_checkin_result['birthdate'] = ( + pms_ocr_checkin_result["birthdate"] = ( datetime.strptime( date_of_birth.value.replace("-", "/"), "%Y/%m/%d" ) @@ -93,7 +91,7 @@ class PmsProperty(models.Model): and document_class_code.value != "" and document_class_code.value == "P" ): - pms_ocr_checkin_result['documentType'] = ( + pms_ocr_checkin_result["documentType"] = ( self.env["res.partner.id_category"] .search([("code", "=", "P")]) .id @@ -108,11 +106,11 @@ class PmsProperty(models.Model): age, date_of_birth, ) - pms_ocr_checkin_result['documentExpeditionDate'] = date_of_issue + pms_ocr_checkin_result["documentExpeditionDate"] = date_of_issue elif date_of_issue and date_of_issue.value != "": - pms_ocr_checkin_result['documentExpeditionDate'] = ( - date_of_issue.value.replace("-", "/") - ) + pms_ocr_checkin_result[ + "documentExpeditionDate" + ] = date_of_issue.value.replace("-", "/") support_number, document_number = self._proccess_document_number( id_country_spain, country_id, @@ -121,9 +119,9 @@ class PmsProperty(models.Model): response.text.get_field(TextFieldType.PERSONAL_NUMBER), ) if support_number: - pms_ocr_checkin_result['documentSupportNumber'] = support_number + pms_ocr_checkin_result["documentSupportNumber"] = support_number if document_number: - pms_ocr_checkin_result['documentNumber'] = document_number + pms_ocr_checkin_result["documentNumber"] = document_number address_street, address_city, address_area = self._process_address( id_country_spain, country_id, @@ -133,11 +131,11 @@ class PmsProperty(models.Model): response.text.get_field(TextFieldType.ADDRESS), ) if address_street: - pms_ocr_checkin_result['residenceStreet'] = address_street + pms_ocr_checkin_result["residenceStreet"] = address_street if address_city: - pms_ocr_checkin_result['residenceCity'] = address_city + pms_ocr_checkin_result["residenceCity"] = address_city if address_area: - pms_ocr_checkin_result['countryState'] = address_area + pms_ocr_checkin_result["countryState"] = address_area return pms_ocr_checkin_result def _process_nationality( diff --git a/pms_ocr_regula/readme/USAGE.rst b/pms_ocr_regula/readme/USAGE.rst index d74b8cd5d..4da449a3c 100644 --- a/pms_ocr_regula/readme/USAGE.rst +++ b/pms_ocr_regula/readme/USAGE.rst @@ -1 +1 @@ -Set api key regula and url parameters of the OCR service and activate the is_used_regula field in pms_property +Set api key klippa and url parameters of the OCR service and select regula provider ocr in pms_property diff --git a/pms_ocr_regula/static/description/index.html b/pms_ocr_regula/static/description/index.html index 77909fefb..98ac023e2 100644 --- a/pms_ocr_regula/static/description/index.html +++ b/pms_ocr_regula/static/description/index.html @@ -367,7 +367,7 @@ ul.auto-toc { !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:b34369f690039d9865de6496bc7fd3d815f16fb385b83e1e7d3db0e35ebabeb7 +!! source digest: sha256:4db37aab9c7f834aaf48397c989242dd06463f3a2a4b652d4d7dc2def9584db4 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Beta License: AGPL-3 OCA/pms Translate me on Weblate Try me on Runboat

Module to connect the OCR regula with the pms

@@ -386,7 +386,7 @@ ul.auto-toc {

Usage

-

Set api key regula and url parameters of the OCR service and activate the is_used_regula field in pms_property

+

Set api key klippa and url parameters of the OCR service and select regula provider ocr in pms_property

Bug Tracker

diff --git a/pms_ocr_regula/views/pms_property_views.xml b/pms_ocr_regula/views/pms_property_views.xml deleted file mode 100644 index b7776c60b..000000000 --- a/pms_ocr_regula/views/pms_property_views.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - pms.property - - - - - - - - - - diff --git a/setup/pms_ocr_klippa/odoo/addons/pms_ocr_klippa b/setup/pms_ocr_klippa/odoo/addons/pms_ocr_klippa new file mode 120000 index 000000000..8ef547b31 --- /dev/null +++ b/setup/pms_ocr_klippa/odoo/addons/pms_ocr_klippa @@ -0,0 +1 @@ +../../../../pms_ocr_klippa \ No newline at end of file diff --git a/setup/pms_ocr_klippa/setup.py b/setup/pms_ocr_klippa/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/pms_ocr_klippa/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)