From 04695e7fe356b41a4ab5441e360167b0685cc0be Mon Sep 17 00:00:00 2001 From: Christopher Hansen Date: Thu, 9 Jun 2022 13:51:46 +0200 Subject: [PATCH] Add Module base_report_to_label_printer --- base_report_to_label_printer/README.rst | 77 ++++ base_report_to_label_printer/__init__.py | 3 + base_report_to_label_printer/__manifest__.py | 19 + .../models/__init__.py | 4 + .../models/ir_actions_report.py | 15 + .../models/res_users.py | 18 + base_report_to_label_printer/pyproject.toml | 3 + .../readme/DESCRIPTION.md | 7 + .../static/description/index.html | 422 ++++++++++++++++++ .../tests/__init__.py | 3 + .../tests/test_ir_actions_report.py | 42 ++ .../views/ir_actions_report.xml | 12 + .../views/res_users.xml | 25 ++ .../models/ir_actions_report.py | 6 +- 14 files changed, 655 insertions(+), 1 deletion(-) create mode 100644 base_report_to_label_printer/README.rst create mode 100644 base_report_to_label_printer/__init__.py create mode 100644 base_report_to_label_printer/__manifest__.py create mode 100644 base_report_to_label_printer/models/__init__.py create mode 100644 base_report_to_label_printer/models/ir_actions_report.py create mode 100644 base_report_to_label_printer/models/res_users.py create mode 100644 base_report_to_label_printer/pyproject.toml create mode 100644 base_report_to_label_printer/readme/DESCRIPTION.md create mode 100644 base_report_to_label_printer/static/description/index.html create mode 100644 base_report_to_label_printer/tests/__init__.py create mode 100644 base_report_to_label_printer/tests/test_ir_actions_report.py create mode 100644 base_report_to_label_printer/views/ir_actions_report.xml create mode 100644 base_report_to_label_printer/views/res_users.xml diff --git a/base_report_to_label_printer/README.rst b/base_report_to_label_printer/README.rst new file mode 100644 index 00000000000..b509fbc245f --- /dev/null +++ b/base_report_to_label_printer/README.rst @@ -0,0 +1,77 @@ +======================= +Report to label printer +======================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:aca3ff63b227ee86edc5dd025a5f815bc17f0a54ca065f9f367a306d6494f0be + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Freport--print--send-lightgray.png?logo=github + :target: https://github.com/OCA/report-print-send/tree/17.0/base_report_to_label_printer + :alt: OCA/report-print-send +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/report-print-send-17-0/report-print-send-17-0-base_report_to_label_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/report-print-send&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module makes it possible to print specific reports to a label +printer that is configured on the user. + +To do this, the following must be configured: + +- Flag the report as a label report +- Define a label printer for the user + +**Table of contents** + +.. contents:: + :local: + +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 +------- + +* Raumschmiede GmbH - Christopher Hansen + +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/report-print-send `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/base_report_to_label_printer/__init__.py b/base_report_to_label_printer/__init__.py new file mode 100644 index 00000000000..69f7babdfb1 --- /dev/null +++ b/base_report_to_label_printer/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import models diff --git a/base_report_to_label_printer/__manifest__.py b/base_report_to_label_printer/__manifest__.py new file mode 100644 index 00000000000..1a93f1bc14b --- /dev/null +++ b/base_report_to_label_printer/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright (C) 2022 Raumschmiede GmbH - Christopher Hansen () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Report to label printer", + "version": "17.0.1.0.0", + "category": "Generic Modules/Base", + "author": "Raumschmiede GmbH - Christopher Hansen," + " Odoo Community Association (OCA)", + "website": "https://github.com/OCA/report-print-send", + "license": "AGPL-3", + "depends": ["base_report_to_printer"], + "data": [ + "views/res_users.xml", + "views/ir_actions_report.xml", + ], + "installable": True, + "application": False, +} diff --git a/base_report_to_label_printer/models/__init__.py b/base_report_to_label_printer/models/__init__.py new file mode 100644 index 00000000000..8e2d51b8441 --- /dev/null +++ b/base_report_to_label_printer/models/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import ir_actions_report +from . import res_users diff --git a/base_report_to_label_printer/models/ir_actions_report.py b/base_report_to_label_printer/models/ir_actions_report.py new file mode 100644 index 00000000000..8a546cc019c --- /dev/null +++ b/base_report_to_label_printer/models/ir_actions_report.py @@ -0,0 +1,15 @@ +# Copyright (C) 2022 Raumschmiede GmbH - Christopher Hansen () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class IrActionsReport(models.Model): + _inherit = "ir.actions.report" + + label = fields.Boolean(string="Report is a Label") + + def _get_user_default_printer(self, user): + if self.label: + return user.default_label_printer_id + return super()._get_user_default_printer(user) diff --git a/base_report_to_label_printer/models/res_users.py b/base_report_to_label_printer/models/res_users.py new file mode 100644 index 00000000000..705b28434d8 --- /dev/null +++ b/base_report_to_label_printer/models/res_users.py @@ -0,0 +1,18 @@ +# Copyright (C) 2022 Raumschmiede GmbH - Christopher Hansen () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class ResUsers(models.Model): + _inherit = "res.users" + + default_label_printer_id = fields.Many2one( + comodel_name="printing.printer", string="Default Label Printer" + ) + + @api.model + def _register_hook(self): + super()._register_hook() + self.SELF_WRITEABLE_FIELDS.extend(["default_label_printer_id"]) + self.SELF_READABLE_FIELDS.extend(["default_label_printer_id"]) diff --git a/base_report_to_label_printer/pyproject.toml b/base_report_to_label_printer/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/base_report_to_label_printer/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/base_report_to_label_printer/readme/DESCRIPTION.md b/base_report_to_label_printer/readme/DESCRIPTION.md new file mode 100644 index 00000000000..20657f6ae7e --- /dev/null +++ b/base_report_to_label_printer/readme/DESCRIPTION.md @@ -0,0 +1,7 @@ +This module makes it possible to print specific reports to a label +printer that is configured on the user. + +To do this, the following must be configured: + +- Flag the report as a label report +- Define a label printer for the user diff --git a/base_report_to_label_printer/static/description/index.html b/base_report_to_label_printer/static/description/index.html new file mode 100644 index 00000000000..d9085be2f50 --- /dev/null +++ b/base_report_to_label_printer/static/description/index.html @@ -0,0 +1,422 @@ + + + + + +Report to label printer + + + +
+

