diff --git a/setup/stock_weighing_threaded_print/odoo/addons/stock_weighing_threaded_print b/setup/stock_weighing_threaded_print/odoo/addons/stock_weighing_threaded_print new file mode 120000 index 00000000..bc3c0f32 --- /dev/null +++ b/setup/stock_weighing_threaded_print/odoo/addons/stock_weighing_threaded_print @@ -0,0 +1 @@ +../../../../stock_weighing_threaded_print \ No newline at end of file diff --git a/setup/stock_weighing_threaded_print/setup.py b/setup/stock_weighing_threaded_print/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/stock_weighing_threaded_print/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_weighing_threaded_print/README.rst b/stock_weighing_threaded_print/README.rst new file mode 100644 index 00000000..e98b6fbc --- /dev/null +++ b/stock_weighing_threaded_print/README.rst @@ -0,0 +1,91 @@ +================================ +Weighing deferred label printing +================================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:27936af3cb3e69603e29a6b7b587ca48dbf64e05bb9d829f4ef904648866772d + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fstock--weighing-lightgray.png?logo=github + :target: https://github.com/OCA/stock-weighing/tree/15.0/stock_weighing_threaded_print + :alt: OCA/stock-weighing +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/stock-weighing-15-0/stock-weighing-15-0-stock_weighing_threaded_print + :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/stock-weighing&target_branch=15.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module is aimed to speed up the label printing process by returning the control of +the user's screen and triggering the printing in a background process. If something goes +wrong, the user is informed with a notification that can be used to retry the process. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +The default behavior is to **print in main thread**, but it can be configured by +following these steps: + +* Activate developer mode. +* Go to *Settings > Technical > Parameters > System Parameters*. +* Create a **stock_weighing_threaded_print.print_in_new_thread** key. + +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 `_: + + * Sergio Teruel + * David Vidal + +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/stock-weighing `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_weighing_threaded_print/__init__.py b/stock_weighing_threaded_print/__init__.py new file mode 100644 index 00000000..aee8895e --- /dev/null +++ b/stock_weighing_threaded_print/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import wizards diff --git a/stock_weighing_threaded_print/__manifest__.py b/stock_weighing_threaded_print/__manifest__.py new file mode 100644 index 00000000..dd98ec2e --- /dev/null +++ b/stock_weighing_threaded_print/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2024 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Weighing deferred label printing", + "summary": "Print labels on a different thread", + "version": "15.0.1.0.0", + "development_status": "Beta", + "category": "Warehouse", + "website": "https://github.com/OCA/stock-weighing", + "author": "Tecnativa, Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": [ + "stock_weighing", + "base_report_to_printer", + "web_notify", + ], + "data": [], + "installable": True, +} diff --git a/stock_weighing_threaded_print/models/__init__.py b/stock_weighing_threaded_print/models/__init__.py new file mode 100644 index 00000000..431f51c2 --- /dev/null +++ b/stock_weighing_threaded_print/models/__init__.py @@ -0,0 +1 @@ +from . import stock_move_line diff --git a/stock_weighing_threaded_print/models/stock_move_line.py b/stock_weighing_threaded_print/models/stock_move_line.py new file mode 100644 index 00000000..c442b570 --- /dev/null +++ b/stock_weighing_threaded_print/models/stock_move_line.py @@ -0,0 +1,58 @@ +# Copyright 2024 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +import threading + +from odoo import _, models + + +class StockMoveLine(models.Model): + _inherit = "stock.move.line" + + def action_print_weight_record_label(self): + """Speedup label printing""" + ICP = self.env["ir.config_parameter"].sudo() + if ICP.get_param( + "stock_weighing_threaded_print.print_in_new_thread" + ) and not self.env.context.get("skip_threaded_printing"): + return self._launch_print_weighing_label_thread() + return super().action_print_weight_record_label() + + def action_print_weighing_label_threaded(self): + with self.pool.cursor() as new_cr: + self = self.with_env(self.env(cr=new_cr)) + report = self.picking_type_id.weighing_label_report_id + try: + report.print_document(self.ids) + self.env.user.notify_success(message="Succesfully printed") + except Exception: + action = self.with_context( + skip_threaded_printing=True + ).action_print_weight_record_label() + action["context"].setdefault("params", {}) + action["context"]["params"]["button_name"] = "Print" + action["context"]["params"]["button_icon"] = "fa-print" + self.env.user.notify_warning( + title=_("Direct print issue"), + message=_( + "The label(s) for
    %(operations_name)s
