Migrate printer_tray to v9.0

This commit is contained in:
Sylvain GARANCHER
2016-11-08 13:13:30 +01:00
parent a7a0761d39
commit 104b531d1f
20 changed files with 173 additions and 266 deletions

View File

@@ -1,3 +1,8 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
========================================
Report to printer - Paper tray selection Report to printer - Paper tray selection
======================================== ========================================
@@ -40,6 +45,10 @@ There is no special usage, once configured, reports are printed in the
select tray. When no tray is configured for a report and a user, the select tray. When no tray is configured for a report and a user, the
default tray setup on the CUPS server is used. default tray setup on the CUPS server is used.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/144/9.0
Known issues / Roadmap Known issues / Roadmap
====================== ======================
@@ -48,11 +57,10 @@ Known issues / Roadmap
Bug Tracker Bug Tracker
=========== ===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/report-print-send/issues>`_. Bugs are tracked on `GitHub Issues
In case of trouble, please check there if your issue has already been reported. <https://github.com/OCA/report-print-send/issues>`_. In case of trouble, please
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback check there if your issue has already been reported. If you spotted it first,
`here <https://github.com/OCA/report-print-send/issues/new?body=module:%20printer_tray%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. help us smashing it by providing a detailed and welcomed feedback.
Credits Credits
======= =======
@@ -66,12 +74,14 @@ Contributors
Maintainer Maintainer
---------- ----------
.. image:: http://odoo-community.org/logo.png .. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association :alt: Odoo Community Association
:target: http://odoo-community.org :target: https://odoo-community.org
This module is maintained by the OCA. This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit http://odoo-community.org. To contribute to this module, please visit https://odoo-community.org.

View File

@@ -1,25 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## # Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
# # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# Author: Yannick Vaucher
# Copyright 2013 Camptocamp SA from . import models
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import ir_report
from . import printer_tray
from . import printer
from . import users
from . import report_xml_action

View File

@@ -1,43 +1,28 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## # Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
# # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# Author: Yannick Vaucher
# Copyright 2013 Camptocamp SA {
# 'name': 'Report to printer - Paper tray selection',
# This program is free software: you can redistribute it and/or modify 'version': '9.0.1.0.0',
# it under the terms of the GNU Affero General Public License as 'category': 'Printer',
# published by the Free Software Foundation, either version 3 of the 'author': "Camptocamp, Odoo Community Association (OCA)",
# License, or (at your option) any later version. 'maintainer': 'Camptocamp',
# 'website': 'http://www.camptocamp.com/',
# This program is distributed in the hope that it will be useful, 'license': 'AGPL-3',
# but WITHOUT ANY WARRANTY; without even the implied warranty of 'depends': [
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 'base_report_to_printer',
# GNU Affero General Public License for more details. ],
# 'data': [
# You should have received a copy of the GNU Affero General Public License 'views/res_users.xml',
# along with this program. If not, see <http://www.gnu.org/licenses/>. 'views/ir_actions_report_xml.xml',
# 'views/printing_printer.xml',
############################################################################## 'views/printing_report_xml_action.xml',
{'name': 'Report to printer - Paper tray selection', 'security/ir.model.access.csv',
'version': '8.0.1.0.0', ],
'category': 'Printer', 'external_dependencies': {
'author': "Camptocamp,Odoo Community Association (OCA)", 'python': ['cups'],
'maintainer': 'Camptocamp', },
'website': 'http://www.camptocamp.com/', 'installable': True,
'license': 'AGPL-3', 'application': True,
'depends': ['base_report_to_printer', }
],
'data': [
'users_view.xml',
'ir_report_view.xml',
'printer_view.xml',
'report_xml_action_view.xml',
'security/ir.model.access.csv',
],
'external_dependencies': {
'python': ['cups'],
},
'installable': False,
'auto_install': False,
'application': True,
}

View File

@@ -1,37 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Yannick Vaucher
# Copyright 2013 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import models, fields, api
class IrActionsReportXml(models.Model):
_inherit = 'ir.actions.report.xml'
printer_tray_id = fields.Many2one(
comodel_name='printing.tray',
string='Paper Source',
domain="[('printer_id', '=', printing_printer_id)]",
)
@api.onchange('printing_printer_id')
def onchange_printing_printer_id(self):
""" Reset the tray when the printer is changed """
self.printer_tray_id = False

View File

@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import ir_actions_report_xml
from . import printing_tray
from . import printing_printer
from . import res_users
from . import printing_report_xml_action

View File

@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import models, fields, api
class IrActionsReportXml(models.Model):
_inherit = 'ir.actions.report.xml'
printer_tray_id = fields.Many2one(
comodel_name='printing.tray',
string='Paper Source',
domain="[('printer_id', '=', printing_printer_id)]",
)
@api.onchange('printing_printer_id')
def onchange_printing_printer_id(self):
""" Reset the tray when the printer is changed """
self.printer_tray_id = False

View File

@@ -1,23 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## # Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
# # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# Author: Yannick Vaucher
# Copyright 2013 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import errno import errno
import logging import logging
@@ -33,7 +16,7 @@ except ImportError:
_logger.debug('Cannot `import cups`.') _logger.debug('Cannot `import cups`.')
class Printer(models.Model): class PrintingPrinter(models.Model):
_inherit = 'printing.printer' _inherit = 'printing.printer'
tray_ids = fields.One2many(comodel_name='printing.tray', tray_ids = fields.One2many(comodel_name='printing.tray',
@@ -42,10 +25,12 @@ class Printer(models.Model):
@api.multi @api.multi
def _prepare_update_from_cups(self, cups_connection, cups_printer): def _prepare_update_from_cups(self, cups_connection, cups_printer):
vals = super(Printer, self)._prepare_update_from_cups(cups_connection, vals = super(PrintingPrinter, self)._prepare_update_from_cups(
cups_printer) cups_connection, cups_printer)
ppd_info = cups_connection.getPPD3(self.system_name) printer_uri = cups_printer['printer-uri-supported']
printer_system_name = printer_uri[printer_uri.rfind('/') + 1:]
ppd_info = cups_connection.getPPD3(printer_system_name)
ppd_path = ppd_info[2] ppd_path = ppd_info[2]
if not ppd_path: if not ppd_path:
return vals return vals
@@ -85,7 +70,7 @@ class Printer(models.Model):
def print_options(self, report, format, copies=1): def print_options(self, report, format, copies=1):
""" Hook to define Tray """ """ Hook to define Tray """
printing_act_obj = self.env['printing.report.xml.action'] printing_act_obj = self.env['printing.report.xml.action']
options = super(Printer, self).print_options(report, format) options = super(PrintingPrinter, self).print_options(report, format)
# Retrieve user default values # Retrieve user default values
user = self.env.user user = self.env.user

View File

@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import models, fields, api
class PrintingReportXMLAction(models.Model):
_inherit = 'printing.report.xml.action'
printer_tray_id = fields.Many2one(
comodel_name='printing.tray',
string='Paper Source',
domain="[('printer_id', '=', printer_id)]",
)
@api.multi
def behaviour(self):
self.ensure_one()
res = super(PrintingReportXMLAction, self).behaviour()
res['tray'] = self.printer_tray_id.system_name
return res
@api.onchange('printer_id')
def onchange_printer_id(self):
""" Reset the tray when the printer is changed """
self.printer_tray_id = False

View File

@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import models, fields
class PrinterTray(models.Model):
_name = 'printing.tray'
_description = 'Printer Tray'
name = fields.Char(required=True)
system_name = fields.Char(required=True, readonly=True)
printer_id = fields.Many2one(
comodel_name='printing.printer',
string='Printer',
required=True,
readonly=True,
ondelete='cascade',
)

View File

@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import models, fields, api
class ResUsers(models.Model):
_inherit = "res.users"
printer_tray_id = fields.Many2one(
comodel_name='printing.tray',
string='Default Printer Paper Source',
domain="[('printer_id', '=', printing_printer_id)]",
)
@api.onchange('printing_printer_id')
def onchange_printing_printer_id(self):
""" Reset the tray when the printer is changed """
self.printer_tray_id = False

View File

@@ -1,37 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Yannick Vaucher
# Copyright 2013 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import models, fields
class PrinterTray(models.Model):
_name = 'printing.tray'
_description = 'Printer Tray'
name = fields.Char(required=True)
system_name = fields.Char(required=True, readonly=True)
printer_id = fields.Many2one(
comodel_name='printing.printer',
string='Printer',
required=True,
readonly=True,
ondelete='cascade',
)

View File

@@ -1,44 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Yannick Vaucher
# Copyright 2013 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import models, fields, api
class ReportXMLAction(models.Model):
_inherit = 'printing.report.xml.action'
printer_tray_id = fields.Many2one(
comodel_name='printing.tray',
string='Paper Source',
domain="[('printer_id', '=', printer_id)]",
)
@api.multi
def behaviour(self):
self.ensure_one()
res = super(ReportXMLAction, self).behaviour()
res['tray'] = self.printer_tray_id.system_name
return res
@api.onchange('printer_id')
def onchange_printer_id(self):
""" Reset the tray when the printer is changed """
self.printer_tray_id = False

View File

@@ -1,3 +1,3 @@
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" "id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
access_printing_tray_all,printing_tray all,model_printing_tray,,1,0,0,0 access_printing_tray_all,printing_tray all,model_printing_tray,base_report_to_printer.printing_group_user,1,0,0,0
access_printing_tray_operator,printing_tray operator,model_printing_tray,base_report_to_printer.res_groups_printingprintoperator0,1,1,1,1 access_printing_tray_operator,printing_tray operator,model_printing_tray,base_report_to_printer.printing_group_manager,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_printing_tray_all printing_tray all model_printing_tray base_report_to_printer.printing_group_user 1 0 0 0
3 access_printing_tray_operator printing_tray operator model_printing_tray base_report_to_printer.res_groups_printingprintoperator0 base_report_to_printer.printing_group_manager 1 1 1 1

View File

@@ -7,7 +7,8 @@ import tempfile
from openerp.tests.common import TransactionCase from openerp.tests.common import TransactionCase
model = 'openerp.addons.base_report_to_printer.printing' model = 'openerp.addons.base_report_to_printer.models.printing_printer'
server_model = 'openerp.addons.base_report_to_printer.models.printing_server'
ppd_header = '*PPD-Adobe: "4.3"' ppd_header = '*PPD-Adobe: "4.3"'
ppd_input_slot_header = """ ppd_input_slot_header = """
@@ -36,8 +37,11 @@ class TestPrintingPrinter(TransactionCase):
def setUp(self): def setUp(self):
super(TestPrintingPrinter, self).setUp() super(TestPrintingPrinter, self).setUp()
self.Model = self.env['printing.printer'] self.Model = self.env['printing.printer']
self.ServerModel = self.env['printing.server']
self.server = self.env['printing.server'].create({})
self.printer = self.env['printing.printer'].create({ self.printer = self.env['printing.printer'].create({
'name': 'Printer', 'name': 'Printer',
'server_id': self.server.id,
'system_name': 'Sys Name', 'system_name': 'Sys Name',
'default': True, 'default': True,
'status': 'unknown', 'status': 'unknown',
@@ -152,7 +156,7 @@ class TestPrintingPrinter(TransactionCase):
'InputSlot': 'Action tray', 'InputSlot': 'Action tray',
}) })
@mock.patch('%s.cups' % model) @mock.patch('%s.cups' % server_model)
def test_update_printers(self, cups): def test_update_printers(self, cups):
""" """
Check that the update_printers method calls _prepare_update_from_cups Check that the update_printers method calls _prepare_update_from_cups
@@ -162,10 +166,10 @@ class TestPrintingPrinter(TransactionCase):
with mock.patch.object( with mock.patch.object(
self.Model, '_prepare_update_from_cups' self.Model, '_prepare_update_from_cups'
) as prepare_update_from_cups: ) as prepare_update_from_cups:
self.Model.update_printers_status() self.ServerModel.update_printers()
prepare_update_from_cups.assert_called_once() prepare_update_from_cups.assert_called_once()
@mock.patch('%s.cups' % model) @mock.patch('%s.cups' % server_model)
def test_prepare_update_from_cups_no_ppd(self, cups): def test_prepare_update_from_cups_no_ppd(self, cups):
""" """
Check that the tray_ids field has no value when no PPD is available Check that the tray_ids field has no value when no PPD is available
@@ -178,7 +182,7 @@ class TestPrintingPrinter(TransactionCase):
vals = self.printer._prepare_update_from_cups(connection, cups_printer) vals = self.printer._prepare_update_from_cups(connection, cups_printer)
self.assertFalse('tray_ids' in vals) self.assertFalse('tray_ids' in vals)
@mock.patch('%s.cups' % model) @mock.patch('%s.cups' % server_model)
def test_prepare_update_from_cups_empty_ppd(self, cups): def test_prepare_update_from_cups_empty_ppd(self, cups):
""" """
Check that the tray_ids field has no value when the PPD file has Check that the tray_ids field has no value when the PPD file has
@@ -196,7 +200,7 @@ class TestPrintingPrinter(TransactionCase):
vals = self.printer._prepare_update_from_cups(connection, cups_printer) vals = self.printer._prepare_update_from_cups(connection, cups_printer)
self.assertFalse('tray_ids' in vals) self.assertFalse('tray_ids' in vals)
@mock.patch('%s.cups' % model) @mock.patch('%s.cups' % server_model)
def test_prepare_update_from_cups(self, cups): def test_prepare_update_from_cups(self, cups):
""" """
Check the return value when adding a single tray Check the return value when adding a single tray
@@ -212,7 +216,7 @@ class TestPrintingPrinter(TransactionCase):
'system_name': 'Auto', 'system_name': 'Auto',
})]) })])
@mock.patch('%s.cups' % model) @mock.patch('%s.cups' % server_model)
def test_prepare_update_from_cups_with_multiple_trays(self, cups): def test_prepare_update_from_cups_with_multiple_trays(self, cups):
""" """
Check the return value when adding multiple trays at once Check the return value when adding multiple trays at once
@@ -233,7 +237,7 @@ class TestPrintingPrinter(TransactionCase):
'system_name': 'Tray1', 'system_name': 'Tray1',
})]) })])
@mock.patch('%s.cups' % model) @mock.patch('%s.cups' % server_model)
def test_prepare_update_from_cups_already_known_trays(self, cups): def test_prepare_update_from_cups_already_known_trays(self, cups):
""" """
Check that calling the method twice doesn't create the trays multiple Check that calling the method twice doesn't create the trays multiple
@@ -255,7 +259,7 @@ class TestPrintingPrinter(TransactionCase):
'system_name': 'Auto', 'system_name': 'Auto',
})]) })])
@mock.patch('%s.cups' % model) @mock.patch('%s.cups' % server_model)
def test_prepare_update_from_cups_unknown_trays(self, cups): def test_prepare_update_from_cups_unknown_trays(self, cups):
""" """
Check that trays which are not in the PPD file are removed from Odoo Check that trays which are not in the PPD file are removed from Odoo

View File

@@ -5,7 +5,7 @@
from openerp.tests.common import TransactionCase from openerp.tests.common import TransactionCase
model = 'openerp.addons.base_report_to_printer.printing' model = 'openerp.addons.base_report_to_printer.models.printing_server'
class TestPrintingTray(TransactionCase): class TestPrintingTray(TransactionCase):
@@ -13,8 +13,10 @@ class TestPrintingTray(TransactionCase):
def setUp(self): def setUp(self):
super(TestPrintingTray, self).setUp() super(TestPrintingTray, self).setUp()
self.Model = self.env['printing.tray'] self.Model = self.env['printing.tray']
self.server = self.env['printing.server'].create({})
self.printer = self.env['printing.printer'].create({ self.printer = self.env['printing.printer'].create({
'name': 'Printer', 'name': 'Printer',
'server_id': self.server.id,
'system_name': 'Sys Name', 'system_name': 'Sys Name',
'default': True, 'default': True,
'status': 'unknown', 'status': 'unknown',

View File

@@ -1,37 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Yannick Vaucher
# Copyright 2013 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import models, fields, api
class ResUsers(models.Model):
_inherit = "res.users"
printer_tray_id = fields.Many2one(
comodel_name='printing.tray',
string='Default Printer Paper Source',
domain="[('printer_id', '=', printing_printer_id)]",
)
@api.onchange('printing_printer_id')
def onchange_printing_printer_id(self):
""" Reset the tray when the printer is changed """
self.printer_tray_id = False