diff --git a/setup/stock_picking_delivery_label_to_printer/odoo/addons/stock_picking_delivery_label_to_printer b/setup/stock_picking_delivery_label_to_printer/odoo/addons/stock_picking_delivery_label_to_printer new file mode 120000 index 0000000000..6dd0398b7f --- /dev/null +++ b/setup/stock_picking_delivery_label_to_printer/odoo/addons/stock_picking_delivery_label_to_printer @@ -0,0 +1 @@ +../../../../stock_picking_delivery_label_to_printer \ No newline at end of file diff --git a/setup/stock_picking_delivery_label_to_printer/setup.py b/setup/stock_picking_delivery_label_to_printer/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/stock_picking_delivery_label_to_printer/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_picking_delivery_label_to_printer/README.rst b/stock_picking_delivery_label_to_printer/README.rst new file mode 100644 index 0000000000..804c8d3c13 --- /dev/null +++ b/stock_picking_delivery_label_to_printer/README.rst @@ -0,0 +1,97 @@ +===================================== +Print shipping labels on CUPS printer +===================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:527ee725e2a4ae3cb421e13dca36683b453053ac68a16684717eb7c99f87eab0 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fdelivery--carrier-lightgray.png?logo=github + :target: https://github.com/OCA/delivery-carrier/tree/15.0/stock_picking_delivery_label_to_printer + :alt: OCA/delivery-carrier +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/delivery-carrier-15-0/delivery-carrier-15-0-stock_picking_delivery_label_to_printer + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/delivery-carrier&target_branch=15.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows print the carrier labels into a CUPS printer defined +in an special report. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +Configure the report preferences: + +- Go to... + +Configure the picking operation type preferences: + +- Go to... + +Usage +===== + +Once a picking for a type with label autoprint set is validated, those +will be sent to the printer. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Tecnativa + +Contributors +------------ + +- `Tecnativa `__ + + - David Vidal + - Sergio Teruel + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/delivery-carrier `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_picking_delivery_label_to_printer/__init__.py b/stock_picking_delivery_label_to_printer/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/stock_picking_delivery_label_to_printer/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_picking_delivery_label_to_printer/__manifest__.py b/stock_picking_delivery_label_to_printer/__manifest__.py new file mode 100644 index 0000000000..bebbd6aea1 --- /dev/null +++ b/stock_picking_delivery_label_to_printer/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2024 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Print shipping labels on CUPS printer", + "summary": "Send shipping labels to CUPS printer", + "author": "Tecnativa, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/delivery-carrier", + "license": "AGPL-3", + "category": "Delivery", + "version": "15.0.1.0.0", + "depends": [ + "stock_picking_delivery_label_link", + "base_report_to_printer", + "stock_picking_auto_print", + ], + "data": [ + "views/stock_picking_views.xml", + "views/stock_picking_type_views.xml", + "reports/shipping_label_report.xml", + ], +} diff --git a/stock_picking_delivery_label_to_printer/models/__init__.py b/stock_picking_delivery_label_to_printer/models/__init__.py new file mode 100644 index 0000000000..acacdc9f2d --- /dev/null +++ b/stock_picking_delivery_label_to_printer/models/__init__.py @@ -0,0 +1,3 @@ +from . import stock_picking_type +from . import ir_actions_report +from . import stock_picking diff --git a/stock_picking_delivery_label_to_printer/models/ir_actions_report.py b/stock_picking_delivery_label_to_printer/models/ir_actions_report.py new file mode 100644 index 0000000000..32961c61f1 --- /dev/null +++ b/stock_picking_delivery_label_to_printer/models/ir_actions_report.py @@ -0,0 +1,42 @@ +# Copyright 2024 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import Command, _, api, models +from odoo.exceptions import UserError + + +class IrActionsReport(models.Model): + _inherit = "ir.actions.report" + + @api.model + def print_action_for_report_name(self, report_name): + if ( + report_name + == "stock_picking_delivery_label_to_printer.report_shipping_label" + ): + return {} + return super().print_action_for_report_name(report_name) + + def _render_qweb_pdf(self, res_ids=None, data=None): + if ( + self.report_name + != "stock_picking_delivery_label_to_printer.report_shipping_label" + ): + return super()._render_qweb_pdf(res_ids, data) + behaviour = self.behaviour() + printer = behaviour.pop("printer", None) + can_print_report = behaviour["action"] == "server" and printer + shipping_label_ids = data.get("shipping_label_ids") + if not can_print_report or not shipping_label_ids: + # Maybe we could trigger the download... + raise UserError(_("Labels can only be printed with CUPS")) + print_attachment = self.env["wizard.print.attachment"].create( + { + "printer_id": printer.id, + "attachment_line_ids": [ + Command.create({"attachment_id": attachment}) + for attachment in shipping_label_ids + ], + } + ) + print_attachment.print_attachments() + return (b"", "pdf") diff --git a/stock_picking_delivery_label_to_printer/models/stock_picking.py b/stock_picking_delivery_label_to_printer/models/stock_picking.py new file mode 100644 index 0000000000..25310deb93 --- /dev/null +++ b/stock_picking_delivery_label_to_printer/models/stock_picking.py @@ -0,0 +1,28 @@ +# Copyright 2024 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import models + +from odoo.addons.web.controllers.main import clean_action + + +class StockPicking(models.Model): + _inherit = "stock.picking" + + def _get_autoprint_report_actions(self): + report_actions = super()._get_autoprint_report_actions() + pickings_to_print = self.filtered( + lambda p: p.picking_type_id.auto_print_shipping_labels + and p.shipping_label_ids + ) + if pickings_to_print: + action = pickings_to_print.action_print_shipping_labels() + report_actions.append(action) + return report_actions + + def action_print_shipping_labels(self): + action = self.env.ref( + "stock_picking_delivery_label_to_printer.shipping_label_report_action" + ).report_action(self.ids, config=False) + action["data"] = {"shipping_label_ids": self.shipping_label_ids.ids} + clean_action(action, self.env) + return action diff --git a/stock_picking_delivery_label_to_printer/models/stock_picking_type.py b/stock_picking_delivery_label_to_printer/models/stock_picking_type.py new file mode 100644 index 0000000000..d92c053404 --- /dev/null +++ b/stock_picking_delivery_label_to_printer/models/stock_picking_type.py @@ -0,0 +1,12 @@ +# Copyright 2024 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import fields, models + + +class StockPickingType(models.Model): + _inherit = "stock.picking.type" + + auto_print_shipping_labels = fields.Boolean( + help="If this checkbox is ticked, Odoo will automatically print the delivery" + "shipping labels if they're available", + ) diff --git a/stock_picking_delivery_label_to_printer/readme/CONFIGURE.md b/stock_picking_delivery_label_to_printer/readme/CONFIGURE.md new file mode 100644 index 0000000000..4dd455749a --- /dev/null +++ b/stock_picking_delivery_label_to_printer/readme/CONFIGURE.md @@ -0,0 +1,6 @@ +Configure the report preferences: + - Go to... + +Configure the picking operation type preferences: + - Go to... + diff --git a/stock_picking_delivery_label_to_printer/readme/CONTRIBUTORS.md b/stock_picking_delivery_label_to_printer/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..7dc63b01d3 --- /dev/null +++ b/stock_picking_delivery_label_to_printer/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- [Tecnativa](https://tecnativa.com) + - David Vidal + - Sergio Teruel diff --git a/stock_picking_delivery_label_to_printer/readme/DESCRIPTION.md b/stock_picking_delivery_label_to_printer/readme/DESCRIPTION.md new file mode 100644 index 0000000000..c816329b3f --- /dev/null +++ b/stock_picking_delivery_label_to_printer/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module allows print the carrier labels into a CUPS printer defined in an special +report. diff --git a/stock_picking_delivery_label_to_printer/readme/USAGE.md b/stock_picking_delivery_label_to_printer/readme/USAGE.md new file mode 100644 index 0000000000..09ca47f6ab --- /dev/null +++ b/stock_picking_delivery_label_to_printer/readme/USAGE.md @@ -0,0 +1,2 @@ +Once a picking for a type with label autoprint set is validated, those will be sent +to the printer. diff --git a/stock_picking_delivery_label_to_printer/reports/shipping_label_report.xml b/stock_picking_delivery_label_to_printer/reports/shipping_label_report.xml new file mode 100644 index 0000000000..469ef52d53 --- /dev/null +++ b/stock_picking_delivery_label_to_printer/reports/shipping_label_report.xml @@ -0,0 +1,16 @@ + + +