Skip to content

Commit

Permalink
[ADD] zpl_printer, zpl_printer_mrp, zpl_printer_stock: Adding modules…
Browse files Browse the repository at this point in the history
… for direct label printing

Adding the modules we use for production purposes to directly interact with zpl printers.
  • Loading branch information
mohs8421 committed Aug 29, 2024
1 parent 6aa3440 commit a8715f6
Show file tree
Hide file tree
Showing 48 changed files with 2,406 additions and 9 deletions.
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

# report-print-send

TODO: add repo description.
This project aims to deal with the printing of documents on external devices.

<!-- /!\ do not modify below this line -->

Expand All @@ -19,15 +19,18 @@ TODO: add repo description.

Available addons
----------------
addon | version | maintainers | summary
--- | --- | --- | ---
[base_report_to_label_printer](base_report_to_label_printer/) | 16.0.1.0.0 | | Report to label printer
[base_report_to_printer](base_report_to_printer/) | 16.0.1.1.7 | | Report to printer
[base_report_to_printer_mail](base_report_to_printer_mail/) | 16.0.1.0.0 | | Report to printer - Mail extension
addon | version | maintainers | summary
--- |------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| ---
[base_report_to_label_printer](base_report_to_label_printer/) | 16.0.1.0.0 | | Report to label printer
[base_report_to_printer](base_report_to_printer/) | 16.0.1.1.7 | | Report to printer
[base_report_to_printer_mail](base_report_to_printer_mail/) | 16.0.1.0.0 | | Report to printer - Mail extension
[pingen](pingen/) | 16.0.1.0.1 | [![ajaniszewska-dev](https://github.com/ajaniszewska-dev.png?size=30px)](https://github.com/ajaniszewska-dev) [![grindtildeath](https://github.com/grindtildeath.png?size=30px)](https://github.com/grindtildeath) | pingen.com integration
[pingen_env](pingen_env/) | 16.0.1.0.0 | [![ajaniszewska-dev](https://github.com/ajaniszewska-dev.png?size=30px)](https://github.com/ajaniszewska-dev) | pingen.com server environment
[printer_zpl2](printer_zpl2/) | 16.0.1.0.0 | | Add a ZPL II label printing feature
[printing_simple_configuration](printing_simple_configuration/) | 16.0.1.0.1 | | Allow to set printing configuration in company or in warehouse
[pingen_env](pingen_env/) | 16.0.1.0.0 | [![ajaniszewska-dev](https://github.com/ajaniszewska-dev.png?size=30px)](https://github.com/ajaniszewska-dev) | pingen.com server environment
[printer_zpl2](printer_zpl2/) | 16.0.1.0.0 | | Add a ZPL II label printing feature
[printing_simple_configuration](printing_simple_configuration/) | 16.0.1.0.1 | | Allow to set printing configuration in company or in warehouse
[zpl_printer](zpl_printer/) | 16.0.0.0.1 | [![mohs8421](https://github.com/mohs8421.png?size=30px)](https://github.com/mohs8421) | Directly connect label printers to Odoo
[zpl_printer_mrp](zpl_printer_mrp/) | 16.0.0.0.1 | [![mohs8421](https://github.com/mohs8421.png?size=30px)](https://github.com/mohs8421) | Connects zpl_printer module with mrp module
[zpl_printer_stock](zpl_printer_stock/) | 16.0.0.0.1 | [![mohs8421](https://github.com/mohs8421.png?size=30px)](https://github.com/mohs8421) | Connects zpl_printer module with mrp module, add option to specify printer on product

[//]: # (end addons)

Expand Down
1 change: 1 addition & 0 deletions setup/zpl_printer/odoo/addons/zpl_printer
6 changes: 6 additions & 0 deletions setup/zpl_printer/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
1 change: 1 addition & 0 deletions setup/zpl_printer_mrp/odoo/addons/zpl_printer_mrp
6 changes: 6 additions & 0 deletions setup/zpl_printer_mrp/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
1 change: 1 addition & 0 deletions setup/zpl_printer_stock/odoo/addons/zpl_printer_stock
6 changes: 6 additions & 0 deletions setup/zpl_printer_stock/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
120 changes: 120 additions & 0 deletions zpl_printer/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
======================
ZPL Printer Management
======================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:b0c431522ae7a77979f8a985048da965c493f51e56dc36d1a44a38ad67656d43
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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/16.0/zpl_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-16-0/report-print-send-16-0-zpl_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=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module adds a new report type for zpl labels, in order to send them directly to a printer through a https request.

**Table of contents**

.. contents::
:local:

Configuration
=============

To configure this module, you need to:

#. Go to *Settings > Integrationen > Label-Printers*
#. Add at least one printer as default
#. If using stock or mrp modules, make sure that the connection modules
zrp_printer_mrp / zrp_printer_stock are available.
#. Best used in combination with a further module, that provides layouts for printers,
otherwise default-layouts will be used.

Usage
=====

This module uses https connection to a printer in your network to print to it.
Assuming the printer is properly configured for this purpose, and in your network, for example as
`label.my_company.local` then the printer will wait for POST requests to https://label.my_company.local/pstprnt
So that would be the address that makes the printer available to Odoo.

To setup your printer for this, you have to provide a certificate and enable https on the printer,
which works with the following command, that you have to send to it:

::

~DYE:HTTPS_CERT.nrd,B,NRD,1480,,-----BEGIN CERTIFICATE-----
THIS IS THE CONTENT OF YOUR CERTIFICATE, YOU HAVE TO CREATE IT
-----END CERTIFICATE-----
~DYE:HTTPS_KEY.nrd,B,NRD,1704,,-----BEGIN PRIVATE KEY-----
THIS IS THE CONTENT OF THE PRIVATE KEY FOR YOUR PRINTER, YOU HAVE TO CREATE IT
-----END PRIVATE KEY-----
^XA
^JUS
^XZ
! U1 setvar "ip.https.enable" "on"
! U1 do "device.reset" ""

This might be done with a command like:

cat your_cert_file.zpl > /dev/usb/lp1

Once everything is setup, the new printing option should be available eg. in the stock module to print serial numbers
with the option `Serial Number (Send to ZPL-Printer)`.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/report-print-send/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 <https://github.com/OCA/report-print-send/issues/new?body=module:%20zpl_printer%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Voltfang GmbH

Contributors
~~~~~~~~~~~~

* Thomas Kosel <[email protected]>

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 <https://github.com/OCA/report-print-send/tree/16.0/zpl_printer>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions zpl_printer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import controllers
from . import model
17 changes: 17 additions & 0 deletions zpl_printer/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "ZPL Printer Management",
"version": "16.0.0.0.1",
"category": "Manufacturing",
"summary": "Allows easy management of ZPL-Printers, connects to printers through their URL",
"author": "Voltfang GmbH, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/report-print-send",
"license": "AGPL-3",
"depends": ["base_setup"],
"data": ["security/ir.model.access.csv", "views/zpl_printer_view.xml"],
"assets": {
"web.assets_backend": [
"zpl_printer/static/src/js/zplactionmanager.esm.js",
]
},
"installable": True,
}
1 change: 1 addition & 0 deletions zpl_printer/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import report
83 changes: 83 additions & 0 deletions zpl_printer/controllers/report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import json
import logging

from werkzeug.urls import url_parse

from odoo import http
from odoo.http import content_disposition, request
from odoo.tools.misc import html_escape
from odoo.tools.safe_eval import safe_eval, time

from odoo.addons.web.controllers.report import ReportController

_logger = logging.getLogger(__name__)


class ReportController(ReportController):
"""Changing report controller to have zpl reports export as .zpl
(and later on be processed to directly print to a zebra printer)
"""

@http.route(["/report/download"], type="http", auth="user", cors="*")
def report_download(self, data, context=None, token=None):
"""This function is used by 'zplactionmanager.js' in order to trigger
the download of a zpl report.
:param data: a javascript array JSON.stringified containg report
internal url ([0]) and type [1]
:returns: Response with a filetoken cookie and an attachment header
"""
requestcontent = json.loads(data)
url, report_type, resolution = (

Check warning on line 31 in zpl_printer/controllers/report.py

View check run for this annotation

Codecov / codecov/patch

zpl_printer/controllers/report.py#L30-L31

Added lines #L30 - L31 were not covered by tests
requestcontent[0],
requestcontent[1],
requestcontent[2],
)
if "zpl" not in report_type:
return super().report_download(data, context=context, token=token)
try:
reportname = url.split("/report/zpl/")[1].split("?")[0]
docids = None

Check warning on line 40 in zpl_printer/controllers/report.py

View check run for this annotation

Codecov / codecov/patch

zpl_printer/controllers/report.py#L37-L40

Added lines #L37 - L40 were not covered by tests
if "/" in reportname:
reportname, docids = reportname.split("/")

Check warning on line 42 in zpl_printer/controllers/report.py

View check run for this annotation

Codecov / codecov/patch

zpl_printer/controllers/report.py#L42

Added line #L42 was not covered by tests

if docids:
# Generic report:
response = self.report_routes(

Check warning on line 46 in zpl_printer/controllers/report.py

View check run for this annotation

Codecov / codecov/patch

zpl_printer/controllers/report.py#L46

Added line #L46 was not covered by tests
reportname,
docids=docids,
context=json.dumps({"resolution": resolution}),
converter="text",
)
else:
# Particular report:
# decoding the args represented in JSON
data = url_parse(url).decode_query(cls=dict)

Check warning on line 55 in zpl_printer/controllers/report.py

View check run for this annotation

Codecov / codecov/patch

zpl_printer/controllers/report.py#L55

Added line #L55 was not covered by tests
if "context" in data:
context, data_context = json.loads(context or "{}"), json.loads(

Check warning on line 57 in zpl_printer/controllers/report.py

View check run for this annotation

Codecov / codecov/patch

zpl_printer/controllers/report.py#L57

Added line #L57 was not covered by tests
data.pop("context")
)
context = json.dumps(

Check warning on line 60 in zpl_printer/controllers/report.py

View check run for this annotation

Codecov / codecov/patch

zpl_printer/controllers/report.py#L60

Added line #L60 was not covered by tests
{**context, **data_context, "resolution": resolution}
)
response = self.report_routes(

Check warning on line 63 in zpl_printer/controllers/report.py

View check run for this annotation

Codecov / codecov/patch

zpl_printer/controllers/report.py#L63

Added line #L63 was not covered by tests
reportname, converter="text", context=context, **data
)

report = request.env["ir.actions.report"]._get_report_from_name(reportname)
filename = "%s.zpl" % (report.name)

Check warning on line 68 in zpl_printer/controllers/report.py

View check run for this annotation

Codecov / codecov/patch

zpl_printer/controllers/report.py#L67-L68

Added lines #L67 - L68 were not covered by tests

if docids:
ids = [int(x) for x in docids.split(",") if x.isdigit()]
obj = request.env[report.model].browse(ids)

Check warning on line 72 in zpl_printer/controllers/report.py

View check run for this annotation

Codecov / codecov/patch

zpl_printer/controllers/report.py#L72

Added line #L72 was not covered by tests
if report.print_report_name and not len(obj) > 1:
report_name = safe_eval(

Check warning on line 74 in zpl_printer/controllers/report.py

View check run for this annotation

Codecov / codecov/patch

zpl_printer/controllers/report.py#L74

Added line #L74 was not covered by tests
report.print_report_name, {"object": obj, "time": time}
)
filename = "%s.zpl" % (report_name)
response.headers.add("Content-Disposition", content_disposition(filename))
return response
except Exception as e:
se = http.serialize_exception(e)
error = {"code": 200, "message": "Odoo Server Error", "data": se}
return request.make_response(html_escape(json.dumps(error)))

Check warning on line 83 in zpl_printer/controllers/report.py

View check run for this annotation

Codecov / codecov/patch

zpl_printer/controllers/report.py#L77-L83

Added lines #L77 - L83 were not covered by tests
Loading

0 comments on commit a8715f6

Please sign in to comment.