From c38913aadf24298c980fe899431d7c8eb2ad9e55 Mon Sep 17 00:00:00 2001 From: fkantelberg Date: Wed, 17 Jul 2024 08:51:16 +0200 Subject: [PATCH] [IMP] delivery_automatic_print: Allow to filter picking types for each automatically printed report --- delivery_automatic_print/__manifest__.py | 4 +++- delivery_automatic_print/models/ir_actions_report.py | 4 +++- delivery_automatic_print/models/stock_picking.py | 9 ++++++++- .../views/ir_actions_report_views.xml | 12 ++++++++++++ 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 delivery_automatic_print/views/ir_actions_report_views.xml diff --git a/delivery_automatic_print/__manifest__.py b/delivery_automatic_print/__manifest__.py index 68c1a5c3..d10054dc 100644 --- a/delivery_automatic_print/__manifest__.py +++ b/delivery_automatic_print/__manifest__.py @@ -7,7 +7,9 @@ "carrier_shipping_label_template", "stock", ], - "data": [], + "data": [ + "views/ir_actions_report_views.xml", + ], "auto_install": False, "installable": True, "author": "Nitrokey GmbH", diff --git a/delivery_automatic_print/models/ir_actions_report.py b/delivery_automatic_print/models/ir_actions_report.py index 4f4cc3cc..a9e37be5 100644 --- a/delivery_automatic_print/models/ir_actions_report.py +++ b/delivery_automatic_print/models/ir_actions_report.py @@ -1,12 +1,14 @@ # © 2024 initOS GmbH # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models +from odoo import fields, models class IrActionsReport(models.Model): _inherit = "ir.actions.report" + auto_picking_type_ids = fields.Many2many("stock.picking.type") + def _render_qweb_pdf(self, res_ids=None, data=None): document, fmt = super()._render_qweb_pdf(res_ids, data) diff --git a/delivery_automatic_print/models/stock_picking.py b/delivery_automatic_print/models/stock_picking.py index 2ee63676..0a41aa16 100644 --- a/delivery_automatic_print/models/stock_picking.py +++ b/delivery_automatic_print/models/stock_picking.py @@ -27,6 +27,13 @@ def button_validate(self): ctx = {"raise_on_missing_labels": False} for report in self.reports_to_print().with_context(**ctx): - report.sudo()._render_qweb_pdf(self.ids) + if report.auto_picking_type_ids: + pickings = self.filtered_domain( + [("picking_type_id", "in", report.auto_picking_type_ids.ids)] + ) + else: + pickings = self + + report.sudo()._render_qweb_pdf(pickings.ids) return res diff --git a/delivery_automatic_print/views/ir_actions_report_views.xml b/delivery_automatic_print/views/ir_actions_report_views.xml new file mode 100644 index 00000000..e722dcfd --- /dev/null +++ b/delivery_automatic_print/views/ir_actions_report_views.xml @@ -0,0 +1,12 @@ + + + + ir.actions.report + + + + + + + +