[MIG] base_report_to_printer: Upgrade to v9

This commit is contained in:
Dave Lasley
2016-07-04 14:36:57 -07:00
committed by John Herholz
parent 946ffce485
commit 90e5624304
37 changed files with 955 additions and 674 deletions

View File

@@ -1,5 +1,11 @@
Report to printer
-----------------
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
=================
Report To Printer
=================
This module allows users to send reports to a printer attached to the server.
@@ -18,11 +24,22 @@ Settings can be configured:
* per report
* per user and report
Installation
============
After installing enable the "Printing / Print Operator" option under access
* Install PyCups - https://pypi.python.org/pypi/pycups
Configuration
=============
After installing enable the "Printing / Print User" option under access
rights to give users the ability to view the print menu.
Usage
=====
To show all available printers for your server, use the
`Settings/Configuration/Printing/Update Printers from CUPS` wizard.
@@ -36,12 +53,31 @@ Caveat
The notification when a report is sent to a printer will not be
displayed for the deprecated report types (RML, Webkit, ...).
Dependencies
------------
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/144/9.0
This module requires pycups
https://pypi.python.org/pypi/pycups
Known issues / Roadmap
======================
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/{project_repo}/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------
@@ -53,3 +89,19 @@ Contributors
* Yannick Vaucher <yannick.vaucher@camptocamp.com>
* Lionel Sausin <ls@numerigraphe.com>
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
* Dave Lasley <dave@laslabs.com>
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
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.
To contribute to this module, please visit https://odoo-community.org.

View File

@@ -1,30 +1,11 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2007 Ferran Pegueroles <ferran@pegueroles.com>
# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com>
# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import printing
from . import report
from . import report_xml_action
# Copyright (c) 2007 Ferran Pegueroles <ferran@pegueroles.com>
# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com>
# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import models
from . import report_service
from . import users
from . import ir_report
from . import wizard
from . import wizards

View File

@@ -1,48 +1,33 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2007 Ferran Pegueroles <ferran@pegueroles.com>
# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com>
# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
# Copyright (c) 2007 Ferran Pegueroles <ferran@pegueroles.com>
# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com>
# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': "Report to printer",
'version': '8.0.0.1.2',
'version': '9.0.1.0.0',
'category': 'Generic Modules/Base',
'author': "Agile Business Group & Domsense, Pegueroles SCP, NaN,"
"Odoo Community Association (OCA)",
" LasLabs, Odoo Community Association (OCA)",
'website': 'http://www.agilebg.com',
'license': 'AGPL-3',
"depends": ['base',
'report',
],
"depends": ['report'],
'data': [
'data/printing_data.xml',
'security/security.xml',
'printing_data.xml',
'printing_view.xml',
'base_report_to_printer.xml',
'wizard/update_printers.xml',
'views/assets.xml',
'views/printing_printer_view.xml',
'views/printing_report_view.xml',
'views/res_users_view.xml',
'views/ir_actions_report_xml_view.xml',
'wizards/printing_printer_update_wizard_view.xml',
],
'installable': False,
'auto_install': False,
'installable': True,
'application': True,
'external_dependencies': {
'python': ['cups']
}
'python': ['cups'],
},
}

View File

@@ -1,11 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="assets_backend" name="base_report_to_printer assets" inherit_id="report.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/base_report_to_printer/static/src/js/qwebactionmanager.js"></script>
</xpath>
</template>
</data>
</openerp>

View File

@@ -0,0 +1,33 @@
<?xml version="1.0"?>
<odoo noupdate="1">
<!-- printing.action -->
<record model="printing.action" id="printing_action_1">
<field name="name">Send to Printer</field>
<field name="type">server</field>
</record>
<record model="printing.action" id="printing_action_2">
<field name="name">Send to Client</field>
<field name="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.xml'),('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 Status</field>
<field eval="True" name="active"/>
<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 eval="False" name="doall"/>
<field eval="'printing.printer'" name="model"/>
<field eval="'update_printers_status'" name="function"/>
<field eval="'()'" name="args"/>
</record>
</odoo>

View File

