OCA / edi

GNU Affero General Public License v3.0
116 stars 299 forks source link

[15.0][ADD] base_import_pdf_by_template: New module #964

Closed victoralmau closed 3 weeks ago

victoralmau commented 2 months ago

New module

Example use case (import a PDF in Contacts) ejemplo ejemplo-import

Other use cases: Sale Orders, Purchase Orders, Invoices, etc

TODO:

@Tecnativa TT48213

victoralmau commented 2 months ago

Ping @carolinafernandez-tecnativa and @pilarvargas-tecnativa

carolinafernandez-tecnativa commented 2 months ago

Just a little suggestion for multi company templates:

1 - Configure one template for My Company (San Francisco) 2- Change to company My Company Chicago and tried to import PDF for the template configured in step 1. 3- I got this error message:

image

I think it has to show a message like this "No template found for this PDF" or redirect to Documents genereted with empty list.

lauradiaz22 commented 1 month ago

During the functional review, if I leave the pattern field empty, this error appears: Traceback (most recent call last): File "/opt/odoo/odoo/addons/base/models/ir_http.py", line 242, in _dispatch result = request.dispatch() File "/opt/odoo/odoo/http.py", line 702, in dispatch result = self._call_function(self.params) File "/opt/odoo/odoo/http.py", line 368, in _call_function return checked_call(self.db, *args, *kwargs) File "/opt/odoo/odoo/service/model.py", line 94, in wrapper return f(dbname, args, kwargs) File "/opt/odoo/odoo/http.py", line 357, in checked_call result = self.endpoint(*a, kw) File "/opt/odoo/odoo/http.py", line 925, in call return self.method(*args, *kw) File "/opt/odoo/odoo/http.py", line 546, in response_wrap response = f(args, kw) File "/opt/odoo/addons/web/controllers/main.py", line 1328, in call_button action = self._call_kw(model, method, args, kwargs) File "/opt/odoo/addons/web/controllers/main.py", line 1316, in _call_kw return call_kw(request.env[model], method, args, kwargs) File "/opt/odoo/odoo/api.py", line 471, in call_kw result = _call_kw_multi(method, model, args, kwargs) File "/opt/odoo/odoo/api.py", line 456, in _call_kw_multi result = method(recs, *args, **kwargs) File "/mnt/data/odoo-addons-dir/base_import_pdf_simple/wizards/wizard_base_import_pdf_upload.py", line 62, in action_process records += line.action_process() File "/mnt/data/odoo-addons-dir/base_import_pdf_simple/wizards/wizard_base_import_pdf_upload.py", line 121, in action_process record = self._process_form() File "/mnt/data/odoo-addons-dir/base_import_pdf_simple/wizards/wizard_base_import_pdf_upload.py", line 188, in _process_form table_info = template._get_table_info(text) File "/mnt/data/odoo-addons-dir/base_import_pdf_simple/models/base_import_pdf_template.py", line 92, in _get_table_info data = self._get_table_info_data(text) File "/mnt/data/odoo-addons-dir/base_import_pdf_simple/models/base_import_pdf_template.py", line 114, in _get_table_info_data data_key_0 = data_keys[0] Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/opt/odoo/odoo/http.py", line 658, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/opt/odoo/odoo/http.py", line 301, in _handle_exception raise exception.with_traceback(None) from new_cause IndexError: list index out of range

I assume that the pattern should be required when the line is a variable type to avoid this error. Thank you.

carolinafernandez-tecnativa commented 1 month ago

During the functional review, if I leave the pattern field empty, this error appears: Traceback (most recent call last): File "/opt/odoo/odoo/addons/base/models/ir_http.py", line 242, in _dispatch result = request.dispatch() File "/opt/odoo/odoo/http.py", line 702, in dispatch result = self._call_function(self.params) File "/opt/odoo/odoo/http.py", line 368, in _call_function return checked_call(self.db, *args, *kwargs) File "/opt/odoo/odoo/service/model.py", line 94, in wrapper return f(dbname, args, kwargs) File "/opt/odoo/odoo/http.py", line 357, in checked_call result = self.endpoint(*a, kw) File "/opt/odoo/odoo/http.py", line 925, in call return self.method(*args, *kw) File "/opt/odoo/odoo/http.py", line 546, in response_wrap response = f(args, kw) File "/opt/odoo/addons/web/controllers/main.py", line 1328, in call_button action = self._call_kw(model, method, args, kwargs) File "/opt/odoo/addons/web/controllers/main.py", line 1316, in _call_kw return call_kw(request.env[model], method, args, kwargs) File "/opt/odoo/odoo/api.py", line 471, in call_kw result = _call_kw_multi(method, model, args, kwargs) File "/opt/odoo/odoo/api.py", line 456, in _call_kw_multi result = method(recs, *args, **kwargs) File "/mnt/data/odoo-addons-dir/base_import_pdf_simple/wizards/wizard_base_import_pdf_upload.py", line 62, in action_process records += line.action_process() File "/mnt/data/odoo-addons-dir/base_import_pdf_simple/wizards/wizard_base_import_pdf_upload.py", line 121, in action_process record = self._process_form() File "/mnt/data/odoo-addons-dir/base_import_pdf_simple/wizards/wizard_base_import_pdf_upload.py", line 188, in _process_form table_info = template._get_table_info(text) File "/mnt/data/odoo-addons-dir/base_import_pdf_simple/models/base_import_pdf_template.py", line 92, in _get_table_info data = self._get_table_info_data(text) File "/mnt/data/odoo-addons-dir/base_import_pdf_simple/models/base_import_pdf_template.py", line 114, in _get_table_info_data data_key_0 = data_keys[0] Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/opt/odoo/odoo/http.py", line 658, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/opt/odoo/odoo/http.py", line 301, in _handle_exception raise exception.with_traceback(None) from new_cause IndexError: list index out of range

I assume that the pattern should be required when the line is a variable type to avoid this error. Thank you.

When you got that error message it means something is not well configured. Go to Settings > Technical > Base Import PDF Simple > Templates and in the template you defined, you have a button called Preview. Press button Preview and upload your file. In "Technical information" you will see if the information is correctly extracted from PDF. Otherwise, you need to modify PDF Template until you get all the information set in template.

pedrobaeza commented 1 month ago

Maybe the pattern field should be required / have a sane default.

carolinafernandez-tecnativa commented 1 month ago

Maybe the pattern field should be required / have a sane default.

Yes it is something we could add as an improvement, but it won't solve the error message. As this error could appear because Pattern is not established correctly or Columns added on lines not set correctly. I think what we can do additionally, is to catch the exception and got an User error "Please check template defined, some items are not correctly set" (as an example of error message)

pedrobaeza commented 1 month ago

Yes, good idea.

victoralmau commented 1 month ago

Changes done: Pattern defined as invisible/required and improvement added to ROADMAP.

carolinafernandez-tecnativa commented 1 month ago

After last changes I got this error message when trying to import pdf on purchase order:

image

I put the same configuration as previous test and when preview, fields are getting correctly.

image
OCA-git-bot commented 3 weeks ago

What a great day to merge this nice PR. Let's do it! Prepared branch 15.0-ocabot-merge-pr-964-by-pedrobaeza-bump-nobump, awaiting test results.

OCA-git-bot commented 3 weeks ago

Congratulations, your PR was merged at 30604c8a18f640c64f8a53cea2125cf310cb3a91. Thanks a lot for contributing to OCA. ❤️