From 9fd06a616eb88ab2e303f3305c0a7f19ff4c8b6b Mon Sep 17 00:00:00 2001 From: David Date: Fri, 18 Oct 2024 12:59:39 +0200 Subject: [PATCH] [ADD] stock_picking_delivery_label_to_printer: New module TT51077 --- .../stock_picking_delivery_label_to_printer | 1 + .../setup.py | 6 + .../README.rst | 97 ++++ .../__init__.py | 1 + .../__manifest__.py | 21 + .../models/__init__.py | 3 + .../models/ir_actions_report.py | 45 ++ .../models/stock_picking.py | 28 ++ .../models/stock_picking_type.py | 12 + .../readme/CONFIGURE.md | 6 + .../readme/CONTRIBUTORS.md | 3 + .../readme/DESCRIPTION.md | 2 + .../readme/USAGE.md | 2 + .../reports/shipping_label_report.xml | 16 + .../static/description/index.html | 446 ++++++++++++++++++ .../views/stock_picking_type_views.xml | 15 + .../views/stock_picking_views.xml | 19 + 17 files changed, 723 insertions(+) create mode 120000 setup/stock_picking_delivery_label_to_printer/odoo/addons/stock_picking_delivery_label_to_printer create mode 100644 setup/stock_picking_delivery_label_to_printer/setup.py create mode 100644 stock_picking_delivery_label_to_printer/README.rst create mode 100644 stock_picking_delivery_label_to_printer/__init__.py create mode 100644 stock_picking_delivery_label_to_printer/__manifest__.py create mode 100644 stock_picking_delivery_label_to_printer/models/__init__.py create mode 100644 stock_picking_delivery_label_to_printer/models/ir_actions_report.py create mode 100644 stock_picking_delivery_label_to_printer/models/stock_picking.py create mode 100644 stock_picking_delivery_label_to_printer/models/stock_picking_type.py create mode 100644 stock_picking_delivery_label_to_printer/readme/CONFIGURE.md create mode 100644 stock_picking_delivery_label_to_printer/readme/CONTRIBUTORS.md create mode 100644 stock_picking_delivery_label_to_printer/readme/DESCRIPTION.md create mode 100644 stock_picking_delivery_label_to_printer/readme/USAGE.md create mode 100644 stock_picking_delivery_label_to_printer/reports/shipping_label_report.xml create mode 100644 stock_picking_delivery_label_to_printer/static/description/index.html create mode 100644 stock_picking_delivery_label_to_printer/views/stock_picking_type_views.xml create mode 100644 stock_picking_delivery_label_to_printer/views/stock_picking_views.xml 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..f003054c37 --- /dev/null +++ b/stock_picking_delivery_label_to_printer/models/ir_actions_report.py @@ -0,0 +1,45 @@ +# Copyright 2024 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import Command, _, models +from odoo.exceptions import UserError + + +class IrActionsReport(models.Model): + _inherit = "ir.actions.report" + + def print_document(self, record_ids, data=None): + if ( + self.report_name + != "stock_picking_delivery_label_to_printer.report_shipping_label" + ): + return super().print_document(record_ids, data) + return self.print_shipping_label(record_ids, data) + + def print_shipping_label(self, 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() + # This might be untrue! + return True + + 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) + return self.print_shipping_label(res_ids, data) 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 @@ + + +