[IMP] base_report_to_printer_mail: black, isort, prettier

This commit is contained in:
Jaime Arroyo
2020-09-29 12:45:51 +02:00
committed by User
parent ea3e05be75
commit 831c5ff9b2
3 changed files with 75 additions and 73 deletions

View File

@@ -1,18 +1,14 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{ {
'name': "Report to printer - Mail extension", "name": "Report to printer - Mail extension",
'version': '12.0.1.0.0', "version": "12.0.1.0.0",
'category': 'Generic Modules/Base', "category": "Generic Modules/Base",
'author': "DynApps NV, Odoo Community Association (OCA)", "author": "DynApps NV, Odoo Community Association (OCA)",
'website': 'https://github.com/OCA/report-print-send', "website": "https://github.com/OCA/report-print-send",
'license': 'AGPL-3', "license": "AGPL-3",
"depends": [ "depends": ["mail", "base_report_to_printer"],
'mail', "data": [],
'base_report_to_printer', "installable": True,
], "auto_install": True,
'data': [
],
'installable': True,
'auto_install': True,
} }

View File

@@ -5,6 +5,6 @@ class MailTemplate(models.Model):
_inherit = "mail.template" _inherit = "mail.template"
def generate_email(self, res_ids, fields=None): def generate_email(self, res_ids, fields=None):
return super(MailTemplate, self.with_context( return super(
must_skip_send_to_printer=True MailTemplate, self.with_context(must_skip_send_to_printer=True)
)).generate_email(res_ids, fields=fields) ).generate_email(res_ids, fields=fields)

View File

@@ -1,6 +1,7 @@
# 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 mock import mock
from odoo.tests import common from odoo.tests import common
@@ -9,74 +10,79 @@ from odoo.tests import common
class TestMail(common.HttpCase): class TestMail(common.HttpCase):
def setUp(self): def setUp(self):
super(TestMail, self).setUp() super(TestMail, self).setUp()
self.Model = self.env['ir.model'] self.Model = self.env["ir.model"]
self.report_obj = self.env['ir.actions.report'] self.report_obj = self.env["ir.actions.report"]
self.partner_obj = self.env['res.partner'] self.partner_obj = self.env["res.partner"]
self.mail_template_obj = self.env['mail.template'] self.mail_template_obj = self.env["mail.template"]
self.res_partner_model = \ self.res_partner_model = self.Model.search([("model", "=", "res.partner")])
self.Model.search([('model', '=', 'res.partner')]) self.server = self.env["printing.server"].create({})
self.server = self.env['printing.server'].create({}) self.report_imd = self.env["ir.model.data"].create(
self.report_imd = self.env["ir.model.data"].create({ {"name": "test", "module": "base_report_to_printer", "model": "ir.ui.view"}
"name": "test", )
"module": "base_report_to_printer", self.report_view = self.env["ir.ui.view"].create(
"model": "ir.ui.view", {
}) "name": "Test",
self.report_view = self.env["ir.ui.view"].create({ "type": "qweb",
"name": "Test", "xml_id": "base_report_to_printer.test",
"type": "qweb", "model_data_id": self.report_imd.id,
"xml_id": "base_report_to_printer.test", "arch": """<t t-name="base_report_to_printer.test">
"model_data_id": self.report_imd.id,
"arch": """<t t-name="base_report_to_printer.test">
<div>Test</div> <div>Test</div>
</t>""", </t>""",
}) }
)
self.report_imd.res_id = self.report_view.id self.report_imd.res_id = self.report_view.id
self.report = self.report_obj.create({ self.report = self.report_obj.create(
"name": "Test", {
"report_type": "qweb-pdf", "name": "Test",
"model": "res.partner", "report_type": "qweb-pdf",
"report_name": "base_report_to_printer.test", "model": "res.partner",
}) "report_name": "base_report_to_printer.test",
self.test_partner = self.partner_obj.create({ }
'name': 'TestingPartner', )
'city': 'OrigCity', self.test_partner = self.partner_obj.create(
}) {"name": "TestingPartner", "city": "OrigCity"}
self.email_template = self.mail_template_obj.create({ )
'name': 'TestTemplate', self.email_template = self.mail_template_obj.create(
'email_from': 'myself@example.com', {
'email_to': 'brigitte@example.com', "name": "TestTemplate",
'partner_to': '%s' % self.test_partner.id, "email_from": "myself@example.com",
'model_id': self.res_partner_model.id, "email_to": "brigitte@example.com",
'subject': 'About ${object.name}', "partner_to": "%s" % self.test_partner.id,
'body_html': "model_id": self.res_partner_model.id,
'<p>Dear ${object.name}, ' "subject": "About ${object.name}",
'your parent is ${object.parent_id and ' "body_html": "<p>Dear ${object.name}, "
"your parent is ${object.parent_id and "
'object.parent_id.name or "False"}</p>', 'object.parent_id.name or "False"}</p>',
'report_template': self.report.id, "report_template": self.report.id,
}) }
)
def new_printer(self): def new_printer(self):
return self.env['printing.printer'].create({ return self.env["printing.printer"].create(
'name': 'Printer', {
'server_id': self.server.id, "name": "Printer",
'system_name': 'Sys Name', "server_id": self.server.id,
'default': True, "system_name": "Sys Name",
'status': 'unknown', "default": True,
'status_message': 'Msg', "status": "unknown",
'model': 'res.users', "status_message": "Msg",
'location': 'Location', "model": "res.users",
'uri': 'URI', "location": "Location",
}) "uri": "URI",
}
)
def test_generate_email(self): def test_generate_email(self):
""" """
It should NOT print the report, It should NOT print the report,
regardless of the defined behaviour regardless of the defined behaviour
""" """
self.report.property_printing_action_id.action_type = 'server' self.report.property_printing_action_id.action_type = "server"
self.report.printing_printer_id = self.new_printer() self.report.printing_printer_id = self.new_printer()
with mock.patch('odoo.addons.base_report_to_printer.models.' with mock.patch(
'printing_printer.PrintingPrinter.' "odoo.addons.base_report_to_printer.models."
'print_document') as print_document: "printing_printer.PrintingPrinter."
"print_document"
) as print_document:
self.email_template.generate_email(self.test_partner.id) self.email_template.generate_email(self.test_partner.id)
print_document.assert_not_called() print_document.assert_not_called()