[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

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

View File

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

View File

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

View File

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

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 !!
!! 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>Module to connect the OCR regula with the pms</p>
@@ -386,7 +386,7 @@ ul.auto-toc {
</div>
<div class="section" id="usage">
<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 class="section" id="bug-tracker">
<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>