[MIG] base_report_to_printer: Migrate to v11.0

This commit is contained in:
Sylvain GARANCHER
2017-10-03 17:14:08 +02:00
committed by John Herholz
parent 4d5e2b9cd9
commit 321c97435c
23 changed files with 182 additions and 481 deletions

View File

@@ -8,23 +8,23 @@
{ {
'name': "Report to printer", 'name': "Report to printer",
'version': '10.0.1.0.1', 'version': '11.0.1.0.1',
'category': 'Generic Modules/Base', 'category': 'Generic Modules/Base',
'author': "Agile Business Group & Domsense, Pegueroles SCP, NaN," 'author': "Agile Business Group & Domsense, Pegueroles SCP, NaN,"
" LasLabs, Odoo Community Association (OCA)", " LasLabs, Odoo Community Association (OCA)",
'website': 'http://www.agilebg.com', 'website': 'http://www.agilebg.com',
'license': 'AGPL-3', 'license': 'AGPL-3',
"depends": ['report'], "depends": ['web'],
'data': [ 'data': [
'data/printing_data.xml', 'data/printing_data.xml',
'security/security.xml', 'security/security.xml',
'views/assets.xml', 'views/assets.xml',
'views/printing_printer_view.xml', 'views/printing_printer.xml',
'views/printing_server.xml', 'views/printing_server.xml',
'views/printing_job.xml', 'views/printing_job.xml',
'views/printing_report_view.xml', 'views/printing_report.xml',
'views/res_users_view.xml', 'views/res_users.xml',
'views/ir_actions_report_xml_view.xml', 'views/ir_actions_report.xml',
'wizards/printing_printer_update_wizard_view.xml', 'wizards/printing_printer_update_wizard_view.xml',
], ],
'installable': True, 'installable': True,

View File

@@ -13,7 +13,7 @@
<!-- properties --> <!-- properties -->
<record forcecreate="True" id="property_printing_action_id" model="ir.property"> <record forcecreate="True" id="property_printing_action_id" model="ir.property">
<field name="name">property_printing_action_id</field> <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)"/> <field name="value" eval="'printing.action,' + str(printing_action_2)"/>
</record> </record>
@@ -25,7 +25,7 @@
<field name="interval_type">minutes</field> <field name="interval_type">minutes</field>
<field name="numbercall">-1</field> <field name="numbercall">-1</field>
<field eval="False" name="doall"/> <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="'action_update_jobs'" name="function"/>
<field eval="'()'" name="args"/> <field eval="'()'" name="args"/>
</record> </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 -*- # -*- coding: utf-8 -*-
from . import ir_actions_report_xml from . import ir_actions_report
from . import printing_action from . import printing_action
from . import printing_job from . import printing_job
from . import printing_printer from . import printing_printer
from . import printing_server from . import printing_server
from . import printing_report_xml_action from . import printing_report_xml_action
from . import report
from . import res_users from . import res_users

View File

@@ -6,24 +6,20 @@
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>) # Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # 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): class IrActionsReport(models.Model):
""" _inherit = 'ir.actions.report'
Reports
"""
_inherit = 'ir.actions.report.xml'
property_printing_action_id = fields.Many2one( property_printing_action_id = fields.Many2one(
comodel_name='printing.action', comodel_name='printing.action',
string='Action', string='Default Behaviour',
company_dependent=True, company_dependent=True,
) )
printing_printer_id = fields.Many2one( printing_printer_id = fields.Many2one(
comodel_name='printing.printer', comodel_name='printing.printer',
string='Printer' string='Default Printer'
) )
printing_action_ids = fields.One2many( printing_action_ids = fields.One2many(
comodel_name='printing.report.xml.action', comodel_name='printing.report.xml.action',
@@ -39,11 +35,10 @@ class IrActionsReportXml(models.Model):
Called from js Called from js
""" """
report_obj = self.env['report'] report = self._get_report_from_name(report_name)
report = report_obj._get_report_from_name(report_name)
if not report: if not report:
return {} return {}
result = report.behaviour()[report.id] result = report.behaviour()[report]
serializable_result = { serializable_result = {
'action': result['action'], 'action': result['action'],
'printer_name': result['printer'].name, 'printer_name': result['printer'].name,
@@ -79,18 +74,65 @@ class IrActionsReportXml(models.Model):
printer = report.printing_printer_id printer = report.printing_printer_id
# Retrieve report-user specific values # Retrieve report-user specific values
print_action = printing_act_obj.search( print_action = printing_act_obj.search([
[('report_id', '=', report.id), ('report_id', '=', report.id),
('user_id', '=', self.env.uid), ('user_id', '=', self.env.uid),
('action', '!=', 'user_default')], ('action', '!=', 'user_default'),
limit=1) ], limit=1)
if print_action: if print_action:
user_action = print_action.behaviour() user_action = print_action.behaviour()
action = user_action['action'] action = user_action['action']
if user_action['printer']: if user_action['printer']:
printer = user_action['printer'] printer = user_action['printer']
result[report.id] = {'action': action, result[report] = {
'printer': printer, 'action': action,
} 'printer': printer,
}
return result 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, doc_format = 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, doc_format

View File

@@ -126,10 +126,15 @@ class PrintingPrinter(models.Model):
return return
self.ensure_one() self.ensure_one()
default_printers = self.search([('default', '=', True)]) default_printers = self.search([('default', '=', True)])
default_printers.write({'default': False}) default_printers.unset_default()
self.write({'default': True}) self.write({'default': True})
return True return True
@api.multi
def unset_default(self):
self.write({'default': False})
return True
@api.multi @api.multi
def get_default(self): def get_default(self):
return self.search([('default', '=', True)], limit=1) return self.search([('default', '=', True)], limit=1)

View File

@@ -13,7 +13,7 @@ class PrintingReportXmlAction(models.Model):
_name = 'printing.report.xml.action' _name = 'printing.report.xml.action'
_description = 'Printing Report Printing Actions' _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', string='Report',
required=True, required=True,
ondelete='cascade') ondelete='cascade')

View File

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

@@ -26,3 +26,14 @@ class ResUsers(models.Model):
) )
printing_printer_id = fields.Many2one(comodel_name='printing.printer', printing_printer_id = fields.Many2one(comodel_name='printing.printer',
string='Default Printer') string='Default Printer')
@api.model
def _register_hook(self):
self.SELF_WRITEABLE_FIELDS.extend([
'printing_action',
'printing_printer_id',
])
self.SELF_READABLE_FIELDS.extend([
'printing_action',
'printing_printer_id',
])

