[MIG] base_report_to_printer: Migrate to v11.0

This commit is contained in:
Sylvain GARANCHER
2017-10-03 17:14:08 +02:00
parent e10d4ccf0e
commit 49062b590e
21 changed files with 128 additions and 445 deletions

View File

@@ -14,17 +14,17 @@
" LasLabs, Odoo Community Association (OCA)",
'website': 'http://www.agilebg.com',
'license': 'AGPL-3',
"depends": ['report'],
"depends": ['web'],
'data': [
'data/printing_data.xml',
'security/security.xml',
'views/assets.xml',
'views/printing_printer_view.xml',
'views/printing_printer.xml',
'views/printing_server.xml',
'views/printing_job.xml',
'views/printing_report_view.xml',
'views/res_users_view.xml',
'views/ir_actions_report_xml_view.xml',
'views/printing_report.xml',
'views/res_users.xml',
'views/ir_actions_report.xml',
'wizards/printing_printer_update_wizard_view.xml',
],
'installable': True,

View File

@@ -13,7 +13,7 @@
<!-- 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="fields_id" search="[('model', '=', 'ir.actions.report'), ('name', '=', 'property_printing_action_id')]"/>
<field name="value" eval="'printing.action,' + str(printing_action_2)"/>
</record>
@@ -25,7 +25,7 @@
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field eval="False" name="doall"/>
<field eval="'printing.server'" name="model"/>
<field name="model_id" ref="base_report_to_printer.model_printing_server"/>
<field eval="'action_update_jobs'" name="function"/>
<field eval="'()'" name="args"/>
</record>

View File