" + "couldn't be printed. Click below to download it.", + operations_name=( + "".join( + [ + (f"
  • {sml._get_action_weighing_name()}
  • ") + for sml in self + ] + ) + ), + ), + sticky=True, + html=True, + action=action, + ) + + def _launch_print_weighing_label_thread(self): + threaded_calculation = threading.Thread( + target=self.action_print_weighing_label_threaded, + args=(), + ) + threaded_calculation.start() diff --git a/stock_weighing_threaded_print/readme/CONFIGURE.rst b/stock_weighing_threaded_print/readme/CONFIGURE.rst new file mode 100644 index 00000000..b9460baf --- /dev/null +++ b/stock_weighing_threaded_print/readme/CONFIGURE.rst @@ -0,0 +1,6 @@ +The default behavior is to **print in main thread**, but it can be configured by +following these steps: + +* Activate developer mode. +* Go to *Settings > Technical > Parameters > System Parameters*. +* Create a **stock_weighing_threaded_print.print_in_new_thread** key. diff --git a/stock_weighing_threaded_print/readme/CONTRIBUTORS.rst b/stock_weighing_threaded_print/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..e202acff --- /dev/null +++ b/stock_weighing_threaded_print/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Tecnativa `_: + + * Sergio Teruel + * David Vidal diff --git a/stock_weighing_threaded_print/readme/DESCRIPTION.rst b/stock_weighing_threaded_print/readme/DESCRIPTION.rst new file mode 100644 index 00000000..90a51282 --- /dev/null +++ b/stock_weighing_threaded_print/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +This module is aimed to speed up the label printing process by returning the control of +the user's screen and triggering the printing in a background process. If something goes +wrong, the user is informed with a notification that can be used to retry the process. diff --git a/stock_weighing_threaded_print/static/description/icon.png b/stock_weighing_threaded_print/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/stock_weighing_threaded_print/static/description/icon.png differ diff --git a/stock_weighing_threaded_print/static/description/index.html b/stock_weighing_threaded_print/static/description/index.html new file mode 100644 index 00000000..8a876ca2 --- /dev/null +++ b/stock_weighing_threaded_print/static/description/index.html @@ -0,0 +1,440 @@ + + + + + +Weighing deferred label printing + + + +
    +

    Weighing deferred label printing

    + + +

    Beta License: AGPL-3 OCA/stock-weighing Translate me on Weblate Try me on Runboat

    +

    This module is aimed to speed up the label printing process by returning the control of +the user’s screen and triggering the printing in a background process. If something goes +wrong, the user is informed with a notification that can be used to retry the process.

    +

    Table of contents

    + +
    +

    Configuration

    +

    The default behavior is to print in main thread, but it can be configured by +following these steps:

    +
      +
    • Activate developer mode.
    • +
    • Go to Settings > Technical > Parameters > System Parameters.
    • +
    • Create a stock_weighing_threaded_print.print_in_new_thread key.
    • +
    +
    +
    +

    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:
        +
      • Sergio Teruel
      • +
      • David Vidal
      • +
      +
    • +
    +
    +
    +

    Maintainers

    +

    This module is maintained by the OCA.

    + +Odoo Community Association + +

    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/stock-weighing project on GitHub.

    +

    You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

    +
    +
    +
    + + diff --git a/stock_weighing_threaded_print/wizards/__init__.py b/stock_weighing_threaded_print/wizards/__init__.py new file mode 100644 index 00000000..2baf4cfb --- /dev/null +++ b/stock_weighing_threaded_print/wizards/__init__.py @@ -0,0 +1 @@ +from . import weighing_wizard diff --git a/stock_weighing_threaded_print/wizards/weighing_wizard.py b/stock_weighing_threaded_print/wizards/weighing_wizard.py new file mode 100644 index 00000000..34e4e3c8 --- /dev/null +++ b/stock_weighing_threaded_print/wizards/weighing_wizard.py @@ -0,0 +1,27 @@ +# Copyright 2024 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import models + + +class WeighingWizard(models.TransientModel): + _inherit = "weighing.wizard" + + def record_weight(self): + """Print in background if needed so we can handle exceptions""" + print_in_new_thread = ( + self.env["ir.config_parameter"] + .sudo() + .get_param("stock_weighing_threaded_print.print_in_new_thread") + ) + if ( + self.print_label + and print_in_new_thread + and not self.env.context.get("skip_threaded_printing") + ): + self.print_label = False + super().record_weight() + self._cr.postcommit.add( + self.selected_move_line_id.action_print_weight_record_label + ) + return {"type": "ir.actions.act_window_close"} + return super().record_weight()