diff --git a/base_report_to_printer_mail/README.rst b/base_report_to_printer_mail/README.rst new file mode 100644 index 0000000..0697ed1 --- /dev/null +++ b/base_report_to_printer_mail/README.rst @@ -0,0 +1,74 @@ +================================== +Report to printer - Mail extension +================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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/base_report_to_printer_mail + :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-base_report_to_printer_mail + :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 disables the print of a report on a selected printer, +when the report has been triggered from a mail template. + +**Table of contents** + +.. contents:: + :local: + +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 +~~~~~~~ + +* DynApps NV + +Contributors +~~~~~~~~~~~~ + +* Raf Ven + +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/base_report_to_printer_mail/__init__.py b/base_report_to_printer_mail/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/base_report_to_printer_mail/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/base_report_to_printer_mail/__manifest__.py b/base_report_to_printer_mail/__manifest__.py new file mode 100644 index 0000000..0ee0fc3 --- /dev/null +++ b/base_report_to_printer_mail/__manifest__.py @@ -0,0 +1,18 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': "Report to printer - Mail extension", + 'version': '12.0.1.0.0', + 'category': 'Generic Modules/Base', + 'author': "DynApps NV, Odoo Community Association (OCA)", + 'website': 'https://github.com/OCA/report-print-send', + 'license': 'AGPL-3', + "depends": [ + 'mail', + 'base_report_to_printer', + ], + 'data': [ + ], + 'installable': True, + 'auto_install': True, +} diff --git a/base_report_to_printer_mail/models/__init__.py b/base_report_to_printer_mail/models/__init__.py new file mode 100644 index 0000000..44e8395 --- /dev/null +++ b/base_report_to_printer_mail/models/__init__.py @@ -0,0 +1 @@ +from . import mail_template diff --git a/base_report_to_printer_mail/models/mail_template.py b/base_report_to_printer_mail/models/mail_template.py new file mode 100644 index 0000000..6acfd3e --- /dev/null +++ b/base_report_to_printer_mail/models/mail_template.py @@ -0,0 +1,10 @@ +from odoo import models + + +class MailTemplate(models.Model): + _inherit = "mail.template" + + def generate_email(self, res_ids, fields=None): + return super(MailTemplate, self.with_context( + must_skip_send_to_printer=True + )).generate_email(res_ids, fields=fields) diff --git a/base_report_to_printer_mail/readme/CONTRIBUTORS.rst b/base_report_to_printer_mail/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..7937831 --- /dev/null +++ b/base_report_to_printer_mail/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Raf Ven diff --git a/base_report_to_printer_mail/readme/DESCRIPTION.rst b/base_report_to_printer_mail/readme/DESCRIPTION.rst new file mode 100644 index 0000000..e4f70c3 --- /dev/null +++ b/base_report_to_printer_mail/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module disables the print of a report on a selected printer, +when the report has been triggered from a mail template. diff --git a/base_report_to_printer_mail/static/description/icon.png b/base_report_to_printer_mail/static/description/icon.png new file mode 100644 index 0000000..3a0328b Binary files /dev/null and b/base_report_to_printer_mail/static/description/icon.png differ diff --git a/base_report_to_printer_mail/static/description/index.html b/base_report_to_printer_mail/static/description/index.html new file mode 100644 index 0000000..db54ecd --- /dev/null +++ b/base_report_to_printer_mail/static/description/index.html @@ -0,0 +1,420 @@ + + + + + + +Report to printer - Mail extension + + + +
+

Report to printer - Mail extension

+ + +

Beta License: AGPL-3 OCA/report-print-send Translate me on Weblate Try me on Runbot

+

This module disables the print of a report on a selected printer, +when the report has been triggered from a mail template.

+

Table of contents

+ +
+

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

+
    +
  • DynApps NV
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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/base_report_to_printer_mail/tests/__init__.py b/base_report_to_printer_mail/tests/__init__.py new file mode 100644 index 0000000..fde6ca0 --- /dev/null +++ b/base_report_to_printer_mail/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import test_mail diff --git a/base_report_to_printer_mail/tests/test_mail.py b/base_report_to_printer_mail/tests/test_mail.py new file mode 100644 index 0000000..8149ccd --- /dev/null +++ b/base_report_to_printer_mail/tests/test_mail.py @@ -0,0 +1,82 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import mock +from odoo.tests import common + + +@common.at_install(False) +@common.post_install(True) +class TestMail(common.HttpCase): + def setUp(self): + super(TestMail, self).setUp() + self.Model = self.env['ir.model'] + self.report_obj = self.env['ir.actions.report'] + self.partner_obj = self.env['res.partner'] + self.mail_template_obj = self.env['mail.template'] + self.res_partner_model = \ + self.Model.search([('model', '=', 'res.partner')]) + self.server = self.env['printing.server'].create({}) + self.report_imd = self.env["ir.model.data"].create({ + "name": "test", + "module": "base_report_to_printer", + "model": "ir.ui.view", + }) + self.report_view = self.env["ir.ui.view"].create({ + "name": "Test", + "type": "qweb", + "xml_id": "base_report_to_printer.test", + "model_data_id": self.report_imd.id, + "arch": """ +
Test
+
""", + }) + self.report_imd.res_id = self.report_view.id + self.report = self.report_obj.create({ + "name": "Test", + "report_type": "qweb-pdf", + "model": "res.partner", + "report_name": "base_report_to_printer.test", + }) + self.test_partner = self.partner_obj.create({ + 'name': 'TestingPartner', + 'city': 'OrigCity', + }) + self.email_template = self.mail_template_obj.create({ + 'name': 'TestTemplate', + 'email_from': 'myself@example.com', + 'email_to': 'brigitte@example.com', + 'partner_to': '%s' % self.test_partner.id, + 'model_id': self.res_partner_model.id, + 'subject': 'About ${object.name}', + 'body_html': + '

Dear ${object.name}, ' + 'your parent is ${object.parent_id and ' + 'object.parent_id.name or "False"}

', + 'report_template': self.report.id, + }) + + def new_printer(self): + return self.env['printing.printer'].create({ + 'name': 'Printer', + 'server_id': self.server.id, + 'system_name': 'Sys Name', + 'default': True, + 'status': 'unknown', + 'status_message': 'Msg', + 'model': 'res.users', + 'location': 'Location', + 'uri': 'URI', + }) + + def test_generate_email(self): + """ + It should NOT print the report, + regardless of the defined behaviour + """ + self.report.property_printing_action_id.action_type = 'server' + self.report.printing_printer_id = self.new_printer() + with mock.patch('odoo.addons.base_report_to_printer.models.' + 'printing_printer.PrintingPrinter.' + 'print_document') as print_document: + self.email_template.generate_email(self.test_partner.id) + print_document.assert_not_called()