From 9b48d16771ed2a1a1b834808ed91ebe8d0a5be34 Mon Sep 17 00:00:00 2001 From: Sylvain GARANCHER Date: Wed, 4 Oct 2017 11:54:34 +0200 Subject: [PATCH] [FIX] Review fixes --- base_report_to_printer/__manifest__.py | 2 +- .../models/ir_actions_report.py | 9 +++--- .../models/printing_printer.py | 7 +++- .../models/printing_server.py | 12 +++---- .../static/src/js/qweb_action_manager.js | 32 ++++++++----------- .../tests/test_printing_printer.py | 7 ++++ base_report_to_printer/tests/test_report.py | 2 +- .../views/printing_printer.xml | 10 +++--- .../views/printing_report.xml | 4 +-- 9 files changed, 46 insertions(+), 39 deletions(-) diff --git a/base_report_to_printer/__manifest__.py b/base_report_to_printer/__manifest__.py index 667ba7e..313e91a 100644 --- a/base_report_to_printer/__manifest__.py +++ b/base_report_to_printer/__manifest__.py @@ -8,7 +8,7 @@ { '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)", diff --git a/base_report_to_printer/models/ir_actions_report.py b/base_report_to_printer/models/ir_actions_report.py index 4603cbf..3d3dfd5 100644 --- a/base_report_to_printer/models/ir_actions_report.py +++ b/base_report_to_printer/models/ir_actions_report.py @@ -94,8 +94,9 @@ class IrActionsReport(models.Model): @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) + 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: @@ -124,7 +125,7 @@ class IrActionsReport(models.Model): If the action configured on the report is server, it prints the generated document as well. """ - document = super(IrActionsReport, self).render_qweb_pdf( + document, doc_format = super(IrActionsReport, self).render_qweb_pdf( docids, data=data) behaviour = self.behaviour()[self] @@ -134,4 +135,4 @@ class IrActionsReport(models.Model): if can_print_report: printer.print_document(self, document, self.report_type) - return document + 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_server.py b/base_report_to_printer/models/printing_server.py index 02613eb..3f30364 100644 --- a/base_report_to_printer/models/printing_server.py +++ b/base_report_to_printer/models/printing_server.py @@ -190,13 +190,13 @@ class PrintingServer(models.Model): datetime.fromtimestamp(job_data.get( 'time-at-creation', False))), 'time_at_processing': job_data.get( - 'time-at-processing', False) and fields.Datetime.to_string( - datetime.fromtimestamp(job_data.get( - 'time-at-processing', False))), + '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', False) and fields.Datetime.to_string( - datetime.fromtimestamp(job_data.get( - 'time-at-completed', False))), + '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/static/src/js/qweb_action_manager.js b/base_report_to_printer/static/src/js/qweb_action_manager.js index aab5333..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 @@ -8,27 +8,23 @@ odoo.define('base_report_to_printer.print', function(require) { ActionManager.include({ ir_actions_report: function(action, options) { - action = _.clone(action); + 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') - .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/test_printing_printer.py b/base_report_to_printer/tests/test_printing_printer.py index 5eaae36..26043c7 100644 --- a/base_report_to_printer/tests/test_printing_printer.py +++ b/base_report_to_printer/tests/test_printing_printer.py @@ -107,6 +107,13 @@ class TestPrintingPrinter(TransactionCase): self.Model.set_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): """ It should cancel all jobs """ diff --git a/base_report_to_printer/tests/test_report.py b/base_report_to_printer/tests/test_report.py index 9d906f2..8a1f5fe 100644 --- a/base_report_to_printer/tests/test_report.py +++ b/base_report_to_printer/tests/test_report.py @@ -88,7 +88,7 @@ class TestReport(HttpCase): report.property_printing_action_id.action_type = 'server' report.printing_printer_id = self.new_printer() records = self.env[report.model].search([], limit=5) - document = report.render_qweb_pdf(records.ids) + document, doc_format = report.render_qweb_pdf(records.ids) print_document.assert_called_once_with( report, document, report.report_type) diff --git a/base_report_to_printer/views/printing_printer.xml b/base_report_to_printer/views/printing_printer.xml index 864505f..acb2494 100644 --- a/base_report_to_printer/views/printing_printer.xml +++ b/base_report_to_printer/views/printing_printer.xml @@ -2,7 +2,7 @@ @@ -16,20 +16,20 @@

-

- + -