@@ -18,7 +18,7 @@ msgstr ""
"X-Generator: Launchpad (build 16996)\n"
#. module: base_report_to_printer
#: field:ir.actions.report.xml,property_printing_action:0
#: field:ir.actions.report.xml,property_printing_action_id:0
#: field:printing.report.xml.action,action:0
msgid "Action"
msgstr "Action"
@@ -70,7 +70,7 @@ msgstr "Imprimante par défaut"
#. module: base_report_to_printer
#. openerp-web
#: code:addons/base_report_to_printer/static/src/js/qwebactionmanager.js:27
#: code:addons/base_report_to_printer/static/src/js/qweb_action_manager.js:27
#, python-format
msgid "Document sent to the printer "
msgstr "Document envoyé à l'imprimante "
@@ -82,7 +82,7 @@ msgstr "Erreur"
#. module: base_report_to_printer
#. openerp-web
#: code:addons/base_report_to_printer/static/src/js/qwebactionmanager.js:30
#: code:addons/base_report_to_printer/static/src/js/qweb_action_manager.js:30
#, python-format
msgid "Error when sending the document to the printer "
msgstr "Erreur lors de l'envoi du document à l'imprimante "
@@ -139,12 +139,12 @@ msgid "No printer configured to print this report."
msgstr "Pas d'imprimante configurée pour imprimer ce rapport."
#. module: base_report_to_printer
#: view:res.users:base_report_to_printer.view_printing_users_form
#: view:res.users:base_report_to_printer.view_users_form
msgid "Preferences"
msgstr "Préférences"
#. module: base_report_to_printer
#: view:ir.actions.report.xml:base_report_to_printer.action_report_xml_form
#: view:ir.actions.report.xml:base_report_to_printer.act_report_xml_view
msgid "Print"
msgstr "Imprimer"
@@ -161,22 +161,22 @@ msgid "Printer"
msgstr "Imprimante"
#. module: base_report_to_printer
#: model:ir.ui.menu,name:base_report_to_printer.menu_printing_printer_form
#: view:printing.printer:base_report_to_printer.view_printing_printer_form
#: view:printing.printer:base_report_to_printer.view_printing_printer_search
#: view:printing.printer:base_report_to_printer.view_printing_printer_tree
#: model:ir.ui.menu,name:base_report_to_printer.printing_printer_menu
#: view:printing.printer:base_report_to_printer.printing_printer_view_form
#: view:printing.printer:base_report_to_printer.printing_printer_view_search
#: view:printing.printer:base_report_to_printer.printing_printer_view_tree
msgid "Printers"
msgstr "Imprimantes"
#. module: base_report_to_printer
#: model:ir.ui.menu,name:base_report_to_printer.menu_printing_main
#: model:ir.ui.menu,name:base_report_to_printer.printing_menu
#: selection:printing.printer,status:0
#: view:res.users:base_report_to_printer.view_printing_users_prefs
#: view:res.users:base_report_to_printer.view_users_form_simple_modif
msgid "Printing"
msgstr "Impression en cours"
#. module: base_report_to_printer
#: model:res.groups,name:base_report_to_printer.res_groups_printingprintoperator0
#: model:res.groups,name:base_report_to_printer.printing_group_manager
msgid "Printing / Print Operator"
msgstr "Opérateur d'impression"
@@ -187,8 +187,8 @@ msgstr "Action d'impression"
#. module: base_report_to_printer
#. openerp-web
#: code:addons/base_report_to_printer/static/src/js/qwebactionmanager.js:26
#: code:addons/base_report_to_printer/static/src/js/qwebactionmanager.js:29
#: code:addons/base_report_to_printer/static/src/js/qweb_action_manager.js:26
#: code:addons/base_report_to_printer/static/src/js/qweb_action_manager.js:29
#: model:ir.model,name:base_report_to_printer.model_report
#: field:printing.report.xml.action,report_id:0
#, python-format
@@ -196,19 +196,19 @@ msgid "Report"
msgstr "Rapport"
#. module: base_report_to_printer
#: model:ir.model,name:base_report_to_printer.model_printing_report_xml_action
#: view:printing.report.xml.action:base_report_to_printer.printing_report_xml_action_form
#: view:printing.report.xml.action:base_report_to_printer.printing_report_xml_action_tree
#: model:ir.model,name:base_report_to_printer.model_printing_report_xml_action_view_form
#: view:printing.report.xml.action:base_report_to_printer.printing_report_xml_action_view_form
#: view:printing.report.xml.action:base_report_to_printer.printing_report_xml_action_view_tree
msgid "Report Printing Actions"
msgstr "Actions d'impression de rapports"
#. module: base_report_to_printer
#: model:ir.ui.menu,name:base_report_to_printer.menu_printing_reports
#: model:ir.ui.menu,name:base_report_to_printer.printing_report_xml_action_menu
msgid "Reports"
msgstr "Rapport"
#. module: base_report_to_printer
#: view:ir.actions.report.xml:base_report_to_printer.action_report_xml_form
#: view:ir.actions.report.xml:base_report_to_printer.act_report_xml_view
msgid "Security"
msgstr "Sécurité"
@@ -218,17 +218,17 @@ msgid "Server Error"
msgstr "Erreur serveur"
#. module: base_report_to_printer
#: view:printing.printer:base_report_to_printer.view_printing_printer_form
#: view:printing.printer:base_report_to_printer.printing_printer_view_form
msgid "Set Default"
msgstr "Définir par défaut"
#. module: base_report_to_printer
#: model:ir.actions.act_window,name:base_report_to_printer.action_printing_printer_form
#: model:ir.actions.act_window,name:base_report_to_printer.printing_printer_action
msgid "Show Printers"
msgstr "Afficher les imprimantes"
#. module: base_report_to_printer
#: view:ir.actions.report.xml:base_report_to_printer.action_report_xml_form
#: view:ir.actions.report.xml:base_report_to_printer.act_report_xml_view
msgid "Specific actions per user"
msgstr "Action spécifique par utilisateur"

View File

@@ -44,8 +44,8 @@ msgid "Location"
msgstr "Locazione"
#. module: base_report_to_printer
#: model:ir.actions.act_window,name:base_report_to_printer.action_printing_printer_form
#: model:ir.ui.menu,name:base_report_to_printer.menu_printing_printer_form
#: model:ir.actions.act_window,name:base_report_to_printer.printing_printer_action
#: model:ir.ui.menu,name:base_report_to_printer.printing_printer_menu
#: view:printing.printer:0
msgid "Printers"
msgstr "Stampanti"
@@ -88,7 +88,7 @@ msgid "Users"
msgstr ""
#. module: base_report_to_printer
#: model:ir.model,name:base_report_to_printer.model_printing_report_xml_action
#: model:ir.model,name:base_report_to_printer.model_printing_report_xml_action_view_form
#: view:printing.report.xml.action:0
msgid "Report Printing Actions"
msgstr "Azioni di stampa report"
@@ -119,7 +119,7 @@ msgid "Status"
msgstr "Stato"
#. module: base_report_to_printer
#: model:ir.actions.act_window,name:base_report_to_printer.action_printing_printer_form
#: model:ir.actions.act_window,name:base_report_to_printer.printing_printer_action
msgid "Show Printers"
msgstr ""
@@ -170,7 +170,7 @@ msgid "Send to Printer"
msgstr "Invia alla stampante"
#. module: base_report_to_printer
#: model:ir.ui.menu,name:base_report_to_printer.menu_printing_main
#: model:ir.ui.menu,name:base_report_to_printer.printing_menu
#: selection:printing.printer,status:0
msgid "Printing"
msgstr "Stampa"
@@ -181,7 +181,7 @@ msgid "Error"
msgstr "Errore"
#. module: base_report_to_printer
#: field:ir.actions.report.xml,property_printing_action:0
#: field:ir.actions.report.xml,property_printing_action_id:0
#: field:printing.report.xml.action,action:0
msgid "Action"
msgstr "Azione"
@@ -219,7 +219,7 @@ msgid "Cancel"
msgstr "Annulla"
#. module: base_report_to_printer
#: model:res.groups,name:base_report_to_printer.res_groups_printingprintoperator0
#: model:res.groups,name:base_report_to_printer.printing_group_manager
msgid "Printing / Print Operator"
msgstr ""

View File

