diff --git a/oca_dependencies.txt b/oca_dependencies.txt new file mode 100644 index 0000000..9c8c917 --- /dev/null +++ b/oca_dependencies.txt @@ -0,0 +1 @@ +server-tools diff --git a/remote_report_to_printer/README.rst b/remote_report_to_printer/README.rst new file mode 100644 index 0000000..1bd946e --- /dev/null +++ b/remote_report_to_printer/README.rst @@ -0,0 +1,89 @@ +============================ +Report to printer on remotes +============================ + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freport--print--send-lightgray.png?logo=github + :target: https://github.com/OCA/report-print-send/tree/12.0/remote_report_to_printer + :alt: OCA/report-print-send +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/report-print-send-12-0/report-print-send-12-0-remote_report_to_printer + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/144/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows users to send reports to a printer using remote's configuration. + +A *remote* is an external entity that access odoo. For example, computers, mobiles, +servers... We will identify *remotes* by its name or ip. On some environments, +we want to configure the printers by remote, because users may change their +work place. + +It adds an optional behaviour on reports to send it directly to a printer. + +* `Use remote's configuration` use the remote's behaviour + +Also, this option can be selected as a user default option for printer. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + + * In *Settings > Remotes* configure the remotes printers by usage + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Creu Blanca + +Contributors +~~~~~~~~~~~~ + +* Enric Tobella + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +This module is part of the `OCA/report-print-send `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/remote_report_to_printer/__init__.py b/remote_report_to_printer/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/remote_report_to_printer/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/remote_report_to_printer/__manifest__.py b/remote_report_to_printer/__manifest__.py new file mode 100644 index 0000000..39a8836 --- /dev/null +++ b/remote_report_to_printer/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright (c) 2018 Creu Blanca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': "Report to printer on remotes", + 'version': '12.0.2.1.1', + 'category': 'Generic Modules/Base', + 'author': "Creu Blanca, Odoo Community Association (OCA)", + 'website': 'http://www.github.com/OCA/report-print-send', + 'license': 'AGPL-3', + "depends": ['base_remote', 'base_report_to_printer'], + 'data': [ + 'data/printing_data.xml', + 'security/ir.model.access.csv', + 'views/res_remote_views.xml', + 'views/res_remote_printer_views.xml', + ], + 'installable': True, +} diff --git a/remote_report_to_printer/data/printing_data.xml b/remote_report_to_printer/data/printing_data.xml new file mode 100644 index 0000000..9bf8c12 --- /dev/null +++ b/remote_report_to_printer/data/printing_data.xml @@ -0,0 +1,13 @@ + + + + + Use Remote Defaults + remote_default + + + + Use User Defaults + user_default + + diff --git a/remote_report_to_printer/i18n/es.po b/remote_report_to_printer/i18n/es.po new file mode 100644 index 0000000..788245b --- /dev/null +++ b/remote_report_to_printer/i18n/es.po @@ -0,0 +1,129 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * remote_report_to_printer +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2018-11-16 20:19+0000\n" +"Last-Translator: Enric Tobella \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 3.2.2\n" + +#. module: remote_report_to_printer +#: sql_constraint:res.remote.printer:0 +msgid "A Remote cannot have the same printer for the same usage" +msgstr "El remoto no puede repetir la misma impresora para el mismo uso" + +#. module: remote_report_to_printer +#: model:ir.model.fields,field_description:remote_report_to_printer.field_res_remote_printer_create_uid +msgid "Created by" +msgstr "Creado por" + +#. module: remote_report_to_printer +#: model:ir.model.fields,field_description:remote_report_to_printer.field_res_remote_printer_create_date +msgid "Created on" +msgstr "Creado en" + +#. module: remote_report_to_printer +#: model:ir.model.fields,field_description:remote_report_to_printer.field_res_remote_printer_display_name +msgid "Display Name" +msgstr "Nombre mostrado" + +#. module: remote_report_to_printer +#: model:ir.model.fields,field_description:remote_report_to_printer.field_res_remote_printer_id +msgid "ID" +msgstr "ID" + +#. module: remote_report_to_printer +#: model:ir.model.fields,field_description:remote_report_to_printer.field_res_remote_printer_is_default +msgid "Is Default" +msgstr "Por defecto" + +#. module: remote_report_to_printer +#: model:ir.model.fields,field_description:remote_report_to_printer.field_res_remote_printer___last_update +msgid "Last Modified on" +msgstr "Última modificación el" + +#. module: remote_report_to_printer +#: model:ir.model.fields,field_description:remote_report_to_printer.field_res_remote_printer_write_uid +msgid "Last Updated by" +msgstr "Última actualización por" + +#. module: remote_report_to_printer +#: model:ir.model.fields,field_description:remote_report_to_printer.field_res_remote_printer_write_date +msgid "Last Updated on" +msgstr "Última actualización el" + +#. module: remote_report_to_printer +#: code:addons/remote_report_to_printer/models/res_remote_printer.py:48 +#, python-format +msgid "Only one default printer is allowed" +msgstr "Sólo se permite una impresora por defecto" + +#. module: remote_report_to_printer +#: model:ir.model,name:remote_report_to_printer.model_printing_action +msgid "Print Job Action" +msgstr "Acción de imprimir un trabajo" + +#. module: remote_report_to_printer +#: model:ir.model.fields,field_description:remote_report_to_printer.field_res_remote_printer_printer_id +msgid "Printer" +msgstr "Impresora" + +#. module: remote_report_to_printer +#: model:ir.model.fields,field_description:remote_report_to_printer.field_res_remote_printer_printer_tray_id +msgid "Printer Tray" +msgstr "Bandeja de impresora" + +#. module: remote_report_to_printer +#: model:ir.model.fields,field_description:remote_report_to_printer.field_res_remote_printer_printer_usage +msgid "Printer Usage" +msgstr "Uso de impresora" + +#. module: remote_report_to_printer +#: model:ir.ui.view,arch_db:remote_report_to_printer.res_remote_form +msgid "Printers" +msgstr "Impresoras" + +#. module: remote_report_to_printer +#: model:ir.model.fields,field_description:remote_report_to_printer.field_res_remote_printer_remote_id +msgid "Remote" +msgstr "Remoto" + +#. module: remote_report_to_printer +#: model:ir.model.fields,field_description:remote_report_to_printer.field_res_remote_remote_printer_ids +#: model:ir.ui.view,arch_db:remote_report_to_printer.res_remote_printer_form +msgid "Remote Printer" +msgstr "Impresora de remoto" + +#. module: remote_report_to_printer +#: model:ir.ui.view,arch_db:remote_report_to_printer.res_remote_printer_tree +msgid "Remote Printers" +msgstr "Impresoras de remoto" + +#. module: remote_report_to_printer +#: model:ir.model,name:remote_report_to_printer.model_res_remote +msgid "Remotes" +msgstr "Remotos" + +#. module: remote_report_to_printer +#: selection:res.remote.printer,printer_usage:0 +msgid "Standard" +msgstr "Estándar" + +#. module: remote_report_to_printer +#: model:ir.model,name:remote_report_to_printer.model_ir_actions_report +msgid "ir.actions.report" +msgstr "ir.actions.report" + +#. module: remote_report_to_printer +#: model:ir.model,name:remote_report_to_printer.model_res_remote_printer +msgid "res.remote.printer" +msgstr "res.remote.printer" diff --git a/remote_report_to_printer/i18n/remote_report_to_printer.pot b/remote_report_to_printer/i18n/remote_report_to_printer.pot new file mode 100644 index 0000000..c6a6d9c --- /dev/null +++ b/remote_report_to_printer/i18n/remote_report_to_printer.pot @@ -0,0 +1,127 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * remote_report_to_printer +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: \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: remote_report_to_printer +#: sql_constraint:res.remote.printer:0 +msgid "A Remote cannot have the same printer for the same usage" +msgstr "" + +#. module: remote_report_to_printer +#: model:ir.model.fields,field_description:remote_report_to_printer.field_res_remote_printer_create_uid +msgid "Created by" +msgstr "" + +#. module: remote_report_to_printer +#: model:ir.model.fields,field_description:remote_report_to_printer.field_res_remote_printer_create_date +msgid "Created on" +msgstr "" + +#. module: remote_report_to_printer +#: model:ir.model.fields,field_description:remote_report_to_printer.field_res_remote_printer_display_name +msgid "Display Name" +msgstr "" + +#. module: remote_report_to_printer +#: model:ir.model.fields,field_description:remote_report_to_printer.field_res_remote_printer_id +msgid "ID" +msgstr "" + +#. module: remote_report_to_printer +#: model:ir.model.fields,field_description:remote_report_to_printer.field_res_remote_printer_is_default +msgid "Is Default" +msgstr "" + +#. module: remote_report_to_printer +#: model:ir.model.fields,field_description:remote_report_to_printer.field_res_remote_printer___last_update +msgid "Last Modified on" +msgstr "" + +#. module: remote_report_to_printer +#: model:ir.model.fields,field_description:remote_report_to_printer.field_res_remote_printer_write_uid +msgid "Last Updated by" +msgstr "" + +#. module: remote_report_to_printer +#: model:ir.model.fields,field_description:remote_report_to_printer.field_res_remote_printer_write_date +msgid "Last Updated on" +msgstr "" + +#. module: remote_report_to_printer +#: code:addons/remote_report_to_printer/models/res_remote_printer.py:48 +#, python-format +msgid "Only one default printer is allowed" +msgstr "" + +#. module: remote_report_to_printer +#: model:ir.model,name:remote_report_to_printer.model_printing_action +msgid "Print Job Action" +msgstr "" + +#. module: remote_report_to_printer +#: model:ir.model.fields,field_description:remote_report_to_printer.field_res_remote_printer_printer_id +msgid "Printer" +msgstr "" + +#. module: remote_report_to_printer +#: model:ir.model.fields,field_description:remote_report_to_printer.field_res_remote_printer_printer_tray_id +msgid "Printer Tray" +msgstr "" + +#. module: remote_report_to_printer +#: model:ir.model.fields,field_description:remote_report_to_printer.field_res_remote_printer_printer_usage +msgid "Printer Usage" +msgstr "" + +#. module: remote_report_to_printer +#: model:ir.ui.view,arch_db:remote_report_to_printer.res_remote_form +msgid "Printers" +msgstr "" + +#. module: remote_report_to_printer +#: model:ir.model.fields,field_description:remote_report_to_printer.field_res_remote_printer_remote_id +msgid "Remote" +msgstr "" + +#. module: remote_report_to_printer +#: model:ir.model.fields,field_description:remote_report_to_printer.field_res_remote_remote_printer_ids +#: model:ir.ui.view,arch_db:remote_report_to_printer.res_remote_printer_form +msgid "Remote Printer" +msgstr "" + +#. module: remote_report_to_printer +#: model:ir.ui.view,arch_db:remote_report_to_printer.res_remote_printer_tree +msgid "Remote Printers" +msgstr "" + +#. module: remote_report_to_printer +#: model:ir.model,name:remote_report_to_printer.model_res_remote +msgid "Remotes" +msgstr "" + +#. module: remote_report_to_printer +#: selection:res.remote.printer,printer_usage:0 +msgid "Standard" +msgstr "" + +#. module: remote_report_to_printer +#: model:ir.model,name:remote_report_to_printer.model_ir_actions_report +msgid "ir.actions.report" +msgstr "" + +#. module: remote_report_to_printer +#: model:ir.model,name:remote_report_to_printer.model_res_remote_printer +msgid "res.remote.printer" +msgstr "" + diff --git a/remote_report_to_printer/models/__init__.py b/remote_report_to_printer/models/__init__.py new file mode 100644 index 0000000..d17f81d --- /dev/null +++ b/remote_report_to_printer/models/__init__.py @@ -0,0 +1,4 @@ +from . import ir_actions_report +from . import res_remote +from . import res_remote_printer +from . import printing_action diff --git a/remote_report_to_printer/models/ir_actions_report.py b/remote_report_to_printer/models/ir_actions_report.py new file mode 100644 index 0000000..417d86e --- /dev/null +++ b/remote_report_to_printer/models/ir_actions_report.py @@ -0,0 +1,22 @@ +# Copyright (c) 2018 Creu Blanca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class IrActionsReport(models.Model): + _inherit = 'ir.actions.report' + + @api.multi + def _get_user_default_print_behaviour(self): + res = super()._get_user_default_print_behaviour() + if res.get('action', 'unknown') == 'remote_default': + res.update(self.remote.get_printer_behaviour()) + return res + + @api.multi + def _get_report_default_print_behaviour(self): + res = super()._get_report_default_print_behaviour() + if res.get('action', 'unknown') == 'remote_default': + res.update(self.remote.get_printer_behaviour()) + return res diff --git a/remote_report_to_printer/models/printing_action.py b/remote_report_to_printer/models/printing_action.py new file mode 100644 index 0000000..c6f4618 --- /dev/null +++ b/remote_report_to_printer/models/printing_action.py @@ -0,0 +1,18 @@ +# Copyright (c) 2018 Creu Blanca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class PrintingAction(models.Model): + _inherit = 'printing.action' + + @api.model + def _available_action_types(self): + res = super()._available_action_types() + res.append(('remote_default', "Use remote's default")) + return res + + action_type = fields.Selection( + selection=_available_action_types, + ) diff --git a/remote_report_to_printer/models/res_remote.py b/remote_report_to_printer/models/res_remote.py new file mode 100644 index 0000000..4a961f3 --- /dev/null +++ b/remote_report_to_printer/models/res_remote.py @@ -0,0 +1,28 @@ +# Copyright (c) 2018 Creu Blanca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import api, fields, models + + +class ResRemote(models.Model): + _inherit = 'res.remote' + + remote_printer_ids = fields.One2many( + 'res.remote.printer', + inverse_name='remote_id', + ) + + @api.multi + def get_printer_behaviour(self): + self.ensure_one() + printer_usage = self.env.context.get('printer_usage', 'standard') + printers = self.remote.remote_printer_ids.filtered( + lambda r: r.printer_usage == printer_usage + ).sorted(key='is_default', reverse=True) + if printers: + printer = printers[0] + return { + 'action': 'server', + 'printer': printer.printer_id, + 'tray': printer.printer_tray_id.system_name + } + return {'action': 'client'} diff --git a/remote_report_to_printer/models/res_remote_printer.py b/remote_report_to_printer/models/res_remote_printer.py new file mode 100644 index 0000000..5f86d7b --- /dev/null +++ b/remote_report_to_printer/models/res_remote_printer.py @@ -0,0 +1,49 @@ +# Copyright (c) 2018 Creu Blanca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import api, fields, models, _ +from odoo.exceptions import ValidationError + + +class ResRemotePrinter(models.Model): + _name = 'res.remote.printer' + _description = 'Remote Printer' + + remote_id = fields.Many2one( + 'res.remote', + ondelete='cascade', + readonly=True, + ) + printer_id = fields.Many2one( + 'printing.printer', + ondelete='cascade', + ) + printer_tray_id = fields.Many2one( + 'printing.tray', + ondelete='cascade', + domain="[('printer_id', '=', printer_id)]", + ) + is_default = fields.Boolean(default=False) + printer_usage = fields.Selection([ + ('standard', 'Standard') + ], default='standard') + + _sql_constraints = [ + ('unique_printer_remote_usage', + 'unique(remote_id,printer_id,printer_usage)', + 'A Remote cannot have the same printer for the same usage') + ] + + @api.onchange('printer_id') + def _onchange_printing_printer_id(self): + """ Reset the tray when the printer is changed """ + self.printer_tray_id = False + + @api.multi + @api.constrains('remote_id', 'printer_usage', 'is_default') + def _check_remote_usage(self): + for rec in self.filtered(lambda r: r.is_default): + if rec.remote_id.remote_printer_ids.filtered( + lambda r: r != rec and r.is_default + and r.printer_usage == rec.printer_usage + ): + raise ValidationError(_('Only one default printer is allowed')) diff --git a/remote_report_to_printer/readme/CONTRIBUTORS.rst b/remote_report_to_printer/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..93ec993 --- /dev/null +++ b/remote_report_to_printer/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Enric Tobella diff --git a/remote_report_to_printer/readme/DESCRIPTION.rst b/remote_report_to_printer/readme/DESCRIPTION.rst new file mode 100644 index 0000000..3aa0c75 --- /dev/null +++ b/remote_report_to_printer/readme/DESCRIPTION.rst @@ -0,0 +1,12 @@ +This module allows users to send reports to a printer using remote's configuration. + +A *remote* is an external entity that access odoo. For example, computers, mobiles, +servers... We will identify *remotes* by its name or ip. On some environments, +we want to configure the printers by remote, because users may change their +work place. + +It adds an optional behaviour on reports to send it directly to a printer. + +* `Use remote's configuration` use the remote's behaviour + +Also, this option can be selected as a user default option for printer. diff --git a/remote_report_to_printer/readme/USAGE.rst b/remote_report_to_printer/readme/USAGE.rst new file mode 100644 index 0000000..b923702 --- /dev/null +++ b/remote_report_to_printer/readme/USAGE.rst @@ -0,0 +1 @@ + * In *Settings > Remotes* configure the remotes printers by usage diff --git a/remote_report_to_printer/security/ir.model.access.csv b/remote_report_to_printer/security/ir.model.access.csv new file mode 100644 index 0000000..00cfc41 --- /dev/null +++ b/remote_report_to_printer/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_remote,access_remote_printer,model_res_remote_printer,base.group_user,1,0,0,0 +manage_remote,manage_remote_printer,model_res_remote_printer,base.group_system,1,1,1,1 diff --git a/remote_report_to_printer/static/description/icon.png b/remote_report_to_printer/static/description/icon.png new file mode 100644 index 0000000..3a0328b Binary files /dev/null and b/remote_report_to_printer/static/description/icon.png differ diff --git a/remote_report_to_printer/tests/__init__.py b/remote_report_to_printer/tests/__init__.py new file mode 100644 index 0000000..8555121 --- /dev/null +++ b/remote_report_to_printer/tests/__init__.py @@ -0,0 +1,2 @@ +from . import test_remote_printer +from . import test_printer diff --git a/remote_report_to_printer/tests/test_printer.py b/remote_report_to_printer/tests/test_printer.py new file mode 100644 index 0000000..27677b2 --- /dev/null +++ b/remote_report_to_printer/tests/test_printer.py @@ -0,0 +1,106 @@ +# Copyright (c) 2018 Creu Blanca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo.tests.common import TransactionCase +from mock import patch + + +class TestRemotePrinter(TransactionCase): + + def setUp(self): + super().setUp() + name = 'testing_remote_server' + self.remote = self.env['res.remote'].search([('name', '=', name)]) + if not self.remote: + self.remote = self.env['res.remote'].create({ + 'name': name, + 'ip': '127.0.0.1', + }) + self.server = self.env['printing.server'].create({ + 'name': 'Server', + 'address': 'localhost', + 'port': 631, + }) + self.printer_1 = self.env['printing.printer'].create({ + 'name': 'Printer 1', + 'system_name': 'P1', + 'server_id': self.server.id, + }) + self.remote_printer = self.env['res.remote.printer'].create({ + 'remote_id': self.remote.id, + 'printer_id': self.printer_1.id, + 'is_default': True, + }) + self.Model = self.env['ir.actions.report'] + self.report = self.env['ir.actions.report'].search([], limit=1) + + def test_behaviour_user_remote_values(self): + report = self.Model.search([], limit=1) + self.env.user.printing_action = 'remote_default' + with patch( + 'odoo.addons.base_remote.models.base.Base.remote', new=self.remote + ): + behaviour = report.behaviour() + self.assertEqual(behaviour, { + 'action': 'client', + 'printer': self.printer_1, + 'tray': False, + }) + + def test_behaviour_report_values(self): + report = self.Model.search([], limit=1) + self.env.user.printing_action = 'client' + report.property_printing_action_id = self.browse_ref( + 'remote_report_to_printer.printing_action_remote' + ) + with patch( + 'odoo.addons.base_remote.models.base.Base.remote', new=self.remote + ): + behaviour = report.behaviour() + self.assertDictEqual(behaviour, { + 'action': 'server', + 'printer': self.printer_1, + 'tray': False, + }) + + def test_behaviour_user_action(self): + report = self.Model.search([], limit=1) + self.env.user.printing_action = 'remote_default' + report.property_printing_action_id = self.browse_ref( + 'remote_report_to_printer.printing_action_3' + ) + with patch( + 'odoo.addons.base_remote.models.base.Base.remote', new=self.remote + ): + behaviour = report.behaviour() + self.assertEqual(behaviour, { + 'action': 'server', + 'printer': self.printer_1, + 'tray': False, + }) + + def test_behaviour_default_action(self): + report = self.Model.search([], limit=1) + self.env.user.printing_action = 'client' + with patch( + 'odoo.addons.base_remote.models.base.Base.remote', new=self.remote + ): + behaviour = report.behaviour() + self.assertEqual(behaviour, { + 'action': 'client', + 'printer': self.env['printing.printer'], + 'tray': False, + }) + + def test_behaviour_no_printers(self): + self.remote_printer.unlink() + report = self.Model.search([], limit=1) + self.env.user.printing_action = 'remote_default' + report.property_printing_action_id = self.browse_ref( + 'remote_report_to_printer.printing_action_3' + ) + with patch( + 'odoo.addons.base_remote.models.base.Base.remote', + new=self.remote + ): + behaviour = report.behaviour() + self.assertEqual(behaviour['action'], 'client') diff --git a/remote_report_to_printer/tests/test_remote_printer.py b/remote_report_to_printer/tests/test_remote_printer.py new file mode 100644 index 0000000..a76a857 --- /dev/null +++ b/remote_report_to_printer/tests/test_remote_printer.py @@ -0,0 +1,115 @@ +# Copyright (c) 2018 Creu Blanca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo.tests.common import TransactionCase +from odoo.exceptions import ValidationError +from odoo.exceptions import AccessError + + +class TestRemotePrinter(TransactionCase): + + def setUp(self): + super().setUp() + self.system_user_group = self.env.ref('base.group_system') + self.user_group = self.env.ref('base.group_user') + self.printer_manager = self._create_user('printer_manager', + self.system_user_group.id) + self.printer_user = self._create_user('printer_user', + self.user_group.id) + + name = 'testing_remote_server' + self.remote = self.env['res.remote'].search([('name', '=', name)]) + if not self.remote: + self.remote = self.env['res.remote'].create({ + 'name': name, + 'ip': '127.0.0.1', + }) + self.server = self.env['printing.server'].create({ + 'name': 'Server', + 'address': 'localhost', + 'port': 631, + }) + self.printer_1 = self.env['printing.printer'].create({ + 'name': 'Printer 1', + 'system_name': 'P1', + 'server_id': self.server.id, + }) + self.printer_2 = self.env['printing.printer'].create({ + 'name': 'Printer 2', + 'system_name': 'P2', + 'server_id': self.server.id, + }) + self.tray_1 = self.env['printing.tray'].create({ + 'name': 'Tray', + 'system_name': 'P2', + 'printer_id': self.printer_1.id, + }) + + def _create_user(self, name, group_ids): + return self.env['res.users'].with_context( + {'no_reset_password': True}).create( + {'name': name, + 'password': 'demo', + 'login': name, + 'email': '@'.join([name, '@test.com']), + 'groups_id': [(6, 0, [group_ids])] + }) + + def test_constrain(self): + self.env['res.remote.printer'].sudo(self.printer_manager).create({ + 'remote_id': self.remote.id, + 'printer_id': self.printer_1.id, + 'is_default': True, + }) + with self.assertRaises(ValidationError): + self.env['res.remote.printer'].create({ + 'remote_id': self.remote.id, + 'printer_id': self.printer_2.id, + 'is_default': True, + }) + + def test_onchange_printer(self): + remote_printer = self.env['res.remote.printer'].sudo( + self.printer_manager).create({ + 'remote_id': self.remote.id, + 'printer_id': self.printer_1.id, + 'printer_tray_id': self.tray_1.id, + }) + self.assertTrue(remote_printer.printer_tray_id) + remote_printer.printer_id = self.printer_2 + remote_printer._onchange_printing_printer_id() + self.assertFalse(remote_printer.printer_tray_id) + + def test_permissions_delete_manager(self): + printer = self.env['res.remote.printer'].sudo( + self.printer_manager).create({ + 'remote_id': self.remote.id, + 'printer_id': self.printer_1.id, + 'is_default': True, + } + ) + printer.sudo(self.printer_manager).unlink() + printer = self.env['res.remote.printer'].search([ + ('remote_id', '=', self.remote.id), + ('printer_id', '=', self.printer_1.id)], limit=1) + self.assertEquals(printer, self.env['res.remote.printer']) + + def test_permissions_delete_user(self): + printer = self.env['res.remote.printer'].sudo( + self.printer_manager).create({ + 'remote_id': self.remote.id, + 'printer_id': self.printer_1.id, + 'is_default': True, + } + ) + with self.assertRaises(AccessError): + printer.sudo(self.printer_user).unlink() + + def test_permissions_create_user(self): + with self.assertRaises(AccessError): + self.env['res.remote.printer'].sudo( + self.printer_user).create({ + 'remote_id': self.remote.id, + 'printer_id': self.printer_1.id, + 'is_default': True, + } + ) diff --git a/remote_report_to_printer/views/res_remote_printer_views.xml b/remote_report_to_printer/views/res_remote_printer_views.xml new file mode 100644 index 0000000..d745918 --- /dev/null +++ b/remote_report_to_printer/views/res_remote_printer_views.xml @@ -0,0 +1,33 @@ + + + + res.remote.printer.form + res.remote.printer + +
+ + + + + + + + + +
+
+
+ + res.remote.printer.tree + res.remote.printer + + + + + + + + + + +
diff --git a/remote_report_to_printer/views/res_remote_views.xml b/remote_report_to_printer/views/res_remote_views.xml new file mode 100644 index 0000000..6023035 --- /dev/null +++ b/remote_report_to_printer/views/res_remote_views.xml @@ -0,0 +1,15 @@ + + + + res.remote.form + res.remote + + + + + + + + + +