Skip to content

[17.0][ADD] report_printed_flag#1161

Draft
atgalvez08 wants to merge 1 commit intoOCA:17.0from
BinhexTeam:17.0-add-report_printed_flag
Draft

[17.0][ADD] report_printed_flag#1161
atgalvez08 wants to merge 1 commit intoOCA:17.0from
BinhexTeam:17.0-add-report_printed_flag

Conversation

@atgalvez08
Copy link
Copy Markdown

@BinhexTeam

This module provides a reusable framework to track printed QWeb PDF
reports across business models.

It introduces configurable printed tracking with optional logging
and reusable integration through a generic mixin.

Features

  • Configurable printed tracking per model and report
  • Optional printed logs
  • Optional printed report names
  • Multi-company support
  • Reusable mixin for business models
  • Integration with Odoo report engine

Included components

  • report.printed.config
  • report.printed.config.line
  • report.printed.log
  • report.printed.mixin

Design considerations

The implementation is intentionally generic and reusable.

The module:

  • avoids model-specific assumptions
  • isolates report integration logic
  • uses a reusable abstract mixin
  • supports extension through satellite modules

Technical details

  • Hooks into ir.actions.report
  • Supports QWeb PDF reports (qweb-pdf)
  • Uses Many2oneReference for generic log linkage
  • Handles optional logging and report name computation

Future extensions

This module is designed to be extended by modules such as:

  • report_printed_flag_account
  • report_printed_flag_stock

Dependencies

  • base
  • web

Testing

Includes automated tests covering:

  • printed flag assignment
  • printed logs creation
  • report configuration filtering
  • multi-company behavior
  • models without printed support
  • printed report names computation

Checklist

  • Module follows OCA structure
  • README aligned with implementation
  • Tests included
  • No breaking changes
  • License headers included

@OCA-git-bot OCA-git-bot added series:17.0 mod:report_printed_flag Module report_printed_flag labels May 6, 2026
…ramework

This module provides a reusable framework to track printed QWeb PDF
reports across business models.

It introduces:
- printed configuration models
- printed logs
- reusable printed mixin
- report integration hooks

Features:
- configurable printed tracking per model and report
- optional printed logs
- optional printed report names
- multi-company support
- reusable mixin for extension modules

The implementation is designed to be extended by satellite modules
such as account and stock integrations.
Copy link
Copy Markdown
Contributor

@rrebollo rrebollo left a comment

Choose a reason for hiding this comment

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

Please consider my suggestions. I think you'll find some of them compelling.

# Load configurations for model and companies involved
configs = self.env["report.printed.config"].search(
[
("active", "=", True),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
("active", "=", True),

[
("active", "=", True),
("model", "=", model_name),
("company_id", "in", records.mapped("company_id").ids),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here you're assuming records will always have a company_id field. How is that guaranteed? Is it coming from a mixin? 🤔 Whenever company_id is used in this addon, you should take this into consideration.

for record in records:
# Get configuration for record company
config = configs.filtered(
lambda conf, record=record: conf.company_id == record.company_id
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

again, record.company_id, how is that guaranteed?

if not record.filtered_domain(domain):
continue
# Mark as printed
record.write({"printed": True})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
record.write({"printed": True})
record.printed = True

Comment on lines +84 to +94
if config.report_printed_log_active:
self.env["report.printed.log"].sudo().create(
{
"res_model": model_name,
"res_id": record.id,
"report_id": report.id,
"user_id": self.env.user.id,
"company_id": record.company_id.id,
"name": getattr(record, "name", record.display_name),
}
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For performance reasons, you could gather all the data required to create the log records and then create them in batch.

name="report_id"
domain="[('model', '=', parent.model)]"
/>
<field name="domain" />
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
<field name="domain" />
<field name="domain" widget="domain"/>

<field name="create_date" />
<field name="report_id" />
<field name="user_id" />
<field name="company_id" />
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
<field name="company_id" />
<field name="company_id" groups="base.group_multi_company"/>

"installable": True,
"application": False,
"development_status": "Alpha",
"images": ["static/description/icon.png"],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
"images": ["static/description/icon.png"],

"views/menu_views.xml",
],
"installable": True,
"application": False,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
"application": False,

"author": "Binhex Systems Solutions S.L, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/reporting-engine",
"depends": [
"base",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You mentioned before that this was dependent on the web addon, didn't you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:report_printed_flag Module report_printed_flag series:17.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants