Skip to content

Commit

Permalink
[MIG] base_report_to_printer: Migration to 18.0
Browse files Browse the repository at this point in the history
[MIG] base_report_to_printer: Migration to 18.0
  • Loading branch information
trisdoan committed Oct 24, 2024
1 parent 5334764 commit 2f8495e
Show file tree
Hide file tree
Showing 24 changed files with 113 additions and 105 deletions.
17 changes: 12 additions & 5 deletions base_report_to_printer/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Report to printer
: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_printer
:target: https://github.com/OCA/report-print-send/tree/18.0/base_report_to_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_printer
:target: https://translation.odoo-community.org/projects/report-print-send-18-0/report-print-send-18-0-base_report_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/report-print-send&target_branch=17.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/report-print-send&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -131,7 +131,7 @@ 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:%20base_report_to_printer%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/report-print-send/issues/new?body=module:%20base_report_to_printer%0Aversion:%2018.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.

Expand Down Expand Up @@ -168,6 +168,13 @@ Contributors
- Hughes Damry <hughes.damry@acsone.eu>
- Akim Juillerat <akim.juillerat@camptocamp.com>
- Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
- Tris Doan <tridm@trobz.com>

Other credits
-------------

The migration of this module from 17.0 to 18.0 was financially supported
by Camptocamp.

Maintainers
-----------
Expand All @@ -182,6 +189,6 @@ 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/17.0/base_report_to_printer>`_ project on GitHub.
This module is part of the `OCA/report-print-send <https://github.com/OCA/report-print-send/tree/18.0/base_report_to_printer>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion base_report_to_printer/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

{
"name": "Report to printer",
"version": "17.0.1.0.1",
"version": "18.0.1.0.0",
"category": "Generic Modules/Base",
"author": "Agile Business Group & Domsense, Pegueroles SCP, NaN,"
" LasLabs, Camptocamp, Odoo Community Association (OCA),"
Expand Down
16 changes: 5 additions & 11 deletions base_report_to_printer/data/printing_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,19 @@
<field name="name">Send to Client</field>
<field name="action_type">client</field>
</record>
<!-- properties -->
<record forcecreate="True" id="property_printing_action_id" model="ir.property">
<field name="name">property_printing_action_id</field>
<field
name="fields_id"
search="[('model', '=', 'ir.actions.report'), ('name', '=', 'property_printing_action_id')]"
/>
<field name="value" eval="'printing.action,' + str(printing_action_2)" />
</record>
<record forcecreate="True" id="ir_cron_update_printers" model="ir.cron">
<field name="name">Update Printers Jobs</field>
<field name="active" eval="True" />
<field name="user_id" ref="base.user_root" />
<field name="interval_number">1</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False" />
<field name="model_id" ref="base_report_to_printer.model_printing_server" />
<field name="state">code</field>
<field name="code">model.action_update_jobs()</field>
</record>
<function
model="ir.default"
name="set"
eval="('ir.actions.report', 'property_printing_action_id', obj().env.ref('base_report_to_printer.printing_action_2').id)"
/>
</odoo>
2 changes: 1 addition & 1 deletion base_report_to_printer/models/ir_actions_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def print_document(self, record_ids, data=None):
_("This report type (%s) is not supported by direct printing!")
% str(self.report_type)
)
method_name = "_render_qweb_%s" % (report_type)
method_name = f"_render_qweb_{report_type}"
document, doc_format = getattr(
self.with_context(must_skip_send_to_printer=True), method_name
)(self.report_name, record_ids, data=data)
Expand Down
18 changes: 9 additions & 9 deletions base_report_to_printer/models/printing_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo import fields, models

AVAILABLE_ACTION_TYPES = [
("server", "Send to Printer"),
("client", "Send to Client"),
("user_default", "Use user's defaults"),
]


class PrintingAction(models.Model):
_name = "printing.action"
_description = "Print Job Action"

@api.model
def _available_action_types(self):
return [
("server", "Send to Printer"),
("client", "Send to Client"),
("user_default", "Use user's defaults"),
]
_available_action_types = AVAILABLE_ACTION_TYPES

name = fields.Char(required=True)
action_type = fields.Selection(
selection=_available_action_types, string="Type", required=True
selection=AVAILABLE_ACTION_TYPES, string="Type", required=True
)
2 changes: 1 addition & 1 deletion base_report_to_printer/models/printing_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def print_options(self, report=None, **print_opts):
options = {}
for option, value in print_opts.items():
try:
options.update(getattr(self, "_set_option_%s" % option)(report, value))
options.update(getattr(self, f"_set_option_{option}")(report, value))
except AttributeError:
options[option] = str(value)
return options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PrintingReportXmlAction(models.Model):
comodel_name="res.users", string="User", required=True, ondelete="cascade"
)
action = fields.Selection(
selection=lambda s: s.env["printing.action"]._available_action_types(),
selection=lambda s: s.env["printing.action"]._available_action_types,
required=True,
)
printer_id = fields.Many2one(comodel_name="printing.printer", string="Printer")
Expand Down
14 changes: 5 additions & 9 deletions base_report_to_printer/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@

from odoo import api, fields, models

from .printing_action import AVAILABLE_ACTION_TYPES

action_types = [type for type in AVAILABLE_ACTION_TYPES if type[0] != "user_default"]


class ResUsers(models.Model):
_inherit = "res.users"

@api.model
def _user_available_action_types(self):
return [
(code, string)
for code, string in self.env["printing.action"]._available_action_types()
if code != "user_default"
]

