[19.0][IMP] Trigger OCR From bill view form#7
Open
wouitmil wants to merge 3 commits into
Open
Conversation
e0de386 to
8f062f1
Compare
There was a problem hiding this comment.
Pull request overview
Adds an Odoo 19-compatible “Account OCR” integration so users can launch OCR directly from vendor bills (form button) and from a list batch action, then return to the targeted bill after processing.
Changes:
- Introduces a new
account_ocraddon with vendor-bill OCR actions (single + batch) usingqueue_job. - Extends
document.ocrto write OCR results back into an existing vendor bill and redirect back to that bill after processing. - Ports module versions to
19.0.*and adjusts date parsing behavior.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| document_ocr/models/vendor_bill.py | Adjusts date parsing behavior and adds logger setup. |
| document_ocr/manifest.py | Bumps addon version to 19.0. |
| base_ocr/models/ocr_provider.py | Fixes language mapping lookup and updates create() to @api.model_create_multi. |
| base_ocr/manifest.py | Bumps addon version to 19.0. |
| account_ocr/views/account_move_views.xml | Adds “Run OCR” vendor bill form button and a list-view server action for batch OCR. |
| account_ocr/models/account_move.py | Adds OCR validation + execution methods on vendor bills, including queued batch processing via queue_job. |
| account_ocr/models/document_ocr.py | Extends document.ocr to target/update an existing vendor bill and redirect back to it after OCR. |
| account_ocr/models/init.py | Registers new model extensions. |
| account_ocr/data/queue_job_function_data.xml | Registers the queue job function for _job_run_main_attachment_ocr. |
| account_ocr/manifest.py | Declares the new addon, dependencies, and data files. |
| account_ocr/init.py | Initializes the addon’s Python package. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+3
to
+10
| <record id="action_account_move_run_ocr_selected" model="ir.actions.server"> | ||
| <field name="name">Run OCR on selected invoices</field> | ||
| <field name="model_id" ref="account.model_account_move"/> | ||
| <field name="binding_model_id" ref="account.model_account_move"/> | ||
| <field name="binding_view_types">list</field> | ||
| <field name="state">code</field> | ||
| <field name="code">action = records.action_process_selected_main_attachment_ocr()</field> | ||
| </record> |
Comment on lines
44
to
+47
| def _parse_date(self, date_str): | ||
| """Parse date string to YYYY-MM-DD format using dateparser.""" | ||
| if not date_str: | ||
| return False | ||
| return fields.Date.context_today(self) |
Comment on lines
+120
to
+127
| for vals in vals_list: | ||
| if vals.get("is_default"): | ||
| self.search( | ||
| [ | ||
| ("is_default", "=", True), | ||
| ("company_id", "=", vals.get("company_id", self.env.company.id)), | ||
| ] | ||
| ).write({"is_default": False}) |
Comment on lines
+33
to
+46
| def _prepare_vendor_partner(self, parsed_data): | ||
| partner = self.env["res.partner"].search( | ||
| [("name", "ilike", parsed_data.get("vendor_name"))], limit=1 | ||
| ) | ||
| if partner: | ||
| return partner | ||
|
|
||
| return self.env["res.partner"].create( | ||
| { | ||
| "name": parsed_data.get("vendor_name"), | ||
| "company_type": "company", | ||
| "is_company": True, | ||
| } | ||
| ) |
Comment on lines
+51
to
+79
| for item in parsed_data.get("line_items", []): | ||
| product = self.env["product.product"].search( | ||
| [("name", "ilike", item.get("product"))], limit=1 | ||
| ) | ||
| if not product: | ||
| product = self.env["product.product"].create( | ||
| { | ||
| "name": item.get("product"), | ||
| "type": "service", | ||
| "purchase_ok": True, | ||
| } | ||
| ) | ||
|
|
||
| lines.append( | ||
| ( | ||
| 0, | ||
| 0, | ||
| { | ||
| "product_id": product.id, | ||
| "name": ( | ||
| f"{item.get('product')} {item.get('description')}" | ||
| if item.get("description") | ||
| else product.name | ||
| ), | ||
| "quantity": item.get("quantity", 1.0), | ||
| "price_unit": item.get("price", 0.0), | ||
| "tax_ids": [(5, 0, 0)], | ||
| }, | ||
| ) |
Comment on lines
+70
to
+98
| def action_process_selected_main_attachment_ocr(self): | ||
| queued = 0 | ||
| skipped = [] | ||
|
|
||
| for move in self: | ||
| try: | ||
| move._validate_main_attachment_ocr() | ||
| job_description = _("OCR Vendor Bill %s") % move.id | ||
| move.with_delay(description=job_description)._job_run_main_attachment_ocr() | ||
| queued += 1 | ||
| except UserError as err: | ||
| skipped.append( | ||
| _( | ||
| "Invoice %(id)s: %(reason)s", | ||
| id=move.id, | ||
| reason=str(err), | ||
| ) | ||
| ) | ||
|
|
||
| if not queued and skipped: | ||
| raise UserError( | ||
| _( | ||
| "No selected invoice could be queued.\n%(details)s", | ||
| details="\n".join(skipped[:10]), | ||
| ) | ||
| ) | ||
|
|
||
| message = _("OCR queued for %(count)s invoice(s).", count=queued) | ||
| if skipped: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.