@@ -1,302 +0,0 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * base_report_to_printer
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-01-21 14:44+0000\n"
"PO-Revision-Date: 2015-01-21 14:44+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: base_report_to_printer
#: field:ir.actions.report.xml,property_printing_action:0
#: field:printing.report.xml.action,action:0
msgid "Action"
msgstr ""
#. module: base_report_to_printer
#: field:ir.actions.report.xml,printing_action_ids:0
msgid "Actions"
msgstr ""
#. module: base_report_to_printer
#: selection:printing.printer,status:0
msgid "Available"
msgstr ""
#. module: base_report_to_printer
#: view:printing.printer.update.wizard:base_report_to_printer.printer_update_wizard
msgid "Cancel"
msgstr ""
#. module: base_report_to_printer
#: code:addons/base_report_to_printer/wizard/update_printers.py:50
#, python-format
msgid "Could not get the list of printers from the CUPS server (%s:%s)"
msgstr ""
#. module: base_report_to_printer
#: field:printing.action,create_uid:0
#: field:printing.printer,create_uid:0
#: field:printing.printer.update.wizard,create_uid:0
#: field:printing.report.xml.action,create_uid:0
msgid "Created by"
msgstr ""
#. module: base_report_to_printer
#: field:printing.action,create_date:0
#: field:printing.printer,create_date:0
#: field:printing.printer.update.wizard,create_date:0
#: field:printing.report.xml.action,create_date:0
msgid "Created on"
msgstr ""
#. module: base_report_to_printer
#: field:printing.printer,default:0
msgid "Default"
msgstr ""
#. module: base_report_to_printer
#: field:res.users,printing_printer_id:0
msgid "Default Printer"
msgstr ""
#. module: base_report_to_printer
#. openerp-web
#: code:addons/base_report_to_printer/static/src/js/qwebactionmanager.js:27
#, python-format
msgid "Document sent to the printer "
msgstr ""
#. module: base_report_to_printer
#: selection:printing.printer,status:0
msgid "Error"
msgstr ""
#. module: base_report_to_printer
#. openerp-web
#: code:addons/base_report_to_printer/static/src/js/qwebactionmanager.js:30
#, python-format
msgid "Error when sending the document to the printer "
msgstr ""
#. module: base_report_to_printer
#: code:addons/base_report_to_printer/printing.py:140
#, python-format
msgid "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."
msgstr ""
#. module: base_report_to_printer
#: field:printing.action,id:0
#: field:printing.printer,id:0
#: field:printing.printer.update.wizard,id:0
#: field:printing.report.xml.action,id:0
msgid "ID"
msgstr ""
#. module: base_report_to_printer
#: field:printing.action,write_uid:0
#: field:printing.printer,write_uid:0
#: field:printing.printer.update.wizard,write_uid:0
#: field:printing.report.xml.action,write_uid:0
msgid "Last Updated by"
msgstr ""
#. module: base_report_to_printer
#: field:printing.action,write_date:0
#: field:printing.printer,write_date:0
#: field:printing.printer.update.wizard,write_date:0
#: field:printing.report.xml.action,write_date:0
msgid "Last Updated on"
msgstr ""
#. module: base_report_to_printer
#: field:printing.printer,location:0
msgid "Location"
msgstr ""
#. module: base_report_to_printer
#: field:printing.printer,model:0
msgid "Model"
msgstr ""
#. module: base_report_to_printer
#: field:printing.action,name:0
#: field:printing.printer,name:0
msgid "Name"
msgstr ""
#. module: base_report_to_printer
#: code:addons/base_report_to_printer/ir_report.py:114
#, python-format
msgid "No printer configured to print this report."
msgstr ""
#. module: base_report_to_printer
#: view:res.users:base_report_to_printer.view_printing_users_form
msgid "Preferences"
msgstr ""
#. module: base_report_to_printer
#: view:ir.actions.report.xml:base_report_to_printer.action_report_xml_form
msgid "Print"
msgstr ""
#. module: base_report_to_printer
#: model:ir.model,name:base_report_to_printer.model_printing_action
msgid "Print Job Action"
msgstr ""
#. module: base_report_to_printer
#: field:ir.actions.report.xml,printing_printer_id:0
#: model:ir.model,name:base_report_to_printer.model_printing_printer
#: field:printing.report.xml.action,printer_id:0
msgid "Printer"
msgstr ""
#. 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
msgid "Printers"
msgstr ""
#. module: base_report_to_printer
#: model:ir.ui.menu,name:base_report_to_printer.menu_printing_main
#: selection:printing.printer,status:0
#: view:res.users:base_report_to_printer.view_printing_users_prefs
msgid "Printing"
msgstr ""
#. module: base_report_to_printer
#: model:res.groups,name:base_report_to_printer.res_groups_printingprintoperator0
msgid "Printing / Print Operator"
msgstr ""
#. module: base_report_to_printer
#: field:res.users,printing_action:0
msgid "Printing action"
msgstr ""
#. 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
#: model:ir.model,name:base_report_to_printer.model_report
#: field:printing.report.xml.action,report_id:0
#, python-format
msgid "Report"
msgstr ""
#. 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
msgid "Report Printing Actions"
msgstr ""
#. module: base_report_to_printer
#: model:ir.ui.menu,name:base_report_to_printer.menu_printing_reports
msgid "Reports"
msgstr ""
#. module: base_report_to_printer
#: view:ir.actions.report.xml:base_report_to_printer.action_report_xml_form
msgid "Security"
msgstr ""
#. module: base_report_to_printer
#: selection:printing.printer,status:0
msgid "Server Error"
msgstr ""
#. module: base_report_to_printer
#: view:printing.printer:base_report_to_printer.view_printing_printer_form
msgid "Set Default"
msgstr ""
#. module: base_report_to_printer
#: model:ir.actions.act_window,name:base_report_to_printer.action_printing_printer_form
msgid "Show Printers"
msgstr ""
#. module: base_report_to_printer
#: view:ir.actions.report.xml:base_report_to_printer.action_report_xml_form
msgid "Specific actions per user"
msgstr ""
#. module: base_report_to_printer
#: field:printing.printer,status:0
msgid "Status"
msgstr ""
#. module: base_report_to_printer
#: field:printing.printer,status_message:0
msgid "Status message"
msgstr ""
#. module: base_report_to_printer
#: field:printing.printer,system_name:0
msgid "System name"
msgstr ""
#. module: base_report_to_printer
#: help:ir.actions.report.xml,printing_action_ids:0
msgid "This field allows configuring action and printer on a per user basis"
msgstr ""
#. module: base_report_to_printer
#: view:printing.printer.update.wizard:base_report_to_printer.printer_update_wizard
msgid "This process will create all missing printers from the current CUPS server."
msgstr ""
#. module: base_report_to_printer
#: field:printing.action,type:0
msgid "Type"
msgstr ""
#. module: base_report_to_printer
#: field:printing.printer,uri:0
msgid "URI"
msgstr ""
#. module: base_report_to_printer
#: selection:printing.printer,status:0
msgid "Unavailable"
msgstr ""
#. module: base_report_to_printer
#: selection:printing.printer,status:0
msgid "Unknown"
msgstr ""
#. module: base_report_to_printer
#: model:ir.actions.act_window,name:base_report_to_printer.action_printer_update_wizard
#: model:ir.ui.menu,name:base_report_to_printer.menu_printer_update_wizard
#: view:printing.printer.update.wizard:base_report_to_printer.printer_update_wizard
msgid "Update Printers from CUPS"
msgstr ""
#. module: base_report_to_printer
#: field:printing.report.xml.action,user_id:0
msgid "User"
msgstr ""
#. module: base_report_to_printer
#: model:ir.model,name:base_report_to_printer.model_res_users
msgid "Users"
msgstr ""
#. module: base_report_to_printer
#: view:printing.printer.update.wizard:base_report_to_printer.printer_update_wizard
msgid "or"
msgstr ""