View File

@@ -7,28 +7,24 @@ odoo.define('base_report_to_printer.print', function(require) {
var Model = require('web.Model'); var Model = require('web.Model');
ActionManager.include({ ActionManager.include({
ir_actions_report_xml: function(action, options) { ir_actions_report: function(action, options) {
action = _.clone(action); action_val = _.clone(action);
var _t = core._t; var _t = core._t;
var self = this; var self = this;
var _super = this._super; var _super = this._super;
if ('report_type' in action && action.report_type === 'qweb-pdf') { if ('report_type' in action_val && action_val.report_type === 'qweb-pdf') {
framework.blockUI(); framework.blockUI();
new Model('ir.actions.report.xml') new Model('ir.actions.report').
.call('print_action_for_report_name', [action.report_name]) call('print_action_for_report_name', [action_val.report_name]).
.then(function(print_action){ then(function(print_action){
if (print_action && print_action.action === 'server') { if (print_action && print_action.action_val === 'server') {
framework.unblockUI(); framework.unblockUI();
new Model('report') new Model('report').
.call('print_document', call('print_document',
[action.context.active_ids, [action_val.context.active_ids, action_val.report_name],
action.report_name, {data: action_val.data || {}, context: action_val.context || {}}).
], then(function(){
{data: action.data || {},
context: action.context || {},
})
.then(function(){
self.do_notify(_t('Report'), self.do_notify(_t('Report'),
_t('Document sent to the printer ') + print_action.printer_name); _t('Document sent to the printer ') + print_action.printer_name);
}).fail(function() { }).fail(function() {
@@ -37,14 +33,12 @@ odoo.define('base_report_to_printer.print', function(require) {
}); });
} else { } else {
return _super.apply(self, [action, options]); return _super.apply(self, [action_val, options]);
} }
}); });
} else { } else {
return _super.apply(self, [action, options]); return _super.apply(self, [action_val, options]);
} }
} }
}); });
}); });

View File

@@ -7,6 +7,6 @@ from . import test_printing_printer
from . import test_printing_server from . import test_printing_server
from . import test_report from . import test_report
from . import test_res_users 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_printer_wizard
from . import test_printing_report_xml_action from . import test_printing_report_xml_action

View File

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

View File

@@ -53,7 +53,7 @@ class TestPrintingJob(TransactionCase):
job = self.new_job(printer, {'job_id_cups': 2}) job = self.new_job(printer, {'job_id_cups': 2})
job.action_cancel() job.action_cancel()
cups.Connection.side_effect = None 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) @mock.patch('%s.cups' % model)
def test_cancel_job(self, cups): def test_cancel_job(self, cups):

View File

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

View File

@@ -75,7 +75,7 @@ class TestPrintingPrinterWizard(TransactionCase):
limit=1, limit=1,
) )
self.assertTrue(rec_id) 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': if rec_id._fields[key].type == 'many2one':
val = self.env[rec_id._fields[key].comodel_name].browse(val) val = self.env[rec_id._fields[key].comodel_name].browse(val)