Report to label printer

+ + +

Beta License: AGPL-3 OCA/report-print-send Translate me on Weblate Try me on Runboat

+

This module makes it possible to print specific reports to a label +printer that is configured on the user.

+

To do this, the following must be configured:

+
    +
  • Flag the report as a label report
  • +
  • Define a label printer for the user
  • +
+

Table of contents

+ +
+

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

+
    +
  • Raumschmiede GmbH - Christopher Hansen
  • +
+
+
+

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/report-print-send project on GitHub.

+

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

+
+
+
+ + diff --git a/base_report_to_label_printer/tests/__init__.py b/base_report_to_label_printer/tests/__init__.py new file mode 100644 index 00000000000..8eefc7d83d4 --- /dev/null +++ b/base_report_to_label_printer/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import test_ir_actions_report diff --git a/base_report_to_label_printer/tests/test_ir_actions_report.py b/base_report_to_label_printer/tests/test_ir_actions_report.py new file mode 100644 index 00000000000..4b7b79984f2 --- /dev/null +++ b/base_report_to_label_printer/tests/test_ir_actions_report.py @@ -0,0 +1,42 @@ +# Copyright (C) 2022 Raumschmiede GmbH - Christopher Hansen () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestIrActionsReport(TransactionCase): + def setUp(self): + super().setUp() + self.Model = self.env["ir.actions.report"] + + self.server = self.env["printing.server"].create({}) + + def new_printer(self): + return self.env["printing.printer"].create( + { + "name": "Printer", + "server_id": self.server.id, + "system_name": "Sys Name", + "default": True, + "status": "unknown", + "status_message": "Msg", + "model": "res.users", + "location": "Location", + "uri": "URI", + } + ) + + def test_print_behavior_user_label_printer(self): + """It should return the label printer from user""" + report = self.Model.search([], limit=1) + report.label = True + self.env.user.printing_action = "client" + self.env.user.default_label_printer_id = self.new_printer() + self.assertEqual( + report.behaviour(), + { + "action": "client", + "printer": self.env.user.default_label_printer_id, + "tray": False, + }, + ) diff --git a/base_report_to_label_printer/views/ir_actions_report.xml b/base_report_to_label_printer/views/ir_actions_report.xml new file mode 100644 index 00000000000..0d6b321e985 --- /dev/null +++ b/base_report_to_label_printer/views/ir_actions_report.xml @@ -0,0 +1,12 @@ + + + ir.actions.report.inherit.view.form + ir.actions.report + + + + + + + + diff --git a/base_report_to_label_printer/views/res_users.xml b/base_report_to_label_printer/views/res_users.xml new file mode 100644 index 00000000000..262ea59cf02 --- /dev/null +++ b/base_report_to_label_printer/views/res_users.xml @@ -0,0 +1,25 @@ + + + res.users.inherit.view.form + res.users + + + + + + + + + res.users.inherit.view.form + res.users + + + + + + + + diff --git a/base_report_to_printer/models/ir_actions_report.py b/base_report_to_printer/models/ir_actions_report.py index b7d05a55fd8..3d7ef8dfccd 100644 --- a/base_report_to_printer/models/ir_actions_report.py +++ b/base_report_to_printer/models/ir_actions_report.py @@ -56,12 +56,16 @@ def print_action_for_report_name(self, report_name): } return serializable_result + def _get_user_default_printer(self, user): + return user.printing_printer_id + def _get_user_default_print_behaviour(self): printer_obj = self.env["printing.printer"] user = self.env.user + printer = self._get_user_default_printer(user) return dict( action=user.printing_action or "client", - printer=user.printing_printer_id or printer_obj.get_default(), + printer=printer or printer_obj.get_default(), tray=str(user.printer_tray_id.system_name) if user.printer_tray_id else False,