View File

@@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-
from . import ir_actions_report_xml
from . import ir_actions_report
from . import printing_action
from . import printing_job
from . import printing_printer
from . import printing_server
from . import printing_report_xml_action
from . import report
from . import res_users

View File

@@ -6,15 +6,11 @@
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, fields, api
from odoo import api, exceptions, fields, models, _
class IrActionsReportXml(models.Model):
"""
Reports
"""
_inherit = 'ir.actions.report.xml'
class IrActionsReport(models.Model):
_inherit = 'ir.actions.report'
property_printing_action_id = fields.Many2one(
comodel_name='printing.action',
@@ -39,11 +35,10 @@ class IrActionsReportXml(models.Model):
Called from js
"""
report_obj = self.env['report']
report = report_obj._get_report_from_name(report_name)
report = self._get_report_from_name(report_name)
if not report:
return {}
result = report.behaviour()[report.id]
result = report.behaviour()[report]
serializable_result = {
'action': result['action'],
'printer_name': result['printer'].name,
@@ -79,18 +74,64 @@ class IrActionsReportXml(models.Model):
printer = report.printing_printer_id
# Retrieve report-user specific values
print_action = printing_act_obj.search(
[('report_id', '=', report.id),
('user_id', '=', self.env.uid),
('action', '!=', 'user_default')],
limit=1)
print_action = printing_act_obj.search([
('report_id', '=', report.id),
('user_id', '=', self.env.uid),
('action', '!=', 'user_default'),
], limit=1)
if print_action:
user_action = print_action.behaviour()
action = user_action['action']
if user_action['printer']:
printer = user_action['printer']
result[report.id] = {'action': action,
'printer': printer,
}
result[report] = {
'action': action,
'printer': printer,
}
return result
@api.multi
def print_document(self, record_ids, data=None):
""" Print a document, do not return the document file """
document = self.with_context(must_skip_send_to_printer=True).render_qweb_pdf(
record_ids, data=data)
behaviour = self.behaviour()[self]
printer = behaviour['printer']
if not printer:
raise exceptions.Warning(
_('No printer configured to print this report.')
)
return printer.print_document(self, document, self.report_type)
@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 `render_qweb_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.model
def render_qweb_pdf(self, docids, data=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(IrActionsReport, self).render_qweb_pdf(
docids, data=data)
behaviour = self.behaviour()[self]
printer = behaviour['printer']
can_print_report = self._can_print_report(behaviour, printer, document)
if can_print_report:
printer.print_document(self, document, self.report_type)
return document

View File

@@ -13,7 +13,7 @@ class PrintingReportXmlAction(models.Model):
_name = 'printing.report.xml.action'
_description = 'Printing Report Printing Actions'
report_id = fields.Many2one(comodel_name='ir.actions.report.xml',
report_id = fields.Many2one(comodel_name='ir.actions.report',
string='Report',
required=True,
ondelete='cascade')

View File

@@ -78,7 +78,7 @@ class PrintingServer(models.Model):
for printer in server.printer_ids
])
updated_printers = []
for name, printer_info in printers.iteritems():
for name, printer_info in printers.items():
printer = self.env['printing.printer']
if name in existing_printers:
printer = existing_printers[name]
@@ -182,21 +182,21 @@ class PrintingServer(models.Model):
'active': True,
'job_id_cups': cups_job_id,
'job_media_progress': job_data.get(
'job-media-progress', 0),
'job-media-progress', False),
'job_state': mapping.get(
job_data.get('job-state'), 'unknown'),
'job_state_reason': job_data.get('job-state-reasons', ''),
'time_at_creation': fields.Datetime.to_string(
datetime.fromtimestamp(job_data.get(
'time-at-creation', 0))),
'time-at-creation', False))),
'time_at_processing': job_data.get(
'time-at-processing', 0) and fields.Datetime.to_string(
'time-at-processing', False) and fields.Datetime.to_string(
datetime.fromtimestamp(job_data.get(
'time-at-processing', 0))),
'time-at-processing', False))),
'time_at_completed': job_data.get(
'time-at-completed', 0) and fields.Datetime.to_string(
'time-at-completed', False) and fields.Datetime.to_string(
datetime.fromtimestamp(job_data.get(
'time-at-completed', 0))),
'time-at-completed', False))),
}
# Search for the printer in Odoo

View File

@@ -1,56 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2014 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, exceptions, _, api
class Report(models.Model):
_inherit = 'report'
@api.model
def print_document(self, record_ids, report_name, html=None, data=None):
""" Print a document, do not return the document file """
document = self.with_context(must_skip_send_to_printer=True).get_pdf(
record_ids, 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.')
)
return printer.print_document(report, document, report.report_type)
@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.model
def get_pdf(self, docids, report_name, html=None, data=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(
docids, report_name, html=html, data=data)
report = self._get_report_from_name(report_name)
behaviour = report.behaviour()[report.id]
printer = behaviour['printer']
can_print_report = self._can_print_report(behaviour, printer, document)
if can_print_report:
printer.print_document(report, document, report.report_type)
return document

View File

@@ -7,7 +7,7 @@ odoo.define('base_report_to_printer.print', function(require) {
var Model = require('web.Model');
ActionManager.include({
ir_actions_report_xml: function(action, options) {
ir_actions_report: function(action, options) {
action = _.clone(action);
var _t = core._t;
var self = this;
@@ -15,7 +15,7 @@ odoo.define('base_report_to_printer.print', function(require) {
if ('report_type' in action && action.report_type === 'qweb-pdf') {
framework.blockUI();
new Model('ir.actions.report.xml')
new Model('ir.actions.report')
.call('print_action_for_report_name', [action.report_name])
.then(function(print_action){
if (print_action && print_action.action === 'server') {

View File

@@ -7,6 +7,6 @@ from . import test_printing_printer
from . import test_printing_server
from . import test_report
from . import test_res_users
from . import test_ir_actions_report_xml
from . import test_ir_actions_report
from . import test_printing_printer_wizard
from . import test_printing_report_xml_action

View File

@@ -12,10 +12,10 @@ class TestIrActionsReportXml(TransactionCase):
def setUp(self):
super(TestIrActionsReportXml, self).setUp()
self.Model = self.env['ir.actions.report.xml']
self.Model = self.env['ir.actions.report']
self.vals = {}
self.report = self.env['ir.actions.report.xml'].search([], limit=1)
self.report = self.env['ir.actions.report'].search([], limit=1)
self.server = self.env['printing.server'].create({})
def new_action(self):
@@ -46,18 +46,18 @@ class TestIrActionsReportXml(TransactionCase):
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:
with mock.patch.object(self.Model, '_get_report_from_name') as mk:
expect = 'test'
self.Model.print_action_for_report_name(expect)
mk['report']._get_report_from_name.assert_called_once_with(
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.object(self.Model, 'env') as mk:
with mock.patch.object(self.Model, '_get_report_from_name') as mk:
expect = 'test'
mk['report']._get_report_from_name.return_value = False
mk.return_value = False
res = self.Model.print_action_for_report_name(expect)
self.assertDictEqual(
{}, res,
@@ -65,11 +65,9 @@ class TestIrActionsReportXml(TransactionCase):
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:
with mock.patch.object(self.Model, '_get_report_from_name') 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
]
behaviour = mk().behaviour()[mk()]
expect = {
'action': behaviour['action'],
'printer_name': behaviour['printer'].name,
@@ -87,7 +85,7 @@ class TestIrActionsReportXml(TransactionCase):
report.property_printing_action_id = False
report.printing_printer_id = False
self.assertEqual(report.behaviour(), {
report.id: {
report: {
'action': 'client',
'printer': self.env['printing.printer'],
},
@@ -99,7 +97,7 @@ class TestIrActionsReportXml(TransactionCase):
self.env.user.printing_action = 'client'
self.env.user.printing_printer_id = self.new_printer()
self.assertEqual(report.behaviour(), {
report.id: {
report: {
'action': 'client',
'printer': self.env.user.printing_printer_id,
},
@@ -112,7 +110,7 @@ class TestIrActionsReportXml(TransactionCase):
report.property_printing_action_id = self.new_action()
report.printing_printer_id = self.new_printer()
self.assertEqual(report.behaviour(), {
report.id: {
report: {
'action': report.property_printing_action_id.action_type,
'printer': report.printing_printer_id,
},
@@ -124,7 +122,7 @@ class TestIrActionsReportXml(TransactionCase):
self.env.user.printing_action = 'client'
report.property_printing_action_id.action_type = 'user_default'
self.assertEqual(report.behaviour(), {
report.id: {
report: {
'action': 'client',
'printer': report.printing_printer_id,
},
@@ -140,7 +138,7 @@ class TestIrActionsReportXml(TransactionCase):
('id', '!=', self.env.user.id),
], limit=1)
self.assertEqual(report.behaviour(), {
report.id: {
report: {
'action': 'client',
'printer': report.printing_printer_id,
},
@@ -153,11 +151,11 @@ class TestIrActionsReportXml(TransactionCase):
self.env.user.printing_action = 'client'
printing_action = self.new_printing_action()
printing_action.user_id = self.env.user
printing_action.report_id = self.env['ir.actions.report.xml'].search([
printing_action.report_id = self.env['ir.actions.report'].search([
('id', '!=', report.id),
], limit=1)
self.assertEqual(report.behaviour(), {
report.id: {
report: {
'action': 'client',
'printer': report.printing_printer_id,
},
@@ -172,7 +170,7 @@ class TestIrActionsReportXml(TransactionCase):
printing_action.user_id = self.env.user
printing_action.report_id = report
self.assertEqual(report.behaviour(), {
report.id: {
report: {
'action': printing_action.action,
'printer': report.printing_printer_id,
},
@@ -186,7 +184,7 @@ class TestIrActionsReportXml(TransactionCase):
printing_action.user_id = self.env.user
printing_action.printer_id = self.new_printer()
self.assertEqual(report.behaviour(), {
report.id: {
report: {
'action': printing_action.action,
'printer': printing_action.printer_id,
},
@@ -201,7 +199,7 @@ class TestIrActionsReportXml(TransactionCase):
printing_action.user_id = self.env.user
printing_action.action = 'user_default'
self.assertEqual(report.behaviour(), {
report.id: {
report: {
'action': 'client',
'printer': report.printing_printer_id,
},

View File

@@ -53,7 +53,7 @@ class TestPrintingJob(TransactionCase):
job = self.new_job(printer, {'job_id_cups': 2})
job.action_cancel()
cups.Connection.side_effect = None
self.assertEquals(cups.Connection().cancelJob.call_count, 0)
self.assertEqual(cups.Connection().cancelJob.call_count, 0)
@mock.patch('%s.cups' % model)
def test_cancel_job(self, cups):

View File

@@ -37,13 +37,13 @@ class TestPrintingPrinter(TransactionCase):
def test_printing_options(self):
""" It should generate the right options dictionnary """
self.assertEquals(self.Model.print_options('report', 'raw'), {
self.assertEqual(self.Model.print_options('report', 'raw'), {
'raw': 'True',
})
self.assertEquals(self.Model.print_options('report', 'pdf', 2), {
self.assertEqual(self.Model.print_options('report', 'pdf', 2), {
'copies': '2',
})
self.assertEquals(self.Model.print_options('report', 'raw', 2), {
self.assertEqual(self.Model.print_options('report', 'raw', 2), {
'raw': 'True',
'copies': '2',
})
@@ -55,7 +55,7 @@ class TestPrintingPrinter(TransactionCase):
with mock.patch('%s.mkstemp' % model) as mkstemp:
mkstemp.return_value = fd, file_name
printer = self.new_record()
printer.print_document('report_name', 'content to print', 'pdf')
printer.print_document('report_name', b'content to print', 'pdf')
cups.Connection().printFile.assert_called_once_with(
printer.system_name,
file_name,
@@ -72,7 +72,7 @@ class TestPrintingPrinter(TransactionCase):
printer = self.new_record()
with self.assertRaises(UserError):
printer.print_document(
'report_name', 'content to print', 'pdf')
'report_name', b'content to print', 'pdf')
@mock.patch('%s.cups' % server_model)
def test_print_file(self, cups):
@@ -105,7 +105,7 @@ class TestPrintingPrinter(TransactionCase):
self.assertTrue(other_printer.default)
# Check that calling the method on an empty recordset does nothing
self.Model.set_default()
self.assertEquals(other_printer, self.Model.get_default())
self.assertEqual(other_printer, self.Model.get_default())
@mock.patch('%s.cups' % server_model)
def test_cancel_all_jobs(self, cups):

View File

@@ -75,7 +75,7 @@ class TestPrintingPrinterWizard(TransactionCase):
limit=1,
)
self.assertTrue(rec_id)
for key, val in self._record_vals().iteritems():
for key, val in self._record_vals().items():
if rec_id._fields[key].type == 'many2one':
val = self.env[rec_id._fields[key].comodel_name].browse(val)

View File

@@ -11,7 +11,7 @@ class TestPrintingReportXmlAction(TransactionCase):
super(TestPrintingReportXmlAction, self).setUp()
self.Model = self.env['printing.report.xml.action']
self.report = self.env['ir.actions.report.xml'].search([], limit=1)
self.report = self.env['ir.actions.report'].search([], limit=1)
self.server = self.env['printing.server'].create({})
self.report_vals = {

View File

@@ -15,9 +15,13 @@ class TestReport(HttpCase):
def setUp(self):
super(TestReport, self).setUp()
self.Model = self.env['report']
self.Model = self.env['ir.actions.report']
self.server = self.env['printing.server'].create({})
self.report_vals = {}
self.report_vals = {
'name': 'Test Report',
'model': 'ir.actions.report',
'report_name': 'Test Report',
}
def new_record(self):
return self.Model.create(self.report_vals)
@@ -59,39 +63,38 @@ class TestReport(HttpCase):
)
self.assertFalse(res)
def test_get_pdf_not_printable(self):
def test_render_qweb_pdf_not_printable(self):
""" It should print the report, only if it is printable
"""
with mock.patch('odoo.addons.base_report_to_printer.models.'
'printing_printer.PrintingPrinter.'
'print_document') as print_document:
report = self.env['ir.actions.report.xml'].search([
report = self.env['ir.actions.report'].search([
('report_type', '=', 'qweb-pdf'),
], limit=1)
records = self.env[report.model].search([], limit=5)
self.env['report'].get_pdf(records.ids, report.report_name)
report.render_qweb_pdf(records.ids)
print_document.assert_not_called()
def test_get_pdf_printable(self):
def test_render_qweb_pdf_printable(self):
""" It should print the report, only if it is printable
"""
with mock.patch('odoo.addons.base_report_to_printer.models.'
'printing_printer.PrintingPrinter.'
'print_document') as print_document:
report = self.env['ir.actions.report.xml'].search([
report = self.env['ir.actions.report'].search([
('report_type', '=', 'qweb-pdf'),
], limit=1)
report.property_printing_action_id.action_type = 'server'
report.printing_printer_id = self.new_printer()
records = self.env[report.model].search([], limit=5)
document = self.env['report'].get_pdf(
records.ids, report.report_name)
document = report.render_qweb_pdf(records.ids)
print_document.assert_called_once_with(
report, document, report.report_type)
def test_print_document_not_printable(self):
""" It should print the report, regardless of the defined behaviour """
report = self.env['ir.actions.report.xml'].search([
report = self.env['ir.actions.report'].search([
('report_type', '=', 'qweb-pdf'),
], limit=1)
report.printing_printer_id = self.new_printer()
@@ -100,12 +103,12 @@ class TestReport(HttpCase):
with mock.patch('odoo.addons.base_report_to_printer.models.'
'printing_printer.PrintingPrinter.'
'print_document') as print_document:
self.env['report'].print_document(records.ids, report.report_name)
report.print_document(records.ids)
print_document.assert_called_once()
def test_print_document_printable(self):
""" It should print the report, regardless of the defined behaviour """
report = self.env['ir.actions.report.xml'].search([
report = self.env['ir.actions.report'].search([
('report_type', '=', 'qweb-pdf'),
], limit=1)
report.property_printing_action_id.action_type = 'server'
@@ -115,15 +118,15 @@ class TestReport(HttpCase):
with mock.patch('odoo.addons.base_report_to_printer.models.'
'printing_printer.PrintingPrinter.'
'print_document') as print_document:
self.env['report'].print_document(records.ids, report.report_name)
report.print_document(records.ids)
print_document.assert_called_once()
def test_print_document_no_printer(self):
""" It should raise an error """
report = self.env['ir.actions.report.xml'].search([
report = self.env['ir.actions.report'].search([
('report_type', '=', 'qweb-pdf'),
], limit=1)
records = self.env[report.model].search([], limit=5)
with self.assertRaises(exceptions.UserError):
self.env['report'].print_document(records.ids, report.report_name)
report.print_document(records.ids)

View File

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

View File

@@ -2,8 +2,8 @@
<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="name">ir.actions.report.printing</field>
<field name="model">ir.actions.report</field>
<field name="inherit_id" ref="base.act_report_xml_view" />
<field name="arch" type="xml">
<xpath expr="//page[@name='security']" position="before" >

View File

@@ -27,9 +27,9 @@
</record>
<!-- Add a shorcut to "Actions/Report" in the Printing menu -->
<menuitem id="printing_report_xml_action_menu"
<!--menuitem id="printing_report_xml_action_menu"
sequence="30"
parent="printing_menu"
action="base.ir_action_report_xml"/>
action="base.ir_action_report_xml"/-->
</odoo>