View File

@@ -11,7 +11,7 @@ class TestPrintingReportXmlAction(TransactionCase):
super(TestPrintingReportXmlAction, self).setUp() super(TestPrintingReportXmlAction, self).setUp()
self.Model = self.env['printing.report.xml.action'] 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.server = self.env['printing.server'].create({})
self.report_vals = { self.report_vals = {

View File

@@ -15,9 +15,13 @@ class TestReport(HttpCase):
def setUp(self): def setUp(self):
super(TestReport, self).setUp() super(TestReport, self).setUp()
self.Model = self.env['report'] self.Model = self.env['ir.actions.report']
self.server = self.env['printing.server'].create({}) 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): def new_record(self):
return self.Model.create(self.report_vals) return self.Model.create(self.report_vals)
@@ -59,39 +63,38 @@ class TestReport(HttpCase):
) )
self.assertFalse(res) 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 """ It should print the report, only if it is printable
""" """
with mock.patch('odoo.addons.base_report_to_printer.models.' with mock.patch('odoo.addons.base_report_to_printer.models.'
'printing_printer.PrintingPrinter.' 'printing_printer.PrintingPrinter.'
'print_document') as print_document: 'print_document') as print_document:
report = self.env['ir.actions.report.xml'].search([ report = self.env['ir.actions.report'].search([
('report_type', '=', 'qweb-pdf'), ('report_type', '=', 'qweb-pdf'),
], limit=1) ], limit=1)
records = self.env[report.model].search([], limit=5) 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() 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 """ It should print the report, only if it is printable
""" """
with mock.patch('odoo.addons.base_report_to_printer.models.' with mock.patch('odoo.addons.base_report_to_printer.models.'
'printing_printer.PrintingPrinter.' 'printing_printer.PrintingPrinter.'
'print_document') as print_document: 'print_document') as print_document:
report = self.env['ir.actions.report.xml'].search([ report = self.env['ir.actions.report'].search([
('report_type', '=', 'qweb-pdf'), ('report_type', '=', 'qweb-pdf'),
], limit=1) ], limit=1)
report.property_printing_action_id.action_type = 'server' report.property_printing_action_id.action_type = 'server'
report.printing_printer_id = self.new_printer() report.printing_printer_id = self.new_printer()
records = self.env[report.model].search([], limit=5) records = self.env[report.model].search([], limit=5)
document = self.env['report'].get_pdf( document, doc_format = report.render_qweb_pdf(records.ids)
records.ids, report.report_name)
print_document.assert_called_once_with( print_document.assert_called_once_with(
report, document, report.report_type) report, document, report.report_type)
def test_print_document_not_printable(self): def test_print_document_not_printable(self):
""" It should print the report, regardless of the defined behaviour """ """ 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'), ('report_type', '=', 'qweb-pdf'),
], limit=1) ], limit=1)
report.printing_printer_id = self.new_printer() report.printing_printer_id = self.new_printer()
@@ -100,12 +103,12 @@ class TestReport(HttpCase):
with mock.patch('odoo.addons.base_report_to_printer.models.' with mock.patch('odoo.addons.base_report_to_printer.models.'
'printing_printer.PrintingPrinter.' 'printing_printer.PrintingPrinter.'
'print_document') as print_document: '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() print_document.assert_called_once()
def test_print_document_printable(self): def test_print_document_printable(self):
""" It should print the report, regardless of the defined behaviour """ """ 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'), ('report_type', '=', 'qweb-pdf'),
], limit=1) ], limit=1)
report.property_printing_action_id.action_type = 'server' 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.' with mock.patch('odoo.addons.base_report_to_printer.models.'
'printing_printer.PrintingPrinter.' 'printing_printer.PrintingPrinter.'
'print_document') as print_document: '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() print_document.assert_called_once()
def test_print_document_no_printer(self): def test_print_document_no_printer(self):
""" It should raise an error """ """ It should raise an error """
report = self.env['ir.actions.report.xml'].search([ report = self.env['ir.actions.report'].search([
('report_type', '=', 'qweb-pdf'), ('report_type', '=', 'qweb-pdf'),
], limit=1) ], limit=1)
records = self.env[report.model].search([], limit=5) records = self.env[report.model].search([], limit=5)
with self.assertRaises(exceptions.UserError): 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"?> <?xml version="1.0" encoding="utf-8"?>
<odoo> <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"> <xpath expr="." position="inside">
<script type="text/javascript" src="/base_report_to_printer/static/src/js/qweb_action_manager.js" /> <script type="text/javascript" src="/base_report_to_printer/static/src/js/qweb_action_manager.js" />
</xpath> </xpath>

View File

@@ -2,8 +2,8 @@
<odoo> <odoo>
<record model="ir.ui.view" id="act_report_xml_view"> <record model="ir.ui.view" id="act_report_xml_view">
<field name="name">ir.actions.report.xml.printing</field> <field name="name">ir.actions.report.printing</field>
<field name="model">ir.actions.report.xml</field> <field name="model">ir.actions.report</field>
<field name="inherit_id" ref="base.act_report_xml_view" /> <field name="inherit_id" ref="base.act_report_xml_view" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//page[@name='security']" position="before" > <xpath expr="//page[@name='security']" position="before" >

View File

@@ -2,7 +2,7 @@
<odoo> <odoo>
<menuitem name="Printing" <menuitem name="Printing"
id="printing_menu" id="printing_menu" sequence="1"
parent="base.menu_administration" parent="base.menu_administration"
groups="printing_group_manager" groups="printing_group_manager"
/> />
@@ -16,20 +16,20 @@
<header> <header>
<button name="enable" type="object" string="Enable" attrs="{'invisible': [('status', 'in', ('available', 'printing'))]}"/> <button name="enable" type="object" string="Enable" attrs="{'invisible': [('status', 'in', ('available', 'printing'))]}"/>
<button name="disable" type="object" string="Disable" attrs="{'invisible': [('status', '=', 'unavailable')]}"/> <button name="disable" type="object" string="Disable" attrs="{'invisible': [('status', '=', 'unavailable')]}"/>
<button name="action_cancel_all_jobs" type="object" string="Cancel all running jobs"/> <button name="action_cancel_all_jobs" type="object" string="Cancel all running jobs" confirm="Are you sure to want to cancel all jobs of this printer?"/>
</header> </header>
<div class="oe_title"> <div class="oe_title">
<h1> <h1>
<label for="name"/>
<field name="name"/> <field name="name"/>
</h1> </h1>
</div> </div>
<group> <group>
<field name="system_name"/> <field name="system_name"/>
</group> </group>
<group col="3" colspan="4"> <group col="4" colspan="4">
<field name="default"/> <field name="default"/>
<button name="set_default" string="Set Default" type="object"/> <button name="set_default" string="Set Default" type="object" attrs="{'invisible': [('default','=', True)]}"/>
<button name="unset_default" string="Unset Default" type="object" attrs="{'invisible': [('default','=', False)]}"/>
</group> </group>
<group> <group>
<field name="uri"/> <field name="uri"/>

View File

@@ -7,9 +7,9 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<form string="Report Printing Actions"> <form string="Report Printing Actions">
<group col="2"> <group col="2">
<field name="user_id"/> <field name="user_id" options="{'no_create': True}"/>
<field name="action"/> <field name="action"/>
<field name="printer_id" select="1"/> <field name="printer_id" options="{'no_create': True}"/>
</group> </group>
</form> </form>
</field> </field>
@@ -18,10 +18,10 @@
<field name="name">printing.report.xml.action.tree</field> <field name="name">printing.report.xml.action.tree</field>
<field name="model">printing.report.xml.action</field> <field name="model">printing.report.xml.action</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="Report Printing Actions"> <tree string="Report Printing Actions" editable="bottom">
<field name="user_id"/> <field name="user_id" options="{'no_create': True}"/>
<field name="action" /> <field name="action" />
<field name="printer_id" /> <field name="printer_id" options="{'no_create': True}"/>
</tree> </tree>
</field> </field>
</record> </record>
@@ -30,6 +30,6 @@
<menuitem id="printing_report_xml_action_menu" <menuitem id="printing_report_xml_action_menu"
sequence="30" sequence="30"
parent="printing_menu" parent="printing_menu"
action="base.ir_action_report_xml"/> action="base.ir_action_report"/>
</odoo> </odoo>

View File

@@ -9,7 +9,7 @@
<xpath expr="//group[@name='preferences']/ancestor::page" position="inside"> <xpath expr="//group[@name='preferences']/ancestor::page" position="inside">
<group string="Printing" name="printing"> <group string="Printing" name="printing">
<field name="printing_action"/> <field name="printing_action"/>
<field name="printing_printer_id"/> <field name="printing_printer_id" options="{'no_create': True}"/>
</group> </group>
</xpath> </xpath>
</field> </field>
@@ -22,8 +22,8 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<footer position="before"> <footer position="before">
<group string="Printing" name="printing"> <group string="Printing" name="printing">
<field name="printing_action"/> <field name="printing_action" readonly="0"/>
<field name="printing_printer_id"/> <field name="printing_printer_id" readonly="0" options="{'no_create': True}"/>
</group> </group>
</footer> </footer>
</field> </field>