@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
from . import ir_actions_report_xml
from . import printing_action
from . import printing_printer
from . import printing_report_xml_action
from . import report
from . import res_users

View File

@@ -1,41 +1,22 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2007 Ferran Pegueroles <ferran@pegueroles.com>
# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com>
# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import logging
# Copyright (c) 2007 Ferran Pegueroles <ferran@pegueroles.com>
# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com>
# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import models, fields, api
_logger = logging.getLogger('base_report_to_printer')
class ReportXml(models.Model):
class IrActionsReportXml(models.Model):
"""
Reports
"""
_inherit = 'ir.actions.report.xml'
property_printing_action = fields.Many2one(
property_printing_action_id = fields.Many2one(
comodel_name='printing.action',
string='Action',
company_dependent=True,
@@ -91,7 +72,7 @@ class ReportXml(models.Model):
printer = default_printer
# Retrieve report default values
report_action = report.property_printing_action
report_action = report.property_printing_action_id
if report_action and report_action.type != 'user_default':
action = report_action.type
if report.printing_printer_id:

View File

@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2007 Ferran Pegueroles <ferran@pegueroles.com>
# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com>
# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import models, fields, api
@api.model
def _available_action_types(self):
return [('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'
name = fields.Char(required=True)
type = fields.Selection(
lambda s: _available_action_types(s),
required=True,
)

View File

@@ -1,40 +1,29 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2007 Ferran Pegueroles <ferran@pegueroles.com>
# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com>
# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
# Copyright (c) 2007 Ferran Pegueroles <ferran@pegueroles.com>
# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com>
# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging
_logger = logging.getLogger(__name__)
import os
from tempfile import mkstemp
from openerp import models, fields, api, _
from openerp.exceptions import UserError
from openerp.tools.config import config
_logger = logging.getLogger(__name__)
try:
import cups
except ImportError:
_logger.debug('Cannot `import cups`.')
from openerp import models, fields, api, _
from openerp.exceptions import Warning
from openerp.tools.config import config
CUPS_HOST = config.get('cups_host', 'localhost')
CUPS_PORT = int(config.get('cups_port', 631)) # config.get returns a string
@@ -67,8 +56,10 @@ class PrintingPrinter(models.Model):
uri = fields.Char(string='URI', readonly=True)
@api.model
def update_printers_status(self):
printer_recs = self.search([])
def update_printers_status(self, domain=None):
if domain is None:
domain = []
printer_recs = self.search(domain)
try:
connection = cups.Connection(CUPS_HOST, CUPS_PORT)
printers = connection.getPrinters()
@@ -144,7 +135,7 @@ class PrintingPrinter(models.Model):
connection = cups.Connection(CUPS_HOST, CUPS_PORT)
_logger.debug('Connection to CUPS successfull')
except:
raise Warning(
raise UserError(
_("Failed to connect to the CUPS server on %s:%s. "
"Check that the CUPS server is running and that "
"you can reach it from the Odoo server.")
@@ -175,22 +166,3 @@ class PrintingPrinter(models.Model):
@api.multi
def get_default(self):
return self.search([('default', '=', True)], limit=1)
#
# Actions
#
def _available_action_types(self):
return [('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'
name = fields.Char(required=True)
type = fields.Selection(_available_action_types, required=True)

View File

@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2007 Ferran Pegueroles <ferran@pegueroles.com>
# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com>
# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import models, fields, api
from .printing_action import _available_action_types
class PrintingReportXmlAction(models.Model):
_name = 'printing.report.xml.action'
_description = 'Printing Report Printing Actions'
report_id = fields.Many2one(comodel_name='ir.actions.report.xml',
string='Report',
required=True,
ondelete='cascade')
user_id = fields.Many2one(comodel_name='res.users',
string='User',
required=True,
ondelete='cascade')
action = fields.Selection(
lambda s: _available_action_types(s),
required=True,
)
printer_id = fields.Many2one(comodel_name='printing.printer',
string='Printer')
@api.multi
def behaviour(self):
if not self:
return {}
return {'action': self.action,
'printer': self.printer_id,
}

View File

@@ -0,0 +1,72 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2014 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import models, exceptions, _, api
class Report(models.Model):
_inherit = 'report'
@api.multi
def print_document(self, report_name, html=None, data=None):
""" Print a document, do not return the document file """
res = []
context = self.env.context
if context is None:
context = self.env['res.users'].context_get()
local_context = context.copy()
local_context['must_skip_send_to_printer'] = True
for rec_id in self.with_context(local_context):
document = rec_id.get_pdf(report_name, html=html, data=data)
report = self._get_report_from_name(report_name)
behaviour = report.behaviour()[report.id]
printer = behaviour['printer']
if not printer:
raise exceptions.Warning(
_('No printer configured to print this report.')
)
res.append(
printer.print_document(report, document, report.report_type)
)
return all(res)
@api.multi
def _can_print_report(self, behaviour, printer, document):
"""Predicate that decide if report can be sent to printer
If you want to prevent `get_pdf` to send report you can set
the `must_skip_send_to_printer` key to True in the context
"""
if self.env.context.get('must_skip_send_to_printer'):
return False
if behaviour['action'] == 'server' and printer and document:
return True
return False
@api.v7
def get_pdf(self, cr, uid, ids, report_name, html=None,
data=None, context=None):
""" Generate a PDF and returns it.
If the action configured on the report is server, it prints the
generated document as well.
"""
document = super(Report, self).get_pdf(cr, uid, ids, report_name,
html=html, data=data,
context=context)
report = self._get_report_from_name(cr, uid, report_name)
behaviour = report.behaviour()[report.id]
printer = behaviour['printer']
can_print_report = self._can_print_report(cr, uid, ids,
behaviour, printer, document,
context=context)
if can_print_report:
printer.print_document(report, document, report.report_type)
return document
@api.v8
def get_pdf(self, records, report_name, html=None, data=None):
return self._model.get_pdf(self._cr, self._uid,
records.ids, report_name,
html=html, data=data, context=self._context)

View File

@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2007 Ferran Pegueroles <ferran@pegueroles.com>
# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com>
# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import models, fields, api
from .printing_action import _available_action_types
class ResUsers(models.Model):
_inherit = 'res.users'
printing_action = fields.Selection(
lambda s: s._user_available_action_types(),
)
printing_printer_id = fields.Many2one(comodel_name='printing.printer',
string='Default Printer')
@api.model
def _available_action_types(self):
return _available_action_types(self)
@api.model
def _user_available_action_types(self):
return [(code, string) for code, string
in self._available_action_types()
if code != 'user_default']

View File

@@ -1,34 +0,0 @@
<?xml version="1.0"?>
<openerp>
<data noupdate="1">
<!-- printing.action -->
<record model="printing.action" id="printing_action_1">
<field name="name">Send to Printer</field>
<field name="type">server</field>
</record>
<record model="printing.action" id="printing_action_2">
<field name="name">Send to Client</field>
<field name="type">client</field>
</record>
<!-- properties -->
<record forcecreate="True" id="property_printing_action" model="ir.property">
<field name="name">property_printing_action</field>
<field name="fields_id" search="[('model','=','ir.actions.report.xml'),('name','=','property_printing_action')]"/>
<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 Status</field>
<field eval="True" name="active"/>
<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 eval="False" name="doall"/>
<field eval="'printing.printer'" name="model"/>
<field eval="'update_printers_status'" name="function"/>
<field eval="'()'" name="args"/>
</record>
</data>
</openerp>

View File

@@ -1,158 +0,0 @@
<?xml version="1.0"?>
<openerp>
<data>
<menuitem name="Printing" id="menu_printing_main" parent="base.menu_administration" groups="res_groups_printingprintoperator0"/>
<record model="ir.ui.view" id="view_printing_printer_form">
<field name="name">printing.printer.form</field>
<field name="model">printing.printer</field>
<field name="arch" type="xml">
<form string="Printers">
<sheet>
<div class="oe_title">
<h1>
<label for="name"/>
<field name="name"/>
</h1>
</div>
<group>
<field name="system_name"/>
</group>
<group col="3" colspan="4">
<field name="default"/>
<button name="set_default" string="Set Default" type="object"/>
</group>
<group>
<field name="uri"/>
<field name="model"/>
<field name="location"/>
<field name="status"/>
<field name="status_message"/>
</group>
</sheet>
</form>
</field>
</record>
<record model="ir.ui.view" id="view_printing_printer_tree">
<field name="name">printing.printer.tree</field>
<field name="model">printing.printer</field>
<field name="arch" type="xml">
<tree string="Printers" colors="green:status=='available'; orange:status=='printing'; red:1;">
<field name="default"/>
<field name="name"/>
<field name="system_name"/>
<field name="status"/>
</tree>
</field>
</record>
<record model="ir.ui.view" id="view_printing_printer_search">
<field name="name">printing.printer.search</field>
<field name="model">printing.printer</field>
<field name="arch" type="xml">
<search string="Printers">
<field name="name"/>
<field name="system_name"/>
<field name="location"/>
<field name="status"/>
</search>
</field>
</record>
<record model="ir.actions.act_window" id="action_printing_printer_form">
<field name="name">Show Printers</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">printing.printer</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="auto_refresh">20</field>
</record>
<menuitem name="Printers"
id="menu_printing_printer_form"
parent="menu_printing_main"
action="action_printing_printer_form"/>
<record model="ir.ui.view" id="action_report_xml_form">
<field name="name">ir.actions.report.xml.printing</field>
<field name="model">ir.actions.report.xml</field>
<field name="inherit_id" ref="base.act_report_xml_view" />
<field name="arch" type="xml">
<page string="Security" position="after">
<page string="Print">
<group>
<field name="property_printing_action"/>
<field name="printing_printer_id"/>
</group>
<separator string="Specific actions per user"/>
<field name="printing_action_ids"/>
</page>
</page>
</field>
</record>
<!-- res.users -->
<record model="ir.ui.view" id="view_printing_users_form">
<field name="name">res.users.form.printing</field>
<field name="model">res.users</field>
<field name="inherit_id" ref="base.view_users_form" />
<field name="arch" type="xml">
<page string="Preferences">
<group name="printing">
<field name="printing_action"/>
<field name="printing_printer_id"/>
</group>
</page>
</field>
</record>
<!-- "My Preferences -->
<record model="ir.ui.view" id="view_printing_users_prefs">
<field name="name">res.users.form.printing</field>
<field name="model">res.users</field>
<field name="inherit_id" ref="base.view_users_form_simple_modif" />
<field name="arch" type="xml">
<footer position="before">
<group string="Printing" name="printing">
<field name="printing_action"/>
<field name="printing_printer_id"/>
</group>
</footer>
</field>
</record>
<!-- printing.report.xml.action -->
<record model="ir.ui.view" id="printing_report_xml_action_form">
<field name="name">printing.report.xml.action.form</field>
<field name="model">printing.report.xml.action</field>
<field name="arch" type="xml">
<form string="Report Printing Actions">
<group col="2">
<field name="user_id"/>
<field name="action"/>
<field name="printer_id" select="1"/>
</group>
</form>
</field>
</record>
<record model="ir.ui.view" id="printing_report_xml_action_tree">
<field name="name">printing.report.xml.action.tree</field>
<field name="model">printing.report.xml.action</field>
<field name="arch" type="xml">
<tree string="Report Printing Actions">
<field name="user_id"/>
<field name="action" />
<field name="printer_id" />
</tree>
</field>
</record>
<!-- Add a shorcut to "Actions/Report" in the Printing menu -->
<menuitem id="menu_printing_reports"
parent="menu_printing_main"
action="base.ir_action_report_xml"/>
</data>
</openerp>

View File

@@ -1,93 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Guewen Baconnier
# Copyright 2014 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import models, exceptions, _, api
class Report(models.Model):
_inherit = 'report'
@api.v7
def print_document(self, cr, uid, ids, report_name, html=None,
data=None, context=None):
""" Print a document, do not return the document file """
if context is None:
context = self.pool['res.users'].context_get(cr, uid)
local_context = context.copy()
local_context['must_skip_send_to_printer'] = True
document = self.get_pdf(cr, uid, ids, report_name,
html=html, data=data, context=local_context)
report = self._get_report_from_name(cr, uid, report_name)
behaviour = report.behaviour()[report.id]
printer = behaviour['printer']
if not printer:
raise exceptions.Warning(
_('No printer configured to print this report.')
)
return printer.with_context(context).print_document(
report, document, report.report_type)
@api.v8
def print_document(self, records, report_name, html=None, data=None):
return self._model.print_document(
self._cr, self._uid,
records.ids, report_name,
html=html, data=data, context=self._context)
def _can_print_report(self, cr, uid, ids, behaviour, printer, document,
context=None):
"""Predicate that decide if report can be sent to printer
If you want to prevent `get_pdf` to send report you can set
the `must_skip_send_to_printer` key to True in the context
"""
if context is not None and context.get('must_skip_send_to_printer'):
return False
if behaviour['action'] == 'server' and printer and document:
return True
return False
@api.v7
def get_pdf(self, cr, uid, ids, report_name, html=None,
data=None, context=None):
""" Generate a PDF and returns it.
If the action configured on the report is server, it prints the
generated document as well.
"""
document = super(Report, self).get_pdf(cr, uid, ids, report_name,
html=html, data=data,
context=context)
report = self._get_report_from_name(cr, uid, report_name)
behaviour = report.behaviour()[report.id]
printer = behaviour['printer']
can_print_report = self._can_print_report(cr, uid, ids,
behaviour, printer, document,
context=context)
if can_print_report:
printer.print_document(report, document, report.report_type)
return document
@api.v8
def get_pdf(self, records, report_name, html=None, data=None):
return self._model.get_pdf(self._cr, self._uid,
records.ids, report_name,
html=html, data=data, context=self._context)

View File

@@ -1,26 +1,10 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2007 Ferran Pegueroles <ferran@pegueroles.com>
# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com>
# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
# Copyright (c) 2007 Ferran Pegueroles <ferran@pegueroles.com>
# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com>
# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import openerp
@@ -61,9 +45,11 @@ def exp_report_get(db, uid, report_id):
action = data['action']
printer = data['printer']
if action != 'client':
if (self_reports and self_reports.get(report_id)
and self_reports[report_id].get('result')
and self_reports[report_id].get('format')):
if all(self_reports,
self_reports.get(report_id),
self_reports[report_id].get('result'),
self_reports[report_id].get('format')
):
printer.print_document(report,
self_reports
[report_id]['result'],

View File

@@ -1,52 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2007 Ferran Pegueroles <ferran@pegueroles.com>
# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com>
# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import models, fields, api
from .printing import _available_action_types
class ReportXmlAction(models.Model):
_name = 'printing.report.xml.action'
_description = 'Report Printing Actions'
report_id = fields.Many2one(comodel_name='ir.actions.report.xml',
string='Report',
required=True,
ondelete='cascade')
user_id = fields.Many2one(comodel_name='res.users',
string='User',
required=True,
ondelete='cascade')
action = fields.Selection(_available_action_types,
required=True)
printer_id = fields.Many2one(comodel_name='printing.printer',
string='Printer')
@api.multi
def behaviour(self):
if not self:
return {}
return {'action': self.action,
'printer': self.printer_id,
}

View File

@@ -1,32 +1,35 @@
<?xml version="1.0" ?>
<openerp>
<odoo>
<data noupdate="1">
<record id="res_groups_printingprintoperator0" model="res.groups">
<field name="name">Printing / Print Operator</field>
<record id="printing_group_manager" model="res.groups">
<field name="name">Printing / Print Manager</field>
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record>
<record id="ir_model_access_printingprintergroup1" model="ir.model.access">
<field name="name">printing_printer group</field>
<record id="printing_group_user" model="res.groups">
<field name="name">Printing / Print User</field>
</record>
<record id="printing_printer_group_manager" model="ir.model.access">
<field name="name">Printing Printer Manager</field>
<field name="model_id" ref="model_printing_printer"/>
<field name="group_id" ref="res_groups_printingprintoperator0"/>
<field name="group_id" ref="printing_group_manager"/>
<field eval="1" name="perm_read"/>
<field eval="1" name="perm_unlink"/>
<field eval="1" name="perm_write"/>
<field eval="1" name="perm_create"/>
</record>
<record id="ir_model_access_printing_action" model="ir.model.access">
<field name="name">printing_printer group</field>
<record id="printing_action_group_manager" model="ir.model.access">
<field name="name">Printing Action Manager</field>
<field name="model_id" ref="model_printing_action"/>
<field name="group_id" ref="res_groups_printingprintoperator0"/>
<field name="group_id" ref="printing_group_manager"/>
<field eval="1" name="perm_read"/>
<field eval="1" name="perm_unlink"/>
<field eval="1" name="perm_write"/>
<field eval="1" name="perm_create"/>
</record>
<record id="ir_model_access_printingreportxmlaction" model="ir.model.access">
<field name="name">printing_printer group</field>
<record id="printing_report_xml_action_group_manager" model="ir.model.access">
<field name="name">Printing Report Xml Action Manager</field>
<field name="model_id" ref="model_printing_report_xml_action"/>
<field name="group_id" ref="res_groups_printingprintoperator0"/>
<field name="group_id" ref="printing_group_manager"/>
<field eval="1" name="perm_read"/>
<field eval="1" name="perm_unlink"/>
<field eval="1" name="perm_write"/>
@@ -35,29 +38,32 @@
</data>
<data>
<record id="ir_model_access_printingprinterall0" model="ir.model.access">
<field name="name">printing_printer all</field>
<record id="printing_printer_group_user" model="ir.model.access">
<field name="name">Printing Printer User</field>
<field name="model_id" ref="model_printing_printer"/>
<field name="group_id" ref="printing_group_user"/>
<field eval="1" name="perm_read"/>
<field eval="0" name="perm_unlink"/>
<field eval="0" name="perm_write"/>
<field eval="0" name="perm_create"/>
</record>
<record id="ir_model_access_printing_action_all0" model="ir.model.access">
<field name="name">printing_action all</field>
<record id="printing_action_group_user" model="ir.model.access">
<field name="name">Printing Action User</field>
<field name="model_id" ref="model_printing_action"/>
<field name="group_id" ref="printing_group_user"/>
<field eval="1" name="perm_read"/>
<field eval="0" name="perm_unlink"/>
<field eval="0" name="perm_write"/>
<field eval="0" name="perm_create"/>
</record>
<record id="ir_model_access_printing_report_xml_action_all0" model="ir.model.access">
<field name="name">printing_report_xml_action all</field>
<record id="printing_report_xml_action_group_user" model="ir.model.access">
<field name="name">Printing Report Xml Action User</field>
<field name="model_id" ref="model_printing_report_xml_action"/>
<field name="group_id" ref="printing_group_user"/>
<field eval="1" name="perm_read"/>
<field eval="0" name="perm_unlink"/>
<field eval="0" name="perm_write"/>
<field eval="0" name="perm_create"/>
</record>
</data>
</openerp>
</odoo>

View File

@@ -1,20 +1,26 @@
openerp.base_report_to_printer = function(instance) {
odoo.define('base_report_to_printer.print', function(require) {
'use strict';
instance.web.ActionManager.include({
var ActionManager = require('web.ActionManager');
var core = require('web.core');
var framework = require('web.framework');
var Model = require('web.Model');
ActionManager.include({
ir_actions_report_xml: function(action, options) {
instance.web.blockUI();
framework.blockUI();
action = _.clone(action);
var _t = instance.web._t;
var _t = core._t;
var self = this;
var _super = this._super;
if ('report_type' in action && action.report_type === 'qweb-pdf') {
new instance.web.Model('ir.actions.report.xml')
new Model('ir.actions.report.xml')
.call('print_action_for_report_name', [action.report_name])
.then(function(print_action){
if (print_action && print_action['action'] === 'server') {
instance.web.unblockUI();
new instance.web.Model('report')
if (print_action && print_action.action === 'server') {
framework.unblockUI();
new Model('report')
.call('print_document',
[action.context.active_ids,
action.report_name,
@@ -22,7 +28,7 @@ openerp.base_report_to_printer = function(instance) {
{data: action.data || {},
context: action.context || {},
})
.then(function(result){
.then(function(){
self.do_notify(_t('Report'),
_t('Document sent to the printer ') + print_action.printer_name);
}).fail(function() {
@@ -39,5 +45,6 @@ openerp.base_report_to_printer = function(instance) {
}
}
});
};
});

View File

@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
# Copyright 2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_printing_printer
from . import test_report
from . import test_res_users
from . import test_ir_actions_report_xml
from . import test_printing_printer_wizard

View File

@@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-
# Copyright 2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import mock
from openerp.tests.common import TransactionCase
class TestIrActionsReportXml(TransactionCase):
def setUp(self):
super(TestIrActionsReportXml, self).setUp()
self.Model = self.env['ir.actions.report.xml']
self.vals = {}
def new_record(self):
return self.Model.create(self.vals)
def test_print_action_for_report_name_gets_report(self):
""" It should get report by name """
with mock.patch.object(self.Model, 'env') as mk:
expect = 'test'
self.Model.print_action_for_report_name(expect)
mk['report']._get_report_from_name.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.object(self.Model, 'env') as mk:
expect = 'test'
mk['report']._get_report_from_name.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.object(self.Model, 'env') as mk:
res = self.Model.print_action_for_report_name('test')
behaviour = mk['report']._get_report_from_name().behaviour()[
mk['report']._get_report_from_name().id
]
expect = {
'action': behaviour['action'],
'printer_name': behaviour['printer'].name,
}
self.assertDictEqual(
expect, res,
'Expect %s, Got %s' % (expect, res),
)

View File

@@ -0,0 +1,107 @@
# -*- coding: utf-8 -*-
# Copyright 2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import mock
from openerp.tests.common import TransactionCase
from openerp.addons.base_report_to_printer.models.printing_printer import (
CUPS_HOST,
CUPS_PORT,
)
model = 'openerp.addons.base_report_to_printer.models.printing_printer'
class TestPrintingPrinter(TransactionCase):
def setUp(self):
super(TestPrintingPrinter, self).setUp()
self.Model = self.env['printing.printer']
self.printer_vals = {
'name': 'Printer',
'system_name': 'Sys Name',
'default': True,
'status': 'unknown',
'status_message': 'Msg',
'model': 'res.users',
'location': 'Location',
'uri': 'URI',
}
def new_record(self):
return self.Model.create(self.printer_vals)
@mock.patch('%s.cups' % model)
def test_update_printers_status_error(self, cups):
""" It should catch any exception from CUPS and update status """
cups.Connection.side_effect = Exception
rec_id = self.new_record()
self.Model.update_printers_status()
self.assertEqual(
'server-error', rec_id.status,
)
@mock.patch('%s.cups' % model)
def test_update_printers_status_inits_cups(self, cups):
""" It should init CUPS connection """
self.new_record()
self.Model.update_printers_status()
cups.Connection.assert_called_once_with(
CUPS_HOST, CUPS_PORT,
)
@mock.patch('%s.cups' % model)
def test_update_printers_status_gets_all_printers(self, cups):
""" It should get all printers from CUPS server """
self.new_record()
self.Model.update_printers_status()
cups.Connection().getPrinters.assert_called_once_with()
@mock.patch('%s.cups' % model)
def test_update_printers_status_gets_printer(self, cups):
""" It should get printer from CUPS by system_name """
rec_id = self.new_record()
self.Model.update_printers_status()
cups.Connection().getPrinters().get.assert_called_once_with(
rec_id.system_name,
)
@mock.patch('%s.cups' % model)
def test_update_printers_status_search(self, cups):
""" It should search all when no domain """
with mock.patch.object(self.Model, 'search') as search:
self.Model.update_printers_status()
search.assert_called_once_with([])
@mock.patch('%s.cups' % model)
def test_update_printers_status_search_domain(self, cups):
""" It should use specific domain for search """
with mock.patch.object(self.Model, 'search') as search:
expect = [('id', '>', 0)]
self.Model.update_printers_status(expect)
search.assert_called_once_with(expect)
@mock.patch('%s.cups' % model)
def test_update_printers_status_update_printer(self, cups):
""" It should update from CUPS when printer identified """
with mock.patch.object(self.Model, 'search') as search:
printer_mk = mock.MagicMock()
search.return_value = [printer_mk]
self.Model.update_printers_status()
printer_mk.update_from_cups.assert_called_once_with(
cups.Connection(),
cups.Connection().getPrinters().get(),
)
@mock.patch('%s.cups' % model)
def test_update_printers_status_update_unavailable(self, cups):
""" It should update status when printer is unavailable """
rec_id = self.new_record()
cups.Connection().getPrinters().get.return_value = False
self.Model.update_printers_status()
self.assertEqual(
'unavailable', rec_id.status,
)

View File

@@ -0,0 +1,105 @@
# -*- coding: utf-8 -*-
# Copyright 2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import mock
from openerp.tests.common import TransactionCase
from openerp.exceptions import UserError
from openerp.addons.base_report_to_printer.models.printing_printer import (
CUPS_HOST,
CUPS_PORT,
)
model = '%s.%s' % ('openerp.addons.base_report_to_printer.wizards',
'printing_printer_update_wizard')
class StopTest(Exception):
pass
class TestPrintingPrinterWizard(TransactionCase):
def setUp(self):
super(TestPrintingPrinterWizard, self).setUp()
self.Model = self.env['printing.printer.update.wizard']
self.printer_vals = {
'printer-info': 'Info',
'printer-make-and-model': 'Make and Model',
'printer-location': "location",
'device-uri': 'URI',
}
def _record_vals(self, sys_name='sys_name'):
return {
'name': self.printer_vals['printer-info'],
'system_name': sys_name,
'model': self.printer_vals['printer-make-and-model'],
'location': self.printer_vals['printer-location'],
'uri': self.printer_vals['device-uri'],
}
@mock.patch('%s.cups' % model)
def test_action_ok_inits_connection(self, cups):
""" It should initialize CUPS connection """
try:
self.Model.action_ok()
except:
pass
cups.Connection.assert_called_once_with(
CUPS_HOST, CUPS_PORT,
)
@mock.patch('%s.cups' % model)
def test_action_ok_gets_printers(self, cups):
""" It should get printers from CUPS """
cups.Connection().getPrinters.return_value = {
'sys_name': self.printer_vals,
}
self.Model.action_ok()
cups.Connection().getPrinters.assert_called_once_with()
@mock.patch('%s.cups' % model)
def test_action_ok_raises_warning_on_error(self, cups):
""" It should raise Warning on any error """
cups.Connection.side_effect = StopTest
with self.assertRaises(UserError):
self.Model.action_ok()
@mock.patch('%s.cups' % model)
def test_action_ok_creates_new_printer(self, cups):
""" It should create new printer w/ proper vals """
cups.Connection().getPrinters.return_value = {
'sys_name': self.printer_vals,
}
self.Model.action_ok()
rec_id = self.env['printing.printer'].search([
('system_name', '=', 'sys_name')
],
limit=1,
)
self.assertTrue(rec_id)
for key, val in self._record_vals().iteritems():
self.assertEqual(
val, getattr(rec_id, key),
)
@mock.patch('%s.cups' % model)
def test_action_ok_skips_existing_printer(self, cups):
""" It should not recreate existing printers """
cups.Connection().getPrinters.return_value = {
'sys_name': self.printer_vals,
}
self.env['printing.printer'].create(
self._record_vals()
)
self.Model.action_ok()
res_ids = self.env['printing.printer'].search([
('system_name', '=', 'sys_name')
])
self.assertEqual(
1, len(res_ids),
)

View File

@@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
# Copyright 2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp.tests.common import TransactionCase
class StopTest(Exception):
pass
class TestReport(TransactionCase):
def setUp(self):
super(TestReport, self).setUp()
self.Model = self.env['report']
self.report_vals = {}
def new_record(self):
return self.Model.create(self.report_vals)
def test_can_print_report_context_skip(self):
""" It should return False based on context """
rec_id = self.new_record().with_context(
must_skip_send_to_printer=True
)
res = rec_id._can_print_report(
{'action': 'server'}, True, True
)
self.assertFalse(res)
def test_can_print_report_true(self):
""" It should return True when server print allowed """
res = self.new_record()._can_print_report(
{'action': 'server'}, True, True
)
self.assertTrue(res)
def test_can_print_report_false(self):
""" It should return False when server print not allowed """
res = self.new_record()._can_print_report(
{'action': 'server'}, True, False
)
self.assertFalse(res)

View File

@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# Copyright 2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp.tests.common import TransactionCase
class TestResUsers(TransactionCase):
def setUp(self):
super(TestResUsers, self).setUp()
self.user_vals = {'name': 'Test',
'login': 'login',
}
def new_record(self):
return self.env['res.users'].create(self.user_vals)
def test_available_action_types_excludes_user_default(self):
""" It should not contain `user_default` in avail actions """
self.user_vals['printing_action'] = 'user_default'
with self.assertRaises(ValueError):
self.new_record()
def test_available_action_types_includes_something_else(self):
""" It should still contain other valid keys """
self.user_vals['printing_action'] = 'server'
self.assertTrue(self.new_record())

View File

@@ -1,43 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2007 Ferran Pegueroles <ferran@pegueroles.com>
# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com>
# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import models, fields
from .printing import _available_action_types
class res_users(models.Model):
"""
Users
"""
_name = 'res.users'
_inherit = 'res.users'
def _user_available_action_types(self):
return [(code, string) for code, string
in _available_action_types(self)
if code != 'user_default']
printing_action = fields.Selection(_user_available_action_types)
printing_printer_id = fields.Many2one(comodel_name='printing.printer',
string='Default Printer')

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="assets_backend" name="base_report_to_printer assets" inherit_id="report.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/base_report_to_printer/static/src/js/qweb_action_manager.js" />
</xpath>
</template>
</odoo>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0"?>
<odoo>
<record model="ir.ui.view" id="act_report_xml_view">
<field name="name">ir.actions.report.xml.printing</field>
<field name="model">ir.actions.report.xml</field>
<field name="inherit_id" ref="base.act_report_xml_view" />
<field name="arch" type="xml">
<xpath expr="//page[@name='security']">
<page string="Print">
<group>
<field name="property_printing_action_id"/>
<field name="printing_printer_id"/>
</group>
<separator string="Specific actions per user"/>
<field name="printing_action_ids"/>
</page>
</xpath>
</field>
</record>
</odoo>

View File

@@ -0,0 +1,81 @@
<?xml version="1.0"?>
<odoo>
<menuitem name="Printing"
id="printing_menu"
parent="base.menu_administration"
groups="printing_group_manager"
/>
<record model="ir.ui.view" id="printing_printer_view_form">
<field name="name">printing.printer.form</field>
<field name="model">printing.printer</field>
<field name="arch" type="xml">
<form string="Printers">
<sheet>
<div class="oe_title">
<h1>
<label for="name"/>
<field name="name"/>
</h1>
</div>
<group>
<field name="system_name"/>
</group>
<group col="3" colspan="4">
<field name="default"/>
<button name="set_default" string="Set Default" type="object"/>
</group>
<group>
<field name="uri"/>
<field name="model"/>
<field name="location"/>
<field name="status"/>
<field name="status_message"/>
</group>
</sheet>
</form>
</field>
</record>
<record model="ir.ui.view" id="printing_printer_view_tree">
<field name="name">printing.printer.tree</field>
<field name="model">printing.printer</field>
<field name="arch" type="xml">
<tree string="Printers" colors="green:status=='available'; orange:status=='printing'; red:1;">
<field name="default"/>
<field name="name"/>
<field name="system_name"/>
<field name="status"/>
</tree>
</field>
</record>
<record model="ir.ui.view" id="printing_printer_view_search">
<field name="name">printing.printer.search</field>
<field name="model">printing.printer</field>
<field name="arch" type="xml">
<search string="Printers">
<field name="name"/>
<field name="system_name"/>
<field name="location"/>
<field name="status"/>
</search>
</field>
</record>
<record model="ir.actions.act_window" id="printing_printer_action">
<field name="name">Show Printers</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">printing.printer</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="auto_refresh">20</field>
</record>
<menuitem name="Printers"
id="printing_printer_menu"
parent="printing_menu"
action="printing_printer_action"/>
</odoo>

View File

@@ -0,0 +1,34 @@
<?xml version="1.0"?>
<odoo>
<record model="ir.ui.view" id="printing_report_xml_action_view_form">
<field name="name">printing.report.xml.action.form</field>
<field name="model">printing.report.xml.action</field>
<field name="arch" type="xml">
<form string="Report Printing Actions">
<group col="2">
<field name="user_id"/>
<field name="action"/>
<field name="printer_id" select="1"/>
</group>
</form>
</field>
</record>
<record model="ir.ui.view" id="printing_report_xml_action_view_tree">
<field name="name">printing.report.xml.action.tree</field>
<field name="model">printing.report.xml.action</field>
<field name="arch" type="xml">
<tree string="Report Printing Actions">
<field name="user_id"/>
<field name="action" />
<field name="printer_id" />
</tree>
</field>
</record>
<!-- Add a shorcut to "Actions/Report" in the Printing menu -->
<menuitem id="printing_report_xml_action_menu"
parent="printing_menu"
action="base.ir_action_report_xml"/>
</odoo>

View File

@@ -0,0 +1,32 @@
<?xml version="1.0"?>
<odoo>
<record model="ir.ui.view" id="view_users_form">
<field name="name">res.users.form.printing.preferences</field>
<field name="model">res.users</field>
<field name="inherit_id" ref="base.view_users_form" />
<field name="arch" type="xml">
<page string="Preferences">
<group name="printing">
<field name="printing_action"/>
<field name="printing_printer_id"/>
</group>
</page>
</field>
</record>
<record model="ir.ui.view" id="view_users_form_simple_modif">
<field name="name">res.users.form.printing</field>
<field name="model">res.users</field>
<field name="inherit_id" ref="base.view_users_form_simple_modif" />
<field name="arch" type="xml">
<footer position="before">
<group string="Printing" name="printing">
<field name="printing_action"/>
<field name="printing_printer_id"/>
</group>
</footer>
</field>
</record>
</odoo>

View File

@@ -1,22 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com>
# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import update_printers

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import printing_printer_update_wizard

View File

@@ -1,48 +1,33 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com>
# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
# Copyright (C) 2014 Camptocamp SA (<http://www.camptocamp.com>)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com>
# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
# Copyright (C) 2014 Camptocamp (<http://www.camptocamp.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging
_logger = logging.getLogger(__name__)
from openerp.exceptions import UserError
from openerp import models, api, _
from ..models.printing_printer import CUPS_HOST, CUPS_PORT
try:
import cups
except ImportError:
_logger = logging.getLogger(__name__)
_logger.debug('Cannot `import cups`.')
from openerp.exceptions import Warning
from openerp import models, api, _
from openerp.tools.config import config
CUPS_HOST = config.get('cups_host', 'localhost')
CUPS_PORT = int(config.get('cups_port', 631))
_logger = logging.getLogger(__name__)
class PrintingPrinterUpdateWizard(models.TransientModel):
_name = 'printing.printer.update.wizard'
_description = 'Printing Printer Update Wizard'
@api.multi
@api.model
def action_ok(self):
self.ensure_one()
# Update Printers
printer_obj = self.env['printing.printer']
try:
@@ -51,7 +36,7 @@ class PrintingPrinterUpdateWizard(models.TransientModel):
printers = connection.getPrinters()
_logger.info('Printers found: %s' % ','.join(printers.keys()))
except:
raise Warning(
raise UserError(
_('Could not get the list of printers from the CUPS server '
'(%s:%s)') % (CUPS_HOST, CUPS_PORT))
@@ -71,7 +56,7 @@ class PrintingPrinterUpdateWizard(models.TransientModel):
'location': printer.get('printer-location', False),
'uri': printer.get('device-uri', False),
}
self.env['printing.printer'].create(values)
printer_obj.create(values)
_logger.info(
'Created new printer %s with URI %s'
% (values['name'], values['uri']))

View File

@@ -23,6 +23,6 @@
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<menuitem action="action_printer_update_wizard" id="menu_printer_update_wizard" parent="menu_printing_main"/>
<menuitem action="action_printer_update_wizard" id="menu_printer_update_wizard" parent="printing_menu"/>
</data>
</openerp>