[17.0][ADD] report_printed_flag#1161
Conversation
…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.
d42bbb5 to
3b6049d
Compare
rrebollo
left a comment
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
| ("active", "=", True), |
| [ | ||
| ("active", "=", True), | ||
| ("model", "=", model_name), | ||
| ("company_id", "in", records.mapped("company_id").ids), |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
again, record.company_id, how is that guaranteed?
| if not record.filtered_domain(domain): | ||
| continue | ||
| # Mark as printed | ||
| record.write({"printed": True}) |
There was a problem hiding this comment.
| record.write({"printed": True}) | |
| record.printed = True |
| 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), | ||
| } | ||
| ) |
There was a problem hiding this comment.
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" /> |
There was a problem hiding this comment.
| <field name="domain" /> | |
| <field name="domain" widget="domain"/> |
| <field name="create_date" /> | ||
| <field name="report_id" /> | ||
| <field name="user_id" /> | ||
| <field name="company_id" /> |
There was a problem hiding this comment.
| <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"], |
There was a problem hiding this comment.
| "images": ["static/description/icon.png"], |
| "views/menu_views.xml", | ||
| ], | ||
| "installable": True, | ||
| "application": False, |
There was a problem hiding this comment.
| "application": False, |
| "author": "Binhex Systems Solutions S.L, Odoo Community Association (OCA)", | ||
| "website": "https://github.com/OCA/reporting-engine", | ||
| "depends": [ | ||
| "base", |
There was a problem hiding this comment.
You mentioned before that this was dependent on the web addon, didn't you?
@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
Included components
report.printed.configreport.printed.config.linereport.printed.logreport.printed.mixinDesign considerations
The implementation is intentionally generic and reusable.
The module:
Technical details
ir.actions.reportqweb-pdf)Many2oneReferencefor generic log linkageFuture extensions
This module is designed to be extended by modules such as:
report_printed_flag_accountreport_printed_flag_stockDependencies
Testing
Includes automated tests covering:
Checklist