mirror of
https://github.com/OCA/report-print-send.git
synced 2025-02-16 07:11:31 +02:00
[IMP] base_report_to_printer_mail: black, isort, prettier
This commit is contained in:
@@ -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,
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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,19 +10,17 @@ 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",
|
{
|
||||||
})
|
|
||||||
self.report_view = self.env["ir.ui.view"].create({
|
|
||||||
"name": "Test",
|
"name": "Test",
|
||||||
"type": "qweb",
|
"type": "qweb",
|
||||||
"xml_id": "base_report_to_printer.test",
|
"xml_id": "base_report_to_printer.test",
|
||||||
@@ -29,54 +28,61 @@ class TestMail(common.HttpCase):
|
|||||||
"arch": """<t t-name="base_report_to_printer.test">
|
"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",
|
"name": "Test",
|
||||||
"report_type": "qweb-pdf",
|
"report_type": "qweb-pdf",
|
||||||
"model": "res.partner",
|
"model": "res.partner",
|
||||||
"report_name": "base_report_to_printer.test",
|
"report_name": "base_report_to_printer.test",
|
||||||
})
|
}
|
||||||
self.test_partner = self.partner_obj.create({
|
)
|
||||||
'name': 'TestingPartner',
|
self.test_partner = self.partner_obj.create(
|
||||||
'city': 'OrigCity',
|
{"name": "TestingPartner", "city": "OrigCity"}
|
||||||
})
|
)
|
||||||
self.email_template = self.mail_template_obj.create({
|
self.email_template = self.mail_template_obj.create(
|
||||||
'name': 'TestTemplate',
|
{
|
||||||
'email_from': 'myself@example.com',
|
"name": "TestTemplate",
|
||||||
'email_to': 'brigitte@example.com',
|
"email_from": "myself@example.com",
|
||||||
'partner_to': '%s' % self.test_partner.id,
|
"email_to": "brigitte@example.com",
|
||||||
'model_id': self.res_partner_model.id,
|
"partner_to": "%s" % self.test_partner.id,
|
||||||
'subject': 'About ${object.name}',
|
"model_id": self.res_partner_model.id,
|
||||||
'body_html':
|
"subject": "About ${object.name}",
|
||||||
'<p>Dear ${object.name}, '
|
"body_html": "<p>Dear ${object.name}, "
|
||||||
'your parent is ${object.parent_id and '
|
"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()
|
||||||
|
|||||||
Reference in New Issue
Block a user