[10.0][IMP] base_report_to_printer: Copies number in print report

This commit is contained in:
Luis M. Ontalba
2018-01-22 15:56:58 +01:00
committed by Jairo Llopis
parent 2bae394d79
commit a946a2a570
6 changed files with 26 additions and 6 deletions

View File

@@ -99,6 +99,8 @@ Contributors
* Dave Lasley <dave@laslabs.com> * Dave Lasley <dave@laslabs.com>
* Sylvain Garancher <sylvain.garancher@syleam.fr> * Sylvain Garancher <sylvain.garancher@syleam.fr>
* Jairo Llopis <jairo.llopis@tecnativa.com> * Jairo Llopis <jairo.llopis@tecnativa.com>
* Oihane Crucelaegui <oihanecrucelaegi@avanzosc.es>
* Luis M. Ontalba <luis.martinez@tecnativa.com>
Maintainer Maintainer
---------- ----------

View File

@@ -8,10 +8,10 @@
{ {
'name': "Report to printer", 'name': "Report to printer",
'version': '10.0.1.0.3', 'version': '10.0.1.0.4',
'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": ['report'],

View File

@@ -4,6 +4,7 @@
# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>) # Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>) # Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>) # Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
# Copyright 2015 Oihane Crucelaegui - AvanzOSC
# 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 models, fields, api
@@ -21,6 +22,10 @@ class IrActionsReportXml(models.Model):
string='Action', string='Action',
company_dependent=True, company_dependent=True,
) )
report_copies = fields.Integer(
string="# Copies",
default=1,
)
printing_printer_id = fields.Many2one( printing_printer_id = fields.Many2one(
comodel_name='printing.printer', comodel_name='printing.printer',
string='Printer' string='Printer'

View File

@@ -5,6 +5,8 @@
# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>) # Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>) # Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
# Copyright (C) 2016 SYLEAM (<http://www.syleam.fr>) # Copyright (C) 2016 SYLEAM (<http://www.syleam.fr>)
# Copyright 2015 Oihane Crucelaegui - AvanzOSC
# Copyright 2017 Luis M. Ontalba - Tecnativa
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging import logging
@@ -94,7 +96,14 @@ class PrintingPrinter(models.Model):
os.write(fd, content) os.write(fd, content)
finally: finally:
os.close(fd) 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( return self.print_file(
file_name, report=report, copies=copies, format=format) file_name, report=report, copies=copies, format=format)

View File

@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2016 LasLabs Inc. # Copyright 2016 LasLabs Inc.
# Copyright 2017 Tecnativa.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import tempfile import tempfile
@@ -31,6 +32,9 @@ class TestPrintingPrinter(TransactionCase):
'location': 'Location', 'location': 'Location',
'uri': 'URI', 'uri': 'URI',
} }
self.report = self.env['ir.actions.report.xml'].search([
('report_type', '=', 'qweb-pdf'),
], limit=1)
def new_record(self): def new_record(self):
return self.Model.create(self.printer_vals) return self.Model.create(self.printer_vals)
@@ -55,7 +59,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(self.report, '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 +76,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') self.report, '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):

View File

@@ -10,9 +10,9 @@
<page string="Print" name="print" > <page string="Print" name="print" >
<group> <group>
<field name="property_printing_action_id"/> <field name="property_printing_action_id"/>
<field name="report_copies"/>
<field name="printing_printer_id"/> <field name="printing_printer_id"/>
</group> </group>
<separator string="Specific actions per user"/> <separator string="Specific actions per user"/>
<field name="printing_action_ids"/> <field name="printing_action_ids"/>
</page> </page>