[ADD]pms_ocr_klippa: ADD klippa OCR basic flow

This commit is contained in:
Darío Lodeiros
2024-04-22 12:58:37 +02:00
parent 447becce0b
commit 2e3b69ed74
24 changed files with 851 additions and 274 deletions

View File

@@ -1,14 +1,4 @@
from datetime import date, datetime from datetime import datetime
from dateutil.relativedelta import relativedelta
from regula.documentreader.webclient import (
DocumentReaderApi,
ProcessParams,
RecognitionRequest,
Result,
Scenario,
TextFieldType,
)
from odoo.addons.base_rest import restapi from odoo.addons.base_rest import restapi
from odoo.addons.base_rest_datamodel.restapi import Datamodel from odoo.addons.base_rest_datamodel.restapi import Datamodel
@@ -35,225 +25,40 @@ class PmsOcr(Component):
auth="jwt_api_pms", auth="jwt_api_pms",
) )
def process_ocr_document(self, input_param): def process_ocr_document(self, input_param):
pms_property = self.env['pms.property'].browse(input_param.pmsPropertyId) pms_property = self.env["pms.property"].browse(input_param.pmsPropertyId)
ocr_find_method_name = '_%s_document_process' % pms_property.ocr_checkin_supplier ocr_find_method_name = (
checkin_data_dict = hasattr(self, ocr_find_method_name)( "_%s_document_process" % pms_property.ocr_checkin_supplier
input_param.imageBase64Front,
input_param.imageBase64Back
) )
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"] PmsOcrCheckinResult = self.env.datamodels["pms.ocr.checkin.result"]
return PmsOcrCheckinResult( return PmsOcrCheckinResult(
nationality=checkin_data_dict.get('nationality') or None, nationality=checkin_data_dict.get("nationality") or None,
countryId=checkin_data_dict.get('country_id') or None, countryId=checkin_data_dict.get("country_id") or None,
firstname=checkin_data_dict.get('firstname') or None, firstname=checkin_data_dict.get("firstname") or None,
lastname=checkin_data_dict.get('lastname') or None, lastname=checkin_data_dict.get("lastname") or None,
lastname2=checkin_data_dict.get('lastname2') or None, lastname2=checkin_data_dict.get("lastname2") or None,
gender=checkin_data_dict.get('gender') or None, gender=checkin_data_dict.get("gender") or None,
birthdate=checkin_data_dict.get('gender') or None, birthdate=datetime.strftime(
documentType=checkin_data_dict.get('document_type') or None, checkin_data_dict.get("birthdate"), "%Y-%m-%dT%H:%M:%S"
documentExpeditionDate=checkin_data_dict.get('document_expedition_date') or None, )
documentSupportNumber=checkin_data_dict.get('document_support_number') or None, if checkin_data_dict.get("birthdate")
documentNumber=checkin_data_dict.get('document_number') or None, else None,
residenceStreet=checkin_data_dict.get('residence_street') or None, documentType=checkin_data_dict.get("document_type") or None,
residenceCity=checkin_data_dict.get('residence_city') or None, documentExpeditionDate=datetime.strftime(
countryState=checkin_data_dict.get('country_state') or None, checkin_data_dict.get("document_expedition_date"), "%Y-%m-%dT%H:%M:%S"
documentCountryId=checkin_data_dict.get('document_country_id') or None, )
zip=checkin_data_dict.get('zip') or None 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

View File

@@ -91,7 +91,10 @@
</group> </group>
</xpath> </xpath>
<xpath expr="//field[@name='default_departure_hour']" position="after"> <xpath expr="//field[@name='default_departure_hour']" position="after">
<group string="OTAs API Configuration"> <group string="OCR Supplier Configuration">
<field name="ocr_checkin_supplier" />
</group>
<group string="OTAs API Configuration" colspan="8">
<field name="ota_property_settings_ids"> <field name="ota_property_settings_ids">
<tree name="OTAs" editable="bottom"> <tree name="OTAs" editable="bottom">
<field name="pms_property_id" invisible="1" /> <field name="pms_property_id" invisible="1" />

View File

@@ -18,7 +18,7 @@
domain="['&amp;',('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'))]" domain="['&amp;',('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'))]"
/> />
</group> </group>
<group string="Clien API configuration"> <group string="Client API configuration">
<field <field
name="pms_api_client" name="pms_api_client"
string="PMS API Client" string="PMS API Client"

81
pms_ocr_klippa/README.rst Normal file
View File

@@ -0,0 +1,81 @@
==========
OCR Klippa
==========
..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:0de4876412fe017db56d0ae207c4aa1f4f01394f57851ae281b5d94f5fc20c5f
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpms-lightgray.png?logo=github
:target: https://github.com/OCA/pms/tree/14.0/pms_ocr_klippa
:alt: OCA/pms
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/pms-14-0/pms-14-0-pms_ocr_klippa
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/pms&target_branch=14.0
:alt: Try me on Runboat
|badge1| |badge2| |badge3| |badge4| |badge5|
Module to connect the OCR Klippa with the pms
**Table of contents**
.. contents::
:local:
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 <https://github.com/OCA/pms/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 <https://github.com/OCA/pms/issues/new?body=module:%20pms_ocr_klippa%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues.
Credits
=======
Authors
~~~~~~~
* Commit [Sun]
Contributors
~~~~~~~~~~~~
* Brais <brais@roomdoo.com>
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 <https://github.com/OCA/pms/tree/14.0/pms_ocr_klippa>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@@ -0,0 +1 @@
from . import models

View File

@@ -0,0 +1,20 @@
# Copyright 2020-21 Jose Luis Algara (Alda Hotels <https://www.aldahotels.es>)
# 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,
}

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<data noupdate="1">
<record id="config_param_api_key_klippa" model="ir.config_parameter">
<field name="key">ocr_klippa_api_key</field>
<field name="value">False</field>
</record>
<record id="config_param_ocr_klippa_url" model="ir.config_parameter">
<field name="key">ocr_klippa_url</field>
<field
name="value"
>https://custom-ocr.klippa.com/api/v1/parseDocument/identity</field>
</record>
</data>
<data noupdate="0">
<record id="pms.document_type_passport" model="res.partner.id_category">
<field name="klippa_code">P</field>
<field name="klippa_subtype_code">P</field>
</record>
<record
id="pms.document_type_identification_document"
model="res.partner.id_category"
>
<field name="klippa_code">I</field>
<field name="klippa_subtype_code">I</field>
</record>
<record id="pms_l10n_es.document_type_dni" model="res.partner.id_category">
<field name="klippa_code">I</field>
<field name="klippa_subtype_code">D</field>
</record>
</data>
</odoo>

View File

@@ -0,0 +1,2 @@
from . import pms_property
from . import res_partner_id_category

View File

@@ -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, ""]

View File

@@ -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",
)

View File

@@ -0,0 +1 @@
* Brais <brais@roomdoo.com>

View File

@@ -0,0 +1 @@
Module to connect the OCR Klippa with the pms

View File

@@ -0,0 +1 @@
Set api key klippa and url parameters of the OCR service and select klippa provider ocr in pms_property

View File

@@ -0,0 +1,426 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>OCR Klippa</title>
<style type="text/css">
/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
*/
/* used to remove borders from tables and images */
.borderless, table.borderless td, table.borderless th {
border: 0 }
table.borderless td, table.borderless th {
/* Override padding for "table.docutils td" with "! important".
The right padding separates the table cells. */
padding: 0 0.5em 0 0 ! important }
.first {
/* Override more specific margin styles with "! important". */
margin-top: 0 ! important }
.last, .with-subtitle {
margin-bottom: 0 ! important }
.hidden {
display: none }
.subscript {
vertical-align: sub;
font-size: smaller }
.superscript {
vertical-align: super;
font-size: smaller }
a.toc-backref {
text-decoration: none ;
color: black }
blockquote.epigraph {
margin: 2em 5em ; }
dl.docutils dd {
margin-bottom: 0.5em }
object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
overflow: hidden;
}
/* Uncomment (and remove this text!) to get bold-faced definition list terms
dl.docutils dt {
font-weight: bold }
*/
div.abstract {
margin: 2em 5em }
div.abstract p.topic-title {
font-weight: bold ;
text-align: center }
div.admonition, div.attention, div.caution, div.danger, div.error,
div.hint, div.important, div.note, div.tip, div.warning {
margin: 2em ;
border: medium outset ;
padding: 1em }
div.admonition p.admonition-title, div.hint p.admonition-title,
div.important p.admonition-title, div.note p.admonition-title,
div.tip p.admonition-title {
font-weight: bold ;
font-family: sans-serif }
div.attention p.admonition-title, div.caution p.admonition-title,
div.danger p.admonition-title, div.error p.admonition-title,
div.warning p.admonition-title, .code .error {
color: red ;
font-weight: bold ;
font-family: sans-serif }
/* Uncomment (and remove this text!) to get reduced vertical space in
compound paragraphs.
div.compound .compound-first, div.compound .compound-middle {
margin-bottom: 0.5em }
div.compound .compound-last, div.compound .compound-middle {
margin-top: 0.5em }
*/
div.dedication {
margin: 2em 5em ;
text-align: center ;
font-style: italic }
div.dedication p.topic-title {
font-weight: bold ;
font-style: normal }
div.figure {
margin-left: 2em ;
margin-right: 2em }
div.footer, div.header {
clear: both;
font-size: smaller }
div.line-block {
display: block ;
margin-top: 1em ;
margin-bottom: 1em }
div.line-block div.line-block {
margin-top: 0 ;
margin-bottom: 0 ;
margin-left: 1.5em }
div.sidebar {
margin: 0 0 0.5em 1em ;
border: medium outset ;
padding: 1em ;
background-color: #ffffee ;
width: 40% ;
float: right ;
clear: right }
div.sidebar p.rubric {
font-family: sans-serif ;
font-size: medium }
div.system-messages {
margin: 5em }
div.system-messages h1 {
color: red }
div.system-message {
border: medium outset ;
padding: 1em }
div.system-message p.system-message-title {
color: red ;
font-weight: bold }
div.topic {
margin: 2em }
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
margin-top: 0.4em }
h1.title {
text-align: center }
h2.subtitle {
text-align: center }
hr.docutils {
width: 75% }
img.align-left, .figure.align-left, object.align-left, table.align-left {
clear: left ;
float: left ;
margin-right: 1em }
img.align-right, .figure.align-right, object.align-right, table.align-right {
clear: right ;
float: right ;
margin-left: 1em }
img.align-center, .figure.align-center, object.align-center {
display: block;
margin-left: auto;
margin-right: auto;
}
table.align-center {
margin-left: auto;
margin-right: auto;
}
.align-left {
text-align: left }
.align-center {
clear: both ;
text-align: center }
.align-right {
text-align: right }
/* reset inner alignment in figures */
div.align-right {
text-align: inherit }
/* div.align-center * { */
/* text-align: left } */
.align-top {
vertical-align: top }
.align-middle {
vertical-align: middle }
.align-bottom {
vertical-align: bottom }
ol.simple, ul.simple {
margin-bottom: 1em }
ol.arabic {
list-style: decimal }
ol.loweralpha {
list-style: lower-alpha }
ol.upperalpha {
list-style: upper-alpha }
ol.lowerroman {
list-style: lower-roman }
ol.upperroman {
list-style: upper-roman }
p.attribution {
text-align: right ;
margin-left: 50% }
p.caption {
font-style: italic }
p.credits {
font-style: italic ;
font-size: smaller }
p.label {
white-space: nowrap }
p.rubric {
font-weight: bold ;
font-size: larger ;
color: maroon ;
text-align: center }
p.sidebar-title {
font-family: sans-serif ;
font-weight: bold ;
font-size: larger }
p.sidebar-subtitle {
font-family: sans-serif ;
font-weight: bold }
p.topic-title {
font-weight: bold }
pre.address {
margin-bottom: 0 ;
margin-top: 0 ;
font: inherit }
pre.literal-block, pre.doctest-block, pre.math, pre.code {
margin-left: 2em ;
margin-right: 2em }
pre.code .ln { color: grey; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
pre.code .literal.string, code .literal.string { color: #0C5404 }
pre.code .name.builtin, code .name.builtin { color: #352B84 }
pre.code .deleted, code .deleted { background-color: #DEB0A1}
pre.code .inserted, code .inserted { background-color: #A3D289}
span.classifier {
font-family: sans-serif ;
font-style: oblique }
span.classifier-delimiter {
font-family: sans-serif ;
font-weight: bold }
span.interpreted {
font-family: sans-serif }
span.option {
white-space: nowrap }
span.pre {
white-space: pre }
span.problematic {
color: red }
span.section-subtitle {
/* font-size relative to parent (h1..h6 element) */
font-size: 80% }
table.citation {
border-left: solid 1px gray;
margin-left: 1px }
table.docinfo {
margin: 2em 4em }
table.docutils {
margin-top: 0.5em ;
margin-bottom: 0.5em }
table.footnote {
border-left: solid 1px black;
margin-left: 1px }
table.docutils td, table.docutils th,
table.docinfo td, table.docinfo th {
padding-left: 0.5em ;
padding-right: 0.5em ;
vertical-align: top }
table.docutils th.field-name, table.docinfo th.docinfo-name {
font-weight: bold ;
text-align: left ;
white-space: nowrap ;
padding-left: 0 }
/* "booktabs" style (no vertical lines) */
table.docutils.booktabs {
border: 0px;
border-top: 2px solid;
border-bottom: 2px solid;
border-collapse: collapse;
}
table.docutils.booktabs * {
border: 0px;
}
table.docutils.booktabs th {
border-bottom: thin solid;
text-align: left;
}
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
font-size: 100% }
ul.auto-toc {
list-style-type: none }
</style>
</head>
<body>
<div class="document" id="ocr-klippa">
<h1 class="title">OCR Klippa</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:0de4876412fe017db56d0ae207c4aa1f4f01394f57851ae281b5d94f5fc20c5f
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/pms/tree/14.0/pms_ocr_klippa"><img alt="OCA/pms" src="https://img.shields.io/badge/github-OCA%2Fpms-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/pms-14-0/pms-14-0-pms_ocr_klippa"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/pms&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>Module to connect the OCR Klippa with the pms</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#usage" id="toc-entry-1">Usage</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-2">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-3">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-4">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-5">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-6">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<p>Set api key klippa and url parameters of the OCR service and select klippa provider ocr in pms_property</p>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/pms/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/pms/issues/new?body=module:%20pms_ocr_klippa%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#toc-entry-3">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
<ul class="simple">
<li>Commit [Sun]</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<ul class="simple">
<li>Brais &lt;<a class="reference external" href="mailto:brais&#64;roomdoo.com">brais&#64;roomdoo.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/pms/tree/14.0/pms_ocr_klippa">OCA/pms</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_partner_id_category_form" model="ir.ui.view">
<field name="model">res.partner.id_category</field>
<field
name="inherit_id"
ref="partner_identification.view_partner_id_category_form"
/>
<field name="arch" type="xml">
<xpath expr="//field[@name='code']" position="after">
<field name="klippa_code" />
<field name="klippa_subtype_code" />
</xpath>
</field>
</record>
</odoo>

View File

@@ -7,7 +7,7 @@ OCR Regula
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:b34369f690039d9865de6496bc7fd3d815f16fb385b83e1e7d3db0e35ebabeb7 !! source digest: sha256:4db37aab9c7f834aaf48397c989242dd06463f3a2a4b652d4d7dc2def9584db4
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png .. |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 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 Bug Tracker
=========== ===========

View File

@@ -1,3 +1 @@
from . import models from . import models
from . import services
from . import datamodels

View File

@@ -15,6 +15,6 @@
"external_dependencies": { "external_dependencies": {
"python": ["regula.documentreader.webclient", "marshmallow"], "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, "installable": True,
} }

View File

@@ -1,3 +1,6 @@
from datetime import date, datetime
from dateutil.relativedelta import relativedelta
from regula.documentreader.webclient import ( from regula.documentreader.webclient import (
DocumentReaderApi, DocumentReaderApi,
ProcessParams, ProcessParams,
@@ -6,19 +9,14 @@ from regula.documentreader.webclient import (
Scenario, Scenario,
TextFieldType, TextFieldType,
) )
from datetime import date, datetime
from dateutil.relativedelta import relativedelta
from odoo import fields, models from odoo import fields, models
class PmsProperty(models.Model): class PmsProperty(models.Model):
_inherit = "pms.property" _inherit = "pms.property"
ocr_checkin_supplier = fields.Selection( ocr_checkin_supplier = fields.Selection(selection_add=[("regula", "Regula")])
selection_add=["regula", "Regula"]
)
def _regula_document_process(self, image_base_64_front, image_base_64_back=False): def _regula_document_process(self, image_base_64_front, image_base_64_back=False):
ocr_regula_url = ( ocr_regula_url = (
@@ -58,16 +56,16 @@ class PmsProperty(models.Model):
) )
pms_ocr_checkin_result = dict() pms_ocr_checkin_result = dict()
if country_id: if country_id:
pms_ocr_checkin_result['nationality'] = country_id pms_ocr_checkin_result["nationality"] = country_id
if firstname: if firstname:
pms_ocr_checkin_result['firstname'] = firstname pms_ocr_checkin_result["firstname"] = firstname
if lastname: if lastname:
pms_ocr_checkin_result['lastname'] = lastname pms_ocr_checkin_result["lastname"] = lastname
if lastname2: if lastname2:
pms_ocr_checkin_result['lastname2'] = lastname2 pms_ocr_checkin_result["lastname2"] = lastname2
gender = response.text.get_field(TextFieldType.SEX) gender = response.text.get_field(TextFieldType.SEX)
if gender and gender.value != "": if gender and gender.value != "":
pms_ocr_checkin_result['gender'] = ( pms_ocr_checkin_result["gender"] = (
"male" "male"
if gender.value == "M" if gender.value == "M"
else "female" else "female"
@@ -76,7 +74,7 @@ class PmsProperty(models.Model):
) )
date_of_birth = response.text.get_field(TextFieldType.DATE_OF_BIRTH) date_of_birth = response.text.get_field(TextFieldType.DATE_OF_BIRTH)
if date_of_birth and date_of_birth.value != "": if date_of_birth and date_of_birth.value != "":
pms_ocr_checkin_result['birthdate'] = ( pms_ocr_checkin_result["birthdate"] = (
datetime.strptime( datetime.strptime(
date_of_birth.value.replace("-", "/"), "%Y/%m/%d" 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 != ""
and document_class_code.value == "P" and document_class_code.value == "P"
): ):
pms_ocr_checkin_result['documentType'] = ( pms_ocr_checkin_result["documentType"] = (
self.env["res.partner.id_category"] self.env["res.partner.id_category"]
.search([("code", "=", "P")]) .search([("code", "=", "P")])
.id .id
@@ -108,11 +106,11 @@ class PmsProperty(models.Model):
age, age,
date_of_birth, 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 != "": elif date_of_issue and date_of_issue.value != "":
pms_ocr_checkin_result['documentExpeditionDate'] = ( pms_ocr_checkin_result[
date_of_issue.value.replace("-", "/") "documentExpeditionDate"
) ] = date_of_issue.value.replace("-", "/")
support_number, document_number = self._proccess_document_number( support_number, document_number = self._proccess_document_number(
id_country_spain, id_country_spain,
country_id, country_id,
@@ -121,9 +119,9 @@ class PmsProperty(models.Model):
response.text.get_field(TextFieldType.PERSONAL_NUMBER), response.text.get_field(TextFieldType.PERSONAL_NUMBER),
) )
if support_number: if support_number:
pms_ocr_checkin_result['documentSupportNumber'] = support_number pms_ocr_checkin_result["documentSupportNumber"] = support_number
if document_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( address_street, address_city, address_area = self._process_address(
id_country_spain, id_country_spain,
country_id, country_id,
@@ -133,11 +131,11 @@ class PmsProperty(models.Model):
response.text.get_field(TextFieldType.ADDRESS), response.text.get_field(TextFieldType.ADDRESS),
) )
if address_street: if address_street:
pms_ocr_checkin_result['residenceStreet'] = address_street pms_ocr_checkin_result["residenceStreet"] = address_street
if address_city: if address_city:
pms_ocr_checkin_result['residenceCity'] = address_city pms_ocr_checkin_result["residenceCity"] = address_city
if address_area: if address_area:
pms_ocr_checkin_result['countryState'] = address_area pms_ocr_checkin_result["countryState"] = address_area
return pms_ocr_checkin_result return pms_ocr_checkin_result
def _process_nationality( def _process_nationality(

View File

@@ -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

View File

@@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:b34369f690039d9865de6496bc7fd3d815f16fb385b83e1e7d3db0e35ebabeb7 !! source digest: sha256:4db37aab9c7f834aaf48397c989242dd06463f3a2a4b652d4d7dc2def9584db4
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/pms/tree/14.0/pms_ocr_regula"><img alt="OCA/pms" src="https://img.shields.io/badge/github-OCA%2Fpms-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/pms-14-0/pms-14-0-pms_ocr_regula"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/pms&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p> <p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/pms/tree/14.0/pms_ocr_regula"><img alt="OCA/pms" src="https://img.shields.io/badge/github-OCA%2Fpms-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/pms-14-0/pms-14-0-pms_ocr_regula"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/pms&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>Module to connect the OCR regula with the pms</p> <p>Module to connect the OCR regula with the pms</p>
@@ -386,7 +386,7 @@ ul.auto-toc {
</div> </div>
<div class="section" id="usage"> <div class="section" id="usage">
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1> <h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<p>Set api key regula and url parameters of the OCR service and activate the is_used_regula field in pms_property</p> <p>Set api key klippa and url parameters of the OCR service and select regula provider ocr in pms_property</p>
</div> </div>
<div class="section" id="bug-tracker"> <div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1> <h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>

View File

@@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="regula_pms_property_views_inherit" model="ir.ui.view">
<field name="model">pms.property</field>
<field name="inherit_id" ref="pms.pms_property_views_form" />
<field name="arch" type="xml">
<xpath expr="//page[@name='property_settings']" position="inside">
<group string="OCR Regula">
<field name="is_used_regula" widget="boolean_toggle" />
</group>
</xpath>
</field>
</record>
</odoo>

View File

@@ -0,0 +1 @@
../../../../pms_ocr_klippa

View File

@@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)