printing_action = fields.Selection(selection=_user_available_action_types)
printing_action = fields.Selection(selection=action_types)
printing_printer_id = fields.Many2one(
comodel_name="printing.printer", string="Default Printer"
)
Expand Down
1 change: 1 addition & 0 deletions base_report_to_printer/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
- Hughes Damry \<<hughes.damry@acsone.eu>\>
- Akim Juillerat \<<akim.juillerat@camptocamp.com>\>
- Jacques-Etienne Baudoux (BCIM) \<<je@bcim.be>\>
- Tris Doan \<<tridm@trobz.com>\>
1 change: 1 addition & 0 deletions base_report_to_printer/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The migration of this module from 17.0 to 18.0 was financially supported by Camptocamp.
28 changes: 19 additions & 9 deletions base_report_to_printer/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -274,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -368,7 +369,7 @@ <h1 class="title">Report to printer</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:3d37f5e02c22560d293e60d6fb565eea3a6657926defd87d4a6ca71cc229ab60
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/report-print-send/tree/17.0/base_report_to_printer"><img alt="OCA/report-print-send" src="https://img.shields.io/badge/github-OCA%2Freport--print--send-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/report-print-send-17-0/report-print-send-17-0-base_report_to_printer"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/report-print-send&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/report-print-send/tree/18.0/base_report_to_printer"><img alt="OCA/report-print-send" src="https://img.shields.io/badge/github-OCA%2Freport--print--send-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/report-print-send-18-0/report-print-send-18-0-base_report_to_printer"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/report-print-send&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows users to send reports to a printer attached to the
server.</p>
<p>It adds an optional behaviour on reports to send it directly to a
Expand Down Expand Up @@ -407,7 +408,8 @@ <h1 class="title">Report to printer</h1>
<li><a class="reference internal" href="#credits" id="toc-entry-8">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-9">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-10">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-11">Maintainers</a></li>
<li><a class="reference internal" href="#other-credits" id="toc-entry-11">Other credits</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-12">Maintainers</a></li>
</ul>
</li>
</ul>
Expand Down Expand Up @@ -482,7 +484,7 @@ <h1><a class="toc-backref" href="#toc-entry-7">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/report-print-send/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/report-print-send/issues/new?body=module:%20base_report_to_printer%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/report-print-send/issues/new?body=module:%20base_report_to_printer%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand Down Expand Up @@ -518,16 +520,24 @@ <h2><a class="toc-backref" href="#toc-entry-10">Contributors</a></h2>
<li>Hughes Damry &lt;<a class="reference external" href="mailto:hughes.damry&#64;acsone.eu">hughes.damry&#64;acsone.eu</a>&gt;</li>
<li>Akim Juillerat &lt;<a class="reference external" href="mailto:akim.juillerat&#64;camptocamp.com">akim.juillerat&#64;camptocamp.com</a>&gt;</li>
<li>Jacques-Etienne Baudoux (BCIM) &lt;<a class="reference external" href="mailto:je&#64;bcim.be">je&#64;bcim.be</a>&gt;</li>
<li>Tris Doan &lt;<a class="reference external" href="mailto:tridm&#64;trobz.com">tridm&#64;trobz.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="other-credits">
<h2><a class="toc-backref" href="#toc-entry-11">Other credits</a></h2>
<p>The migration of this module from 17.0 to 18.0 was financially supported
by Camptocamp.</p>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-11">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-12">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/report-print-send/tree/17.0/base_report_to_printer">OCA/report-print-send</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/report-print-send/tree/18.0/base_report_to_printer">OCA/report-print-send</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/** @odoo-module */
import {_t} from "@web/core/l10n/translation";
import {registry} from "@web/core/registry";

Expand Down
6 changes: 3 additions & 3 deletions base_report_to_printer/tests/test_ir_actions_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,22 @@ def new_tray(self, vals=None, defaults=None):

def test_print_action_for_report_name_gets_report(self):
"""It should get report by name"""
with mock.patch("%s._get_report_from_name" % model) as mk:
with mock.patch(f"{model}._get_report_from_name") as mk:
expect = "test"
self.Model.print_action_for_report_name(expect)
mk.assert_called_once_with(expect)

def test_print_action_for_report_name_returns_if_no_report(self):
"""It should return empty dict when no matching report"""
with mock.patch("%s._get_report_from_name" % model) as mk:
with mock.patch(f"{model}._get_report_from_name") as mk:
expect = "test"
mk.return_value = False
res = self.Model.print_action_for_report_name(expect)
self.assertDictEqual({}, res)

def test_print_action_for_report_name_returns_if_report(self):
"""It should return correct serializable result for behaviour"""
with mock.patch("%s._get_report_from_name" % model) as mk:
with mock.patch(f"{model}._get_report_from_name") as mk:
res = self.Model.print_action_for_report_name("test")
behaviour = mk().behaviour()
expect = {
Expand Down
4 changes: 2 additions & 2 deletions base_report_to_printer/tests/test_printing_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def new_job(self, printer, vals=None):
values["printer_id"] = printer.id
return self.env["printing.job"].create(values)

@mock.patch("%s.cups" % model)
@mock.patch(f"{model}.cups")
def test_cancel_job_error(self, cups):
"""It should catch any exception from CUPS and update status"""
cups.Connection.side_effect = Exception
Expand All @@ -52,7 +52,7 @@ def test_cancel_job_error(self, cups):
cups.Connection.side_effect = None
self.assertEqual(cups.Connection().cancelJob.call_count, 0)

@mock.patch("%s.cups" % model)
@mock.patch(f"{model}.cups")
def test_cancel_job(self, cups):
"""It should catch any exception from CUPS and update status"""
printer = self.new_printer()
Expand Down
Loading

0 comments on commit 2f8495e

Please sign in to comment.