diff --git a/mgmtsystem_indicators_report/models/mgmtsystem_indicator_report_abstract.py b/mgmtsystem_indicators_report/models/mgmtsystem_indicator_report_abstract.py index 684f1c6be..4df8f272d 100644 --- a/mgmtsystem_indicators_report/models/mgmtsystem_indicator_report_abstract.py +++ b/mgmtsystem_indicators_report/models/mgmtsystem_indicator_report_abstract.py @@ -46,7 +46,7 @@ class MgmtsystemIndicatorAbstract(models.AbstractModel): help="Technical field for UX purpose.", ) - item_blocked = fields.Boolean(default=False) + item_blocked = fields.Boolean() _sql_constraints = [ ( diff --git a/mgmtsystem_indicators_report_pdf2data_import/README.rst b/mgmtsystem_indicators_report_pdf2data_import/README.rst new file mode 100644 index 000000000..8df815c12 --- /dev/null +++ b/mgmtsystem_indicators_report_pdf2data_import/README.rst @@ -0,0 +1,63 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +============================================ +Mgmtsystem Indicators Report Pdf2data Import +============================================ + +This addon allows to create a indicators report extracting the data from a pdf + +Usage +===== + +To use this module you have to add in the configuration file a field called "pdf2data_templates_dir". Here the yml templates will be saved. +For example I used: +pdf2data_templates_dir=/home/REINACB/alba.riera/demoextract/templates_pdf2data + +It is also needed to write the model in which this template will be used in the field "issuer". + +Here you have an example of a template to use: + +.. code-block:: python + + issuer: mgmtsystem.indicators.report + keywords: + - TeleTest + fields: + report_id: Informe\s(\d{3,}v\d) + name: Nombre\sMuestra\s+\#\s+(\w.+) + sample_date: Fecha\sToma\sMuestra\s+\#\s+Dia\s+(\d{2}/\d{2}/\d{2}) + date: Fecha\sValidacion\sy\sEmision\sInforme:\s+(\d{2}/\d{2}/\d{2}) + validation_partner: Informe\sValidado\spor\s(\w.+)\s+Jefe + options: + decimal_separator: "," + remove_whitespace: False + remove_accents: True + date_formats: + - '%d/%m/%Y' + lines: + start: Control\sHigienico + end: Informe\sValidado\spor + first_line: (?PRecuento\s.+) + line: (?P\d+,\d+)\s*u.f.c./\s*cm2\s+\(VR + last_line: (?P\d+,\d+)\s*u.f.c./\s*m3 + types: + value: float + required_fields: + - issuer + + +To use this module first you have to define a template with its yml file. To do so go to: + +EDI -> Pdf2data templates + + a) Select the model you want to generate with this template ( for example Mgmtsystem indicators report) + b) Copy and paste the template above (in the future the issuer field will be autogenerated with the field model) + +Now you can import a PDF of the mgmtsystem.indicators.report model going to: + +Settings -> Technical (add the permission to do so ) -> Pdf2dataimport -> Import PDF + +a) Select the PDF anc click import +b) A indicator report will be generated with the PDF file diff --git a/mgmtsystem_indicators_report_pdf2data_import/__init__.py b/mgmtsystem_indicators_report_pdf2data_import/__init__.py new file mode 100644 index 000000000..f24d3e242 --- /dev/null +++ b/mgmtsystem_indicators_report_pdf2data_import/__init__.py @@ -0,0 +1,2 @@ +from . import components +from . import models diff --git a/mgmtsystem_indicators_report_pdf2data_import/__manifest__.py b/mgmtsystem_indicators_report_pdf2data_import/__manifest__.py new file mode 100644 index 000000000..1316e52e5 --- /dev/null +++ b/mgmtsystem_indicators_report_pdf2data_import/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2021 Creu Blanca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Mgmtsystem Indicators Report Pdf2data Import", + "summary": """ + This addon allows to create a indicators report + extracting the data from a pdf""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "CreuBlanca,Odoo Community Association (OCA)", + "website": "https://github.com/tegin/cb-addons", + "depends": ["mgmtsystem_indicators_report", "edi_pdf2data_oca"], + "data": [ + "views/pdf2data_template.xml", + "views/mgmtsystem_menu.xml", + "data/edi_pdf2data_type.xml", + ], + "demo": [], +} diff --git a/mgmtsystem_indicators_report_pdf2data_import/components/__init__.py b/mgmtsystem_indicators_report_pdf2data_import/components/__init__.py new file mode 100644 index 000000000..64040a87d --- /dev/null +++ b/mgmtsystem_indicators_report_pdf2data_import/components/__init__.py @@ -0,0 +1 @@ +from . import edi_mgmtsystem_indicators_report_process_data diff --git a/mgmtsystem_indicators_report_pdf2data_import/components/edi_mgmtsystem_indicators_report_process_data.py b/mgmtsystem_indicators_report_pdf2data_import/components/edi_mgmtsystem_indicators_report_process_data.py new file mode 100644 index 000000000..44000997a --- /dev/null +++ b/mgmtsystem_indicators_report_pdf2data_import/components/edi_mgmtsystem_indicators_report_process_data.py @@ -0,0 +1,76 @@ +# Copyright 2020 ACSONE +# @author: Simone Orsi +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo.addons.component.core import Component + + +class EDIBackendInputComponentMixin(Component): + _inherit = "edi.input.process.pdf2data.base" + _name = "edi.component.process_data.mgmtsystem.indicators.report" + _exchange_type = "pdf2data_mgmtsystem_indicators_report" + + def _get_parsed_pdf2data_values(self, model, data_extracted): + report_values = {} + for field in data_extracted: + if field in model._fields: + report_values[field] = data_extracted[field] + line_values = [ + (0, 0, self._get_parsed_pdf2data_indicator_ids(line)) + for line in data_extracted.get("lines") + ] + report_values.update({"indicator_ids": line_values}) + return report_values + + def _get_parsed_pdf2data_indicator_ids(self, line): + return {"name": line.get("concept"), "value": line.get("value")} + + def _generate_from_template(self, data, template): + report_template = template.mgmtsystem_indicator_template_id + report = report_template._generate_report() + vals = {} + for field in data: + if field in report._fields: + vals[field] = data[field] + line_vals = [] + for line in data.get("lines"): + if line.get("concept"): + template_indicator = report.indicator_ids.filtered( + lambda r: r.name == line.get("concept") + ) + if template_indicator: + if template_indicator.value_type and line.get("value"): + line_vals.append( + ( + 1, + template_indicator.id, + { + "value_%s" + % template_indicator.value_type: line.get("value") + }, + ) + ) + elif line.get("value"): + line_vals.append( + ( + 1, + template_indicator.id, + {"value": line.get("value")}, + ) + ) + else: + line_vals.append( + (0, 0, self._get_parsed_pdf2data_indicator_ids(line)) + ) + vals.update({"indicator_ids": line_vals}) + report.write(vals) + return report + + def process_data(self, data, template, file): + if not template.mgmtsystem_indicator_template_id: + model = self.env["mgmtsystem.indicators.report"] + record = model.create(self._get_parsed_pdf2data_values(model, data)) + else: + record = self._generate_from_template(data, template) + record.update({"report_pdf": file}) + self.exchange_record.write({"model": record._name, "res_id": record.id}) diff --git a/mgmtsystem_indicators_report_pdf2data_import/data/edi_pdf2data_type.xml b/mgmtsystem_indicators_report_pdf2data_import/data/edi_pdf2data_type.xml new file mode 100644 index 000000000..9ac322624 --- /dev/null +++ b/mgmtsystem_indicators_report_pdf2data_import/data/edi_pdf2data_type.xml @@ -0,0 +1,15 @@ + + + + + Pdf2Data Management System Indicators Report Exchange type + pdf2data_mgmtsystem_indicators_report + + input + {record_name}{dt} + pdf + + + diff --git a/mgmtsystem_indicators_report_pdf2data_import/models/__init__.py b/mgmtsystem_indicators_report_pdf2data_import/models/__init__.py new file mode 100644 index 000000000..e9ca26094 --- /dev/null +++ b/mgmtsystem_indicators_report_pdf2data_import/models/__init__.py @@ -0,0 +1 @@ +from . import pdf2data_template diff --git a/mgmtsystem_indicators_report_pdf2data_import/models/pdf2data_template.py b/mgmtsystem_indicators_report_pdf2data_import/models/pdf2data_template.py new file mode 100644 index 000000000..174c948fc --- /dev/null +++ b/mgmtsystem_indicators_report_pdf2data_import/models/pdf2data_template.py @@ -0,0 +1,13 @@ +# Copyright 2021 Creu Blanca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class Pdf2dataTemplate(models.Model): + + _inherit = "pdf2data.template" + + mgmtsystem_indicator_template_id = fields.Many2one( + "mgmtsystem.indicators.report.template" + ) diff --git a/mgmtsystem_indicators_report_pdf2data_import/static/description/icon.png b/mgmtsystem_indicators_report_pdf2data_import/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/mgmtsystem_indicators_report_pdf2data_import/static/description/icon.png differ diff --git a/mgmtsystem_indicators_report_pdf2data_import/views/mgmtsystem_menu.xml b/mgmtsystem_indicators_report_pdf2data_import/views/mgmtsystem_menu.xml new file mode 100644 index 000000000..65caee6c9 --- /dev/null +++ b/mgmtsystem_indicators_report_pdf2data_import/views/mgmtsystem_menu.xml @@ -0,0 +1,18 @@ + + + + + Import PDF + pdf2data.import + form + new + {} + + + diff --git a/mgmtsystem_indicators_report_pdf2data_import/views/pdf2data_template.xml b/mgmtsystem_indicators_report_pdf2data_import/views/pdf2data_template.xml new file mode 100644 index 000000000..8133b7162 --- /dev/null +++ b/mgmtsystem_indicators_report_pdf2data_import/views/pdf2data_template.xml @@ -0,0 +1,17 @@ + + + + + pdf2data.template.form (in mgmtsystem_indicators_report_pdf2data_import) + pdf2data.template + + + + + + + + diff --git a/setup/mgmtsystem_indicators_report_pdf2data_import/odoo/addons/mgmtsystem_indicators_report_pdf2data_import b/setup/mgmtsystem_indicators_report_pdf2data_import/odoo/addons/mgmtsystem_indicators_report_pdf2data_import new file mode 120000 index 000000000..3a93292df --- /dev/null +++ b/setup/mgmtsystem_indicators_report_pdf2data_import/odoo/addons/mgmtsystem_indicators_report_pdf2data_import @@ -0,0 +1 @@ +../../../../mgmtsystem_indicators_report_pdf2data_import \ No newline at end of file diff --git a/setup/mgmtsystem_indicators_report_pdf2data_import/setup.py b/setup/mgmtsystem_indicators_report_pdf2data_import/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/mgmtsystem_indicators_report_pdf2data_import/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)