diff --git a/base_report_to_printer/README.rst b/base_report_to_printer/README.rst index bf9e238..6fac34a 100644 --- a/base_report_to_printer/README.rst +++ b/base_report_to_printer/README.rst @@ -99,6 +99,8 @@ Contributors * Dave Lasley * Sylvain Garancher * Jairo Llopis +* Oihane Crucelaegui +* Luis M. Ontalba Maintainer ---------- diff --git a/base_report_to_printer/__manifest__.py b/base_report_to_printer/__manifest__.py index 68b40b4..0049e43 100644 --- a/base_report_to_printer/__manifest__.py +++ b/base_report_to_printer/__manifest__.py @@ -8,10 +8,10 @@ { 'name': "Report to printer", - 'version': '10.0.1.0.3', + 'version': '10.0.1.0.4', 'category': 'Generic Modules/Base', 'author': "Agile Business Group & Domsense, Pegueroles SCP, NaN," - " LasLabs, Odoo Community Association (OCA)", + "LasLabs, Odoo Community Association (OCA)", 'website': 'http://www.agilebg.com', 'license': 'AGPL-3', "depends": ['report'], diff --git a/base_report_to_printer/models/ir_actions_report_xml.py b/base_report_to_printer/models/ir_actions_report_xml.py index f45867a..1a63dee 100644 --- a/base_report_to_printer/models/ir_actions_report_xml.py +++ b/base_report_to_printer/models/ir_actions_report_xml.py @@ -4,6 +4,7 @@ # Copyright (C) 2011 Agile Business Group sagl () # Copyright (C) 2011 Domsense srl () # Copyright (C) 2013-2014 Camptocamp () +# Copyright 2015 Oihane Crucelaegui - AvanzOSC # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import models, fields, api @@ -21,6 +22,10 @@ class IrActionsReportXml(models.Model): string='Action', company_dependent=True, ) + report_copies = fields.Integer( + string="# Copies", + default=1, + ) printing_printer_id = fields.Many2one( comodel_name='printing.printer', string='Printer' diff --git a/base_report_to_printer/models/printing_printer.py b/base_report_to_printer/models/printing_printer.py index 5a78f46..bbbee97 100644 --- a/base_report_to_printer/models/printing_printer.py +++ b/base_report_to_printer/models/printing_printer.py @@ -5,6 +5,8 @@ # Copyright (C) 2011 Domsense srl () # Copyright (C) 2013-2014 Camptocamp () # Copyright (C) 2016 SYLEAM () +# Copyright 2015 Oihane Crucelaegui - AvanzOSC +# Copyright 2017 Luis M. Ontalba - Tecnativa # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). import logging @@ -94,7 +96,14 @@ class PrintingPrinter(models.Model): os.write(fd, content) finally: os.close(fd) - + if copies == 1: + # If number of copies is not indicated by argument, check context + # or report definition + copies = ( + self.env.context.get('report_copies') or + (report and report.report_copies) or + copies + ) return self.print_file( file_name, report=report, copies=copies, format=format) diff --git a/base_report_to_printer/tests/test_printing_printer.py b/base_report_to_printer/tests/test_printing_printer.py index f983472..c79d24e 100644 --- a/base_report_to_printer/tests/test_printing_printer.py +++ b/base_report_to_printer/tests/test_printing_printer.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- # Copyright 2016 LasLabs Inc. +# Copyright 2017 Tecnativa. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). import tempfile @@ -31,6 +32,9 @@ class TestPrintingPrinter(TransactionCase): 'location': 'Location', 'uri': 'URI', } + self.report = self.env['ir.actions.report.xml'].search([ + ('report_type', '=', 'qweb-pdf'), + ], limit=1) def new_record(self): return self.Model.create(self.printer_vals) @@ -55,7 +59,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(self.report, 'content to print', 'pdf') cups.Connection().printFile.assert_called_once_with( printer.system_name, file_name, @@ -72,7 +76,7 @@ class TestPrintingPrinter(TransactionCase): printer = self.new_record() with self.assertRaises(UserError): printer.print_document( - 'report_name', 'content to print', 'pdf') + self.report, 'content to print', 'pdf') @mock.patch('%s.cups' % server_model) def test_print_file(self, cups): diff --git a/base_report_to_printer/views/ir_actions_report_xml_view.xml b/base_report_to_printer/views/ir_actions_report_xml_view.xml index 317f87a..fda34ad 100644 --- a/base_report_to_printer/views/ir_actions_report_xml_view.xml +++ b/base_report_to_printer/views/ir_actions_report_xml_view.xml @@ -10,9 +10,9 @@ + -