diff --git a/base_report_to_printer/__manifest__.py b/base_report_to_printer/__manifest__.py
index f43141f..313e91a 100644
--- a/base_report_to_printer/__manifest__.py
+++ b/base_report_to_printer/__manifest__.py
@@ -8,23 +8,23 @@
{
'name': "Report to printer",
- 'version': '10.0.1.0.1',
+ 'version': '11.0.1.0.1',
'category': 'Generic Modules/Base',
'author': "Agile Business Group & Domsense, Pegueroles SCP, NaN,"
" 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,
diff --git a/base_report_to_printer/data/printing_data.xml b/base_report_to_printer/data/printing_data.xml
index 18fd399..7c88ad4 100644
--- a/base_report_to_printer/data/printing_data.xml
+++ b/base_report_to_printer/data/printing_data.xml
@@ -13,7 +13,7 @@
property_printing_action_id
-
+
@@ -25,7 +25,7 @@
minutes
-1
-
+
diff --git a/base_report_to_printer/i18n/base_report_to_printer.pot b/base_report_to_printer/i18n/base_report_to_printer.pot
deleted file mode 100644
index 25a506b..0000000
--- a/base_report_to_printer/i18n/base_report_to_printer.pot
+++ /dev/null
@@ -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 ""
-
diff --git a/base_report_to_printer/models/__init__.py b/base_report_to_printer/models/__init__.py
index 3736ec1..2d903d1 100644
--- a/base_report_to_printer/models/__init__.py
+++ b/base_report_to_printer/models/__init__.py
@@ -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
diff --git a/base_report_to_printer/models/ir_actions_report_xml.py b/base_report_to_printer/models/ir_actions_report.py
similarity index 52%
rename from base_report_to_printer/models/ir_actions_report_xml.py
rename to base_report_to_printer/models/ir_actions_report.py
index f45867a..d620228 100644
--- a/base_report_to_printer/models/ir_actions_report_xml.py
+++ b/base_report_to_printer/models/ir_actions_report.py
@@ -6,24 +6,20 @@
# Copyright (C) 2013-2014 Camptocamp ()
# 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',
- string='Action',
+ string='Default Behaviour',
company_dependent=True,
)
printing_printer_id = fields.Many2one(
comodel_name='printing.printer',
- string='Printer'
+ string='Default Printer'
)
printing_action_ids = fields.One2many(
comodel_name='printing.report.xml.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,65 @@ 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, 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
diff --git a/base_report_to_printer/models/printing_printer.py b/base_report_to_printer/models/printing_printer.py
index 5a78f46..51880ff 100644
--- a/base_report_to_printer/models/printing_printer.py
+++ b/base_report_to_printer/models/printing_printer.py
@@ -126,10 +126,15 @@ class PrintingPrinter(models.Model):
return
self.ensure_one()
default_printers = self.search([('default', '=', True)])
- default_printers.write({'default': False})
+ default_printers.unset_default()
self.write({'default': True})
return True
+ @api.multi
+ def unset_default(self):
+ self.write({'default': False})
+ return True
+
@api.multi
def get_default(self):
return self.search([('default', '=', True)], limit=1)
diff --git a/base_report_to_printer/models/printing_report_xml_action.py b/base_report_to_printer/models/printing_report_xml_action.py
index fc90155..ccc27b4 100644
--- a/base_report_to_printer/models/printing_report_xml_action.py
+++ b/base_report_to_printer/models/printing_report_xml_action.py
@@ -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')
diff --git a/base_report_to_printer/models/printing_server.py b/base_report_to_printer/models/printing_server.py
index fe52761..3f30364 100644
--- a/base_report_to_printer/models/printing_server.py
+++ b/base_report_to_printer/models/printing_server.py
@@ -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(
- datetime.fromtimestamp(job_data.get(
- 'time-at-processing', 0))),
+ 'time-at-processing', False) and
+ fields.Datetime.to_string(datetime.fromtimestamp(
+ job_data.get('time-at-processing', False))),
'time_at_completed': job_data.get(
- 'time-at-completed', 0) and fields.Datetime.to_string(
- datetime.fromtimestamp(job_data.get(
- 'time-at-completed', 0))),
+ 'time-at-completed', False) and
+ fields.Datetime.to_string(datetime.fromtimestamp(
+ job_data.get('time-at-completed', False))),
}
# Search for the printer in Odoo
diff --git a/base_report_to_printer/models/report.py b/base_report_to_printer/models/report.py
deleted file mode 100644
index 28ca298..0000000
--- a/base_report_to_printer/models/report.py
+++ /dev/null
@@ -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
diff --git a/base_report_to_printer/models/res_users.py b/base_report_to_printer/models/res_users.py
index 35be34f..092a00b 100644
--- a/base_report_to_printer/models/res_users.py
+++ b/base_report_to_printer/models/res_users.py
@@ -26,3 +26,14 @@ class ResUsers(models.Model):
)
printing_printer_id = fields.Many2one(comodel_name='printing.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',
+ ])
diff --git a/base_report_to_printer/static/src/js/qweb_action_manager.js b/base_report_to_printer/static/src/js/qweb_action_manager.js
index 794e24b..d1f884f 100644
--- a/base_report_to_printer/static/src/js/qweb_action_manager.js
+++ b/base_report_to_printer/static/src/js/qweb_action_manager.js
@@ -7,28 +7,24 @@ odoo.define('base_report_to_printer.print', function(require) {
var Model = require('web.Model');
ActionManager.include({
- ir_actions_report_xml: function(action, options) {
- action = _.clone(action);
+ ir_actions_report: function(action, options) {
+ action_val = _.clone(action);
var _t = core._t;
var self = this;
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();
- 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') {
+ new Model('ir.actions.report').
+ call('print_action_for_report_name', [action_val.report_name]).
+ then(function(print_action){
+ if (print_action && print_action.action_val === 'server') {
framework.unblockUI();
- new Model('report')
- .call('print_document',
- [action.context.active_ids,
- action.report_name,
- ],
- {data: action.data || {},
- context: action.context || {},
- })
- .then(function(){
+ new Model('report').
+ call('print_document',
+ [action_val.context.active_ids, action_val.report_name],
+ {data: action_val.data || {}, context: action_val.context || {}}).
+ then(function(){
self.do_notify(_t('Report'),
_t('Document sent to the printer ') + print_action.printer_name);
}).fail(function() {
@@ -37,14 +33,12 @@ odoo.define('base_report_to_printer.print', function(require) {
});
} else {
- return _super.apply(self, [action, options]);
+ return _super.apply(self, [action_val, options]);
}
});
} else {
- return _super.apply(self, [action, options]);
+ return _super.apply(self, [action_val, options]);
}
}
});
-
});
-
diff --git a/base_report_to_printer/tests/__init__.py b/base_report_to_printer/tests/__init__.py
index a43edf1..49a8da5 100644
--- a/base_report_to_printer/tests/__init__.py
+++ b/base_report_to_printer/tests/__init__.py
@@ -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
diff --git a/base_report_to_printer/tests/test_ir_actions_report_xml.py b/base_report_to_printer/tests/test_ir_actions_report.py
similarity index 88%
rename from base_report_to_printer/tests/test_ir_actions_report_xml.py
rename to base_report_to_printer/tests/test_ir_actions_report.py
index 442f960..25f6e16 100644
--- a/base_report_to_printer/tests/test_ir_actions_report_xml.py
+++ b/base_report_to_printer/tests/test_ir_actions_report.py
@@ -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,
},
diff --git a/base_report_to_printer/tests/test_printing_job.py b/base_report_to_printer/tests/test_printing_job.py
index 6a82422..612c038 100644
--- a/base_report_to_printer/tests/test_printing_job.py
+++ b/base_report_to_printer/tests/test_printing_job.py
@@ -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):
diff --git a/base_report_to_printer/tests/test_printing_printer.py b/base_report_to_printer/tests/test_printing_printer.py
index f983472..26043c7 100644
--- a/base_report_to_printer/tests/test_printing_printer.py
+++ b/base_report_to_printer/tests/test_printing_printer.py
@@ -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,14 @@ 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())
+
+ 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)
def test_cancel_all_jobs(self, cups):
diff --git a/base_report_to_printer/tests/test_printing_printer_wizard.py b/base_report_to_printer/tests/test_printing_printer_wizard.py
index 437e221..45c4054 100644
--- a/base_report_to_printer/tests/test_printing_printer_wizard.py
+++ b/base_report_to_printer/tests/test_printing_printer_wizard.py
@@ -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)
diff --git a/base_report_to_printer/tests/test_printing_report_xml_action.py b/base_report_to_printer/tests/test_printing_report_xml_action.py
index 52c8329..4020dbd 100644
--- a/base_report_to_printer/tests/test_printing_report_xml_action.py
+++ b/base_report_to_printer/tests/test_printing_report_xml_action.py
@@ -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 = {
diff --git a/base_report_to_printer/tests/test_report.py b/base_report_to_printer/tests/test_report.py
index 9ee58b2..8a1f5fe 100644
--- a/base_report_to_printer/tests/test_report.py
+++ b/base_report_to_printer/tests/test_report.py
@@ -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, doc_format = 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)
diff --git a/base_report_to_printer/views/assets.xml b/base_report_to_printer/views/assets.xml
index 7630e2e..1cfdad9 100644
--- a/base_report_to_printer/views/assets.xml
+++ b/base_report_to_printer/views/assets.xml
@@ -1,6 +1,6 @@
-
+
diff --git a/base_report_to_printer/views/ir_actions_report_xml_view.xml b/base_report_to_printer/views/ir_actions_report.xml
similarity index 83%
rename from base_report_to_printer/views/ir_actions_report_xml_view.xml
rename to base_report_to_printer/views/ir_actions_report.xml
index 317f87a..33757ae 100644
--- a/base_report_to_printer/views/ir_actions_report_xml_view.xml
+++ b/base_report_to_printer/views/ir_actions_report.xml
@@ -2,8 +2,8 @@
- ir.actions.report.xml.printing
- ir.actions.report.xml
+ ir.actions.report.printing
+ ir.actions.report
diff --git a/base_report_to_printer/views/printing_printer_view.xml b/base_report_to_printer/views/printing_printer.xml
similarity index 88%
rename from base_report_to_printer/views/printing_printer_view.xml
rename to base_report_to_printer/views/printing_printer.xml
index 864505f..acb2494 100644
--- a/base_report_to_printer/views/printing_printer_view.xml
+++ b/base_report_to_printer/views/printing_printer.xml
@@ -2,7 +2,7 @@
@@ -16,20 +16,20 @@
-
-
+
-
+
+
diff --git a/base_report_to_printer/views/printing_report_view.xml b/base_report_to_printer/views/printing_report.xml
similarity index 71%
rename from base_report_to_printer/views/printing_report_view.xml
rename to base_report_to_printer/views/printing_report.xml
index bd41196..ee2f4c4 100644
--- a/base_report_to_printer/views/printing_report_view.xml
+++ b/base_report_to_printer/views/printing_report.xml
@@ -7,9 +7,9 @@
@@ -18,10 +18,10 @@
printing.report.xml.action.tree
printing.report.xml.action
-
-
+
+
-
+
@@ -30,6 +30,6 @@
+ action="base.ir_action_report"/>
diff --git a/base_report_to_printer/views/res_users_view.xml b/base_report_to_printer/views/res_users.xml
similarity index 80%
rename from base_report_to_printer/views/res_users_view.xml
rename to base_report_to_printer/views/res_users.xml
index 6d4a002..a6792b7 100644
--- a/base_report_to_printer/views/res_users_view.xml
+++ b/base_report_to_printer/views/res_users.xml
@@ -9,7 +9,7 @@
-
+
@@ -22,8 +22,8 @@