Skip to content

[19.0][IMP] Trigger OCR From bill view form#7

Open
wouitmil wants to merge 3 commits into
0yik:18.0from
baboum-dev:19-ocr-from-bills
Open

[19.0][IMP] Trigger OCR From bill view form#7
wouitmil wants to merge 3 commits into
0yik:18.0from
baboum-dev:19-ocr-from-bills

Conversation

@wouitmil
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_ocr addon with vendor-bill OCR actions (single + batch) using queue_job.
  • Extends document.ocr to 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:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants