Thomas Binsfeld
8 years ago
13 changed files with 346 additions and 0 deletions
-
60mail_as_letter/README.rst
-
1mail_as_letter/__init__.py
-
22mail_as_letter/__openerp__.py
-
48mail_as_letter/report/mail_as_letter_qweb.xml
-
79mail_as_letter/static/description/icon.svg
-
1mail_as_letter/tests/__init__.py
-
54mail_as_letter/tests/test_mail_as_letter.py
-
1mail_as_letter/wizards/__init__.py
-
45mail_as_letter/wizards/mail_compose_message.py
-
27mail_as_letter/wizards/mail_compose_message.xml
-
1setup/mail_as_letter/odoo_addons/__init__.py
-
1setup/mail_as_letter/odoo_addons/mail_as_letter
-
6setup/mail_as_letter/setup.py
@ -0,0 +1,60 @@ |
|||
.. 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 |
|||
|
|||
============== |
|||
Mail As Letter |
|||
============== |
|||
|
|||
This module allows to download a mail message as a pdf letter with formal layout. |
|||
|
|||
Usage |
|||
===== |
|||
|
|||
To use this module, you need to: |
|||
|
|||
#. Write a new email from the mail composer |
|||
#. Click on the print button to download the email as a pdf file |
|||
|
|||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas |
|||
:alt: Try me on Runbot |
|||
:target: https://runbot.odoo-community.org/runbot/{repo_id}/{branch} |
|||
|
|||
.. repo_id is available in https://github.com/OCA/maintainer-tools/blob/master/tools/repos_with_ids.txt |
|||
.. branch is "8.0" for example |
|||
|
|||
Bug Tracker |
|||
=========== |
|||
|
|||
Bugs are tracked on `GitHub Issues |
|||
<https://github.com/OCA/social/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. |
|||
|
|||
Credits |
|||
======= |
|||
|
|||
Images |
|||
------ |
|||
|
|||
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_. |
|||
|
|||
Contributors |
|||
------------ |
|||
|
|||
* Thomas Binsfeld <thomas.binsfeld@acsone.eu> |
|||
|
|||
Maintainer |
|||
---------- |
|||
|
|||
.. image:: https://odoo-community.org/logo.png |
|||
:alt: Odoo Community Association |
|||
:target: https://odoo-community.org |
|||
|
|||
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. |
|||
|
|||
To contribute to this module, please visit https://odoo-community.org. |
@ -0,0 +1 @@ |
|||
from . import wizards |
@ -0,0 +1,22 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Copyright 2016 ACSONE SA/NV |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
|
|||
{ |
|||
'name': 'Mail As Letter', |
|||
'summary': """ |
|||
This module allows to download a mail message as a pdf letter.""", |
|||
'version': '9.0.1.0.0', |
|||
'license': 'AGPL-3', |
|||
'author': 'ACSONE SA/NV,Odoo Community Association (OCA)', |
|||
'website': 'www.acsone.eu', |
|||
'depends': [ |
|||
'mail', |
|||
], |
|||
'data': [ |
|||
'wizards/mail_compose_message.xml', |
|||
'report/mail_as_letter_qweb.xml', |
|||
], |
|||
'demo': [ |
|||
], |
|||
} |
@ -0,0 +1,48 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<openerp> |
|||
<data> |
|||
|
|||
<record id="qweb_mail_pdf_export" model="ir.actions.report.xml"> |
|||
<field name="name">mail_as_letter</field> |
|||
<field name="model">mail.compose.message</field> |
|||
<field name="type">ir.actions.report.xml</field> |
|||
<field name="report_name">mail_as_letter.report_mail_print</field> |
|||
<field name="report_type">qweb-pdf</field> |
|||
<field name="paperformat_id" eval="ref('report.paperformat_euro')"/> |
|||
<field name="auto" eval="False"/> |
|||
</record> |
|||
|
|||
<template id="mail_print"> |
|||
<t t-call="report.external_layout"> |
|||
<div class="page"> |
|||
<div class="oe_structure"/> |
|||
<t t-foreach="o.partner_ids" t-as="p"> |
|||
<p> |
|||
<address t-field="o.partner_ids" |
|||
t-field-options='{"widget": "contact", |
|||
"fields": ["address", "name"], |
|||
"no_marker": true}' /> |
|||
</p> |
|||
</t> |
|||
<br/> |
|||
<p> |
|||
<b>Subject : <span t-field="o.subject" /></b> |
|||
</p> |
|||
<br/> |
|||
<p> |
|||
<span class="email_preview" t-raw="o.body" /> |
|||
</p> |
|||
</div> |
|||
</t> |
|||
</template> |
|||
|
|||
<template id="report_mail_print"> |
|||
<t t-call="report.html_container"> |
|||
<t t-foreach="docs" t-as="o"> |
|||
<t t-call="mail_as_letter.mail_print"/> |
|||
</t> |
|||
</t> |
|||
</template> |
|||
|
|||
</data> |
|||
</openerp> |
79
mail_as_letter/static/description/icon.svg
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1 @@ |
|||
from . import test_mail_as_letter |
@ -0,0 +1,54 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Copyright 2016 ACSONE SA/NV |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
|
|||
from openerp.tests.common import TransactionCase |
|||
from openerp.exceptions import UserError |
|||
|
|||
|
|||
class TestMailAsLetter(TransactionCase): |
|||
|
|||
def setUp(self): |
|||
super(TestMailAsLetter, self).setUp() |
|||
|
|||
# ENVIRONMENTS |
|||
self.mail_compose_message = self.env['mail.compose.message'] |
|||
|
|||
# INSTANCES |
|||
# Partners |
|||
self.base_partner = self.ref('base.main_partner') |
|||
self.root_partner = self.ref('base.partner_root') |
|||
# Mail compose message |
|||
self.mail_composer = self.mail_compose_message.create({ |
|||
'subject': "Test mail", |
|||
'body': "Blah blah blah"}) |
|||
|
|||
def test_compute_partner_count(self): |
|||
# No partner |
|||
self.mail_composer.update({ |
|||
'partner_ids': False}) |
|||
self.assertEqual(self.mail_composer.partner_count, 0) |
|||
# One partner |
|||
self.mail_composer.update({ |
|||
'partner_ids': [self.base_partner]}) |
|||
self.assertEqual(self.mail_composer.partner_count, 1) |
|||
# Two partners |
|||
self.mail_composer.update({ |
|||
'partner_ids': [self.base_partner, self.root_partner]}) |
|||
self.assertEqual(self.mail_composer.partner_count, 2) |
|||
|
|||
def test_download_pdf(self): |
|||
# With no partner |
|||
with self.assertRaises(UserError), self.cr.savepoint(): |
|||
self.mail_composer.update({ |
|||
'partner_ids': False}) |
|||
self.mail_composer.download_pdf() |
|||
# With more than one partner |
|||
with self.assertRaises(UserError), self.cr.savepoint(): |
|||
self.mail_composer.update({ |
|||
'partner_ids': [self.base_partner, self.root_partner]}) |
|||
self.mail_composer.download_pdf() |
|||
# With exactly one partner |
|||
self.mail_composer.update({ |
|||
'partner_ids': [self.base_partner]}) |
|||
self.mail_composer.download_pdf() |
@ -0,0 +1 @@ |
|||
from . import mail_compose_message |
@ -0,0 +1,45 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Copyright 2016 ACSONE SA/NV |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
|
|||
from openerp import api, fields, models, _ |
|||
from openerp.exceptions import UserError |
|||
|
|||
|
|||
class MailComposeMessage(models.TransientModel): |
|||
|
|||
_inherit = 'mail.compose.message' |
|||
|
|||
# The number of partner is needed to hide the 'print' button if |
|||
# there is more than one partner |
|||
partner_count = fields.Integer( |
|||
string='Number of partners', |
|||
compute='_compute_partner_count') |
|||
|
|||
@api.depends('partner_ids') |
|||
def _compute_partner_count(self): |
|||
for rec in self: |
|||
rec.partner_count = len(rec.partner_ids) |
|||
|
|||
@api.multi |
|||
def download_pdf(self): |
|||
''' |
|||
Download the email in pdf format, based on a QWeb report. |
|||
''' |
|||
self.ensure_one() |
|||
if self.partner_count != 1: |
|||
raise UserError(_("There must be only one recipient.")) |
|||
ctx = self.env.context.copy() |
|||
ctx.update({'active_id': self.id, |
|||
'active_ids': [self.id], |
|||
'active_model': 'mail.compose.message'}) |
|||
|
|||
return { |
|||
'name': 'mail_as_letter', |
|||
'model': 'mail.compose.message', |
|||
'res_id': self.id, |
|||
'type': 'ir.actions.report.xml', |
|||
'report_name': |
|||
'mail_as_letter.report_mail_print', |
|||
'report_type': 'qweb-pdf', |
|||
'context': ctx, } |
@ -0,0 +1,27 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<!-- Copyright 2016 ACSONE SA/NV |
|||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> |
|||
|
|||
<openerp> |
|||
<data> |
|||
|
|||
<record model="ir.ui.view" id="mail_compose_message_form_view"> |
|||
<field name="name">mail.compose.message.form (in mail_as_letter)</field> |
|||
<field name="model">mail.compose.message</field> |
|||
<field name="inherit_id" ref="mail.email_compose_message_wizard_form"/> |
|||
<field name="arch" type="xml"> |
|||
<button name="save_as_template"> |
|||
<field name="partner_count" attrs="{'invisible': True}"/> |
|||
<button icon="fa-file-pdf-o" |
|||
type="object" |
|||
name="download_pdf" |
|||
string="Print PDF" |
|||
class="pull-right btn-default" |
|||
help="Save as a PDF file" |
|||
attrs="{'invisible': [('partner_count', '!=', 1)]}"/> |
|||
</button> |
|||
</field> |
|||
</record> |
|||
|
|||
</data> |
|||
</openerp> |
@ -0,0 +1 @@ |
|||
__import__('pkg_resources').declare_namespace(__name__) |
@ -0,0 +1 @@ |
|||
../../../mail_as_letter |
@ -0,0 +1,6 @@ |
|||
import setuptools |
|||
|
|||
setuptools.setup( |
|||
setup_requires=['setuptools-odoo'], |
|||
odoo_addon=True, |
|||
) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue