Skip to content

Commit

Permalink
Raport PRN
Browse files Browse the repository at this point in the history
  • Loading branch information
dhongu committed Oct 14, 2024
1 parent bddc7bd commit 36aeced
Show file tree
Hide file tree
Showing 17 changed files with 674 additions and 5 deletions.
65 changes: 65 additions & 0 deletions deltatech_report_prn/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
==========
Raport PRN
==========

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:f063b37a4881db5750ee3c637075aa09b5bd6eb3fc70de468bfc870e8a9fb9da
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Mature-brightgreen.png
:target: https://odoo-community.org/page/development-status
:alt: Mature
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-dhongu%2Fdeltatech-lightgray.png?logo=github
:target: https:/dhongu/deltatech/tree/17.0/deltatech_report_prn
:alt: dhongu/deltatech

|badge1| |badge2| |badge3|

Features:

- It allows the printing of files with the .prn extension. These are
files that have syntax for Zebra label printers.

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `Terrabit Issues <https://www.terrabit.ro/helpdesk>`_.
In case of trouble, please check there if your issue has already been reported.

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

Credits
=======

Authors
-------

* Terrabit
* Dorin Hongu

Maintainers
-----------

.. |maintainer-dhongu| image:: https:/dhongu.png?size=40px
:target: https:/dhongu
:alt: dhongu

Current maintainer:

|maintainer-dhongu|

This module is part of the `dhongu/deltatech <https:/dhongu/deltatech/tree/17.0/deltatech_report_prn>`_ project on GitHub.

You are welcome to contribute.
5 changes: 5 additions & 0 deletions deltatech_report_prn/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# © 2008-2021 Deltatech
# See README.rst file on addons root folder for license details

from . import models
from . import controllers
20 changes: 20 additions & 0 deletions deltatech_report_prn/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# © 2008-2021 Deltatech
# See README.rst file on addons root folder for license details

{
"name": "Raport PRN",
"summary": "Raport PRN",
"version": "17.0.1.0.4",
"category": "Stock",
"author": "Terrabit, Dorin Hongu",
"website": "https://www.terrabit.ro",
"depends": ["web"],
"license": "LGPL-3",
"data": [
# "views/assets.xml"
],
"images": ["static/description/main_screenshot.png"],
"development_status": "Mature",
"maintainers": ["dhongu"],
"assets": {"web.assets_backend": ["deltatech_report_prn/static/src/js/action_manager.esm.js"]},
}
4 changes: 4 additions & 0 deletions deltatech_report_prn/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# © 2008-2021 Deltatech
# See README.rst file on addons root folder for license details

from . import main
69 changes: 69 additions & 0 deletions deltatech_report_prn/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# © 2008-2021 Deltatech
# See README.rst file on addons root folder for license details


import json
import time

from werkzeug.urls import url_decode

from odoo.http import content_disposition, request, route
from odoo.tools.safe_eval import safe_eval

import odoo.addons.web.controllers.report as report


class ReportController(report.ReportController):
@route()
def report_routes(self, reportname, docids=None, converter=None, **data):
if converter == "prn":
return super().report_routes(reportname, docids, "text", **data)
return super().report_routes(reportname, docids, converter, **data)

@route()
def report_download(self, data, context=None):
"""This function is used by 'action_manager_report.js' in order to trigger the download of
a pdf/controller 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 = requestcontent[0], requestcontent[1]
if report_type == "qweb-prn":
converter = "prn"
extension = "prn"

pattern = "/report/prn/"
reportname = url.split(pattern)[1].split("?")[0]

docids = None
if "/" in reportname:
reportname, docids = reportname.split("/")

if docids:
# Generic report:
response = self.report_routes(reportname, docids=docids, converter=converter, context=context)
else:
# Particular report:
data = dict(url_decode(url.split("?")[1]).items()) # decoding the args represented in JSON
if "context" in data:
context, data_context = json.loads(context or "{}"), json.loads(data.pop("context"))
context = json.dumps({**context, **data_context})
response = self.report_routes(reportname, converter=converter, context=context, **data)

report = request.env["ir.actions.report"]._get_report_from_name(reportname)
filename = f"{report.name}.{extension}"

if docids:
ids = [int(x) for x in docids.split(",")]
obj = request.env[report.model].browse(ids)
if report.print_report_name and not len(obj) > 1:
report_name = safe_eval(report.print_report_name, {"object": obj, "time": time})
filename = f"{report_name}.{extension}"
response.headers.add("Content-Disposition", content_disposition(filename))
return response

return super().report_download(data, context)
5 changes: 5 additions & 0 deletions deltatech_report_prn/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# © 2008-2021 Deltatech
# See README.rst file on addons root folder for license details


from . import ir_report
19 changes: 19 additions & 0 deletions deltatech_report_prn/models/ir_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# © 2008-2021 Deltatech
# See README.rst file on addons root folder for license details


from odoo import api, fields, models


class ReportAction(models.Model):
_inherit = "ir.actions.report"

report_type = fields.Selection(selection_add=[("qweb-prn", "PRN")], ondelete={"qweb-prn": "set default"})

@api.model
def _render_qweb_prn(self, report_ref, docids, data):
if not data:
data = {}
data.setdefault("report_type", "text")
data = self._get_rendering_context(self, docids, data)
return self._render_template(self.sudo().report_name, data), "text"
3 changes: 3 additions & 0 deletions deltatech_report_prn/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
3 changes: 3 additions & 0 deletions deltatech_report_prn/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Features:

- It allows the printing of files with the .prn extension. These are files that have syntax for Zebra label printers.
Binary file added deltatech_report_prn/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 36aeced

Please sign in to comment.