mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[ADD]14.0-pms_ocr_regula: module to connect the OCR regula with the pms
This commit is contained in:
@@ -65,3 +65,4 @@ from . import feed_post
|
||||
|
||||
from . import pms_wizard_state
|
||||
|
||||
from . import pms_ocr
|
||||
|
||||
26
pms_api_rest/datamodels/pms_ocr.py
Normal file
26
pms_api_rest/datamodels/pms_ocr.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from marshmallow import fields
|
||||
|
||||
from odoo.addons.datamodel.core import Datamodel
|
||||
|
||||
|
||||
class PmsOcrInput(Datamodel):
|
||||
_name = "pms.ocr.input"
|
||||
imageBase64 = fields.String(required=True, allow_none=False)
|
||||
|
||||
|
||||
class PmsOcrCheckinResult(Datamodel):
|
||||
_name = "pms.ocr.checkin.result"
|
||||
nationality = fields.Integer(required=False, allow_none=True)
|
||||
countryId = fields.Integer(required=False, allow_none=True)
|
||||
firstname = fields.String(required=False, allow_none=True)
|
||||
lastname = fields.String(required=False, allow_none=True)
|
||||
lastname2 = fields.String(required=False, allow_none=True)
|
||||
gender = fields.String(required=False, allow_none=True)
|
||||
birthdate = fields.String(required=False, allow_none=True)
|
||||
documentType = fields.Integer(required=False, allow_none=True)
|
||||
documentExpeditionDate = fields.String(required=False, allow_none=True)
|
||||
documentSupportNumber = fields.String(required=False, allow_none=True)
|
||||
documentNumber = fields.String(required=False, allow_none=True)
|
||||
residenceStreet = fields.String(required=False, allow_none=True)
|
||||
residenceCity = fields.String(required=False, allow_none=True)
|
||||
countryState = fields.Integer(required=False, allow_none=True)
|
||||
81
pms_ocr_regula/README.rst
Normal file
81
pms_ocr_regula/README.rst
Normal file
@@ -0,0 +1,81 @@
|
||||
==========
|
||||
OCR Regula
|
||||
==========
|
||||
|
||||
..
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! changes will be overwritten. !!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! source digest: sha256:b34369f690039d9865de6496bc7fd3d815f16fb385b83e1e7d3db0e35ebabeb7
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
.. |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_regula
|
||||
: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_regula
|
||||
: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 regula with the pms
|
||||
|
||||
**Table of contents**
|
||||
|
||||
.. contents::
|
||||
:local:
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
Set api key regula and url parameters of the OCR service and activate the is_used_regula field 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_regula%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_regula>`_ project on GitHub.
|
||||
|
||||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
|
||||
3
pms_ocr_regula/__init__.py
Normal file
3
pms_ocr_regula/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from . import models
|
||||
from . import services
|
||||
from . import datamodels
|
||||
20
pms_ocr_regula/__manifest__.py
Normal file
20
pms_ocr_regula/__manifest__.py
Normal 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 Regula",
|
||||
"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",
|
||||
],
|
||||
"external_dependencies": {
|
||||
"python": ["regula.documentreader.webclient", "marshmallow"],
|
||||
},
|
||||
"data": ["views/pms_property_views.xml", "data/pms_ocr_regula_data.xml"],
|
||||
"installable": True,
|
||||
}
|
||||
11
pms_ocr_regula/data/pms_ocr_regula_data.xml
Normal file
11
pms_ocr_regula/data/pms_ocr_regula_data.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
<record id="config_param_api_key_regula" model="ir.config_parameter">
|
||||
<field name="key">api_key_regula</field>
|
||||
<field name="value">False</field>
|
||||
</record>
|
||||
<record id="config_param_ocr_regula_url" model="ir.config_parameter">
|
||||
<field name="key">ocr_regula_url</field>
|
||||
<field name="value">False</field>
|
||||
</record>
|
||||
</odoo>
|
||||
1
pms_ocr_regula/datamodels/__init__.py
Normal file
1
pms_ocr_regula/datamodels/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import pms_property
|
||||
8
pms_ocr_regula/datamodels/pms_property.py
Normal file
8
pms_ocr_regula/datamodels/pms_property.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from marshmallow import fields
|
||||
|
||||
from odoo.addons.datamodel.core import Datamodel
|
||||
|
||||
|
||||
class PmsPropertyInfo(Datamodel):
|
||||
_inherit = "pms.property.info"
|
||||
isUsedRegula = fields.Boolean(required=False, allow_none=True)
|
||||
1
pms_ocr_regula/models/__init__.py
Normal file
1
pms_ocr_regula/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import pms_property
|
||||
9
pms_ocr_regula/models/pms_property.py
Normal file
9
pms_ocr_regula/models/pms_property.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class PmsProperty(models.Model):
|
||||
_inherit = "pms.property"
|
||||
|
||||
is_used_regula = fields.Boolean(
|
||||
string="Used regula", help="True if this property uses regula's OCR"
|
||||
)
|
||||
1
pms_ocr_regula/readme/CONTRIBUTORS.rst
Normal file
1
pms_ocr_regula/readme/CONTRIBUTORS.rst
Normal file
@@ -0,0 +1 @@
|
||||
* Brais <brais@roomdoo.com>
|
||||
1
pms_ocr_regula/readme/DESCRIPTION.rst
Normal file
1
pms_ocr_regula/readme/DESCRIPTION.rst
Normal file
@@ -0,0 +1 @@
|
||||
Module to connect the OCR regula with the pms
|
||||
1
pms_ocr_regula/readme/USAGE.rst
Normal file
1
pms_ocr_regula/readme/USAGE.rst
Normal file
@@ -0,0 +1 @@
|
||||
Set api key regula and url parameters of the OCR service and activate the is_used_regula field in pms_property
|
||||
2
pms_ocr_regula/services/__init__.py
Normal file
2
pms_ocr_regula/services/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from . import ocr_document_service
|
||||
from . import pms_property_service
|
||||
356
pms_ocr_regula/services/ocr_document_service.py
Normal file
356
pms_ocr_regula/services/ocr_document_service.py
Normal file
@@ -0,0 +1,356 @@
|
||||
from datetime import date, 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_datamodel.restapi import Datamodel
|
||||
from odoo.addons.component.core import Component
|
||||
|
||||
|
||||
class PmsOcr(Component):
|
||||
_inherit = "base.rest.service"
|
||||
_name = "ocr.document.service"
|
||||
_usage = "ocr-document"
|
||||
_collection = "pms.services"
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/",
|
||||
],
|
||||
"POST",
|
||||
)
|
||||
],
|
||||
input_param=Datamodel("pms.ocr.input"),
|
||||
output_param=Datamodel("pms.ocr.checkin.result", is_list=False),
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def process_ocr_document_regula(self, input_param):
|
||||
PmsOcrCheckinResult = self.env.datamodels["pms.ocr.checkin.result"]
|
||||
pms_ocr_checkin_result = PmsOcrCheckinResult()
|
||||
ocr_regula_url = (
|
||||
self.env["ir.config_parameter"].sudo().get_param("ocr_regula_url")
|
||||
)
|
||||
with DocumentReaderApi(host=ocr_regula_url) as api:
|
||||
params = ProcessParams(
|
||||
scenario=Scenario.FULL_PROCESS,
|
||||
result_type_output=[
|
||||
Result.TEXT,
|
||||
Result.STATUS,
|
||||
Result.VISUAL_TEXT,
|
||||
Result.DOCUMENT_TYPE,
|
||||
],
|
||||
)
|
||||
request = RecognitionRequest(
|
||||
process_params=params, images=[input_param.imageBase64]
|
||||
)
|
||||
response = api.process(request)
|
||||
if response.text and response.text.field_list:
|
||||
# for elemento in response.text.field_list:
|
||||
# print("campo: ", elemento.field_name)
|
||||
# print("valor: ", elemento.value)
|
||||
# print('-')
|
||||
id_country_spain = (
|
||||
self.env["res.country"].search([("code", "=", "ES")]).id
|
||||
)
|
||||
country_id = self.process_nationality(
|
||||
response.text.get_field(TextFieldType.NATIONALITY),
|
||||
response.text.get_field(TextFieldType.NATIONALITY_CODE),
|
||||
response.text.get_field(TextFieldType.NATIONALITY_CODE_NUMERIC),
|
||||
)
|
||||
firstname, lastname, lastname2 = self.process_name(
|
||||
id_country_spain,
|
||||
country_id,
|
||||
response.text.get_field(TextFieldType.GIVEN_NAMES),
|
||||
response.text.get_field(TextFieldType.FIRST_SURNAME),
|
||||
response.text.get_field(TextFieldType.SECOND_SURNAME),
|
||||
response.text.get_field(TextFieldType.SURNAME),
|
||||
response.text.get_field(TextFieldType.SURNAME_AND_GIVEN_NAMES),
|
||||
)
|
||||
if country_id:
|
||||
pms_ocr_checkin_result.nationality = country_id
|
||||
if firstname:
|
||||
pms_ocr_checkin_result.firstname = firstname
|
||||
if lastname:
|
||||
pms_ocr_checkin_result.lastname = lastname
|
||||
if lastname2:
|
||||
pms_ocr_checkin_result.lastname2 = lastname2
|
||||
gender = response.text.get_field(TextFieldType.SEX)
|
||||
if gender and gender.value != "":
|
||||
pms_ocr_checkin_result.gender = (
|
||||
"male"
|
||||
if gender.value == "M"
|
||||
else "female"
|
||||
if gender.value == "F"
|
||||
else "other"
|
||||
)
|
||||
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 = (
|
||||
datetime.strptime(
|
||||
date_of_birth.value.replace("-", "/"), "%Y/%m/%d"
|
||||
)
|
||||
.date()
|
||||
.isoformat()
|
||||
)
|
||||
date_of_expiry = response.text.get_field(TextFieldType.DATE_OF_EXPIRY)
|
||||
age = response.text.get_field(TextFieldType.AGE)
|
||||
document_class_code = response.text.get_field(
|
||||
TextFieldType.DOCUMENT_CLASS_CODE
|
||||
)
|
||||
if (
|
||||
document_class_code
|
||||
and document_class_code.value != ""
|
||||
and document_class_code.value == "P"
|
||||
):
|
||||
pms_ocr_checkin_result.documentType = (
|
||||
self.env["res.partner.id_category"]
|
||||
.search([("code", "=", "P")])
|
||||
.id
|
||||
)
|
||||
date_of_issue = response.text.get_field(TextFieldType.DATE_OF_ISSUE)
|
||||
if country_id == id_country_spain and (
|
||||
not date_of_issue or date_of_issue.value == ""
|
||||
):
|
||||
date_of_issue = self.calc_expedition_date(
|
||||
document_class_code,
|
||||
date_of_expiry,
|
||||
age,
|
||||
date_of_birth,
|
||||
)
|
||||
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("-", "/")
|
||||
)
|
||||
support_number, document_number = self.proccess_document_number(
|
||||
id_country_spain,
|
||||
country_id,
|
||||
document_class_code,
|
||||
response.text.get_field(TextFieldType.DOCUMENT_NUMBER),
|
||||
response.text.get_field(TextFieldType.PERSONAL_NUMBER),
|
||||
)
|
||||
if support_number:
|
||||
pms_ocr_checkin_result.documentSupportNumber = support_number
|
||||
if document_number:
|
||||
pms_ocr_checkin_result.documentNumber = document_number
|
||||
address_street, address_city, address_area = self.process_address(
|
||||
id_country_spain,
|
||||
country_id,
|
||||
response.text.get_field(TextFieldType.ADDRESS_STREET),
|
||||
response.text.get_field(TextFieldType.ADDRESS_CITY),
|
||||
response.text.get_field(TextFieldType.ADDRESS_AREA),
|
||||
response.text.get_field(TextFieldType.ADDRESS),
|
||||
)
|
||||
if address_street:
|
||||
pms_ocr_checkin_result.residenceStreet = address_street
|
||||
if address_city:
|
||||
pms_ocr_checkin_result.residenceCity = address_city
|
||||
if address_area:
|
||||
pms_ocr_checkin_result.countryState = address_area
|
||||
return pms_ocr_checkin_result
|
||||
|
||||
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
|
||||
26
pms_ocr_regula/services/pms_property_service.py
Normal file
26
pms_ocr_regula/services/pms_property_service.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from odoo.addons.base_rest import restapi
|
||||
from odoo.addons.base_rest_datamodel.restapi import Datamodel
|
||||
from odoo.addons.component.core import Component
|
||||
|
||||
|
||||
class PmsPropertyService(Component):
|
||||
_inherit = "pms.property.service"
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/",
|
||||
],
|
||||
"GET",
|
||||
)
|
||||
],
|
||||
output_param=Datamodel("pms.property.info", is_list=True),
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def get_properties(self):
|
||||
result_properties = super(PmsPropertyService, self).get_properties()
|
||||
for prop_info in result_properties:
|
||||
pms_property = self.env["pms.property"].browse(prop_info.id)
|
||||
prop_info.isUsedRegula = pms_property.is_used_regula
|
||||
return result_properties
|
||||
426
pms_ocr_regula/static/description/index.html
Normal file
426
pms_ocr_regula/static/description/index.html
Normal 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 Regula</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-regula">
|
||||
<h1 class="title">OCR Regula</h1>
|
||||
|
||||
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! changes will be overwritten. !!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! source digest: sha256:b34369f690039d9865de6496bc7fd3d815f16fb385b83e1e7d3db0e35ebabeb7
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||||
<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&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><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 regula and url parameters of the OCR service and activate the is_used_regula field 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_regula%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 <<a class="reference external" href="mailto:brais@roomdoo.com">brais@roomdoo.com</a>></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_regula">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>
|
||||
14
pms_ocr_regula/views/pms_property_views.xml
Normal file
14
pms_ocr_regula/views/pms_property_views.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?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>
|
||||
@@ -4,5 +4,6 @@ jose
|
||||
jwt
|
||||
marshmallow
|
||||
pycountry
|
||||
regula.documentreader.webclient
|
||||
simplejson
|
||||
xlrd
|
||||
|
||||
1
setup/pms_ocr_regula/odoo/addons/pms_ocr_regula
Symbolic link
1
setup/pms_ocr_regula/odoo/addons/pms_ocr_regula
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../../pms_ocr_regula
|
||||
6
setup/pms_ocr_regula/setup.py
Normal file
6
setup/pms_ocr_regula/setup.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import setuptools
|
||||
|
||||
setuptools.setup(
|
||||
setup_requires=['setuptools-odoo'],
|
||||
odoo_addon=True,
|
||||
)
|
||||
Reference in New Issue
Block a user