Browse Source

[IMP] add tax shelter mail template

pull/1/head
houssine 8 years ago
parent
commit
fae45a79b6
  1. 56
      easy_my_coop_taxshelter_report/data/mail_template_data.xml
  2. 1
      easy_my_coop_taxshelter_report/models/__init__.py
  3. 50
      easy_my_coop_taxshelter_report/models/mail_template.py

56
easy_my_coop_taxshelter_report/data/mail_template_data.xml

@ -0,0 +1,56 @@
<openerp>
<!-- Mail template are declared in a NOUPDATE block
so users can freely customize/delete them -->
<data noupdate="0">
<record id="email_template_tax_shelter_certificate" model="mail.template">
<field name="name">Tax Shelter Certificate - Send By Email</field>
<field name="email_from">${(object.company_id.coop_email_contact or object.user_id.email)|safe}</field>
<field name="subject">Tax Shelter Certificate</field>
<field name="partner_to">${object.partner_id.id}</field>
<field name="reply_to">${(object.company_id.coop_email_contact or object.user_id.email)|safe}</field>
<field name="model_id" ref="model_tax_shelter_certificate"/>
<field name="auto_delete" eval="True"/>
<field name="lang">${object.lang}</field>
<field name="body_html"><![CDATA[
<div style="font-family: 'Lucica Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 12px; color: rgb(34, 34, 34); background-color: #FFF; ">
<p>Hello ${object.partner_id.name},</p>
<p>You have subscribed to some shares of ${object.company_id.name} on ${object.declaration_id.fiscal_year}.
You can benefit from the tax shelter, it means a tax reduction of ${object.declaration_id.tax_shelter_percentage} percent on the invested amount.
For this you will find in attachments the documents certifying that you've suscribed to ${object.company_id.name} shares</p>
<p>A dedicated FAQ is coming soon on ${object.company_id.website}.</p>
<p>For any additional questions, please contact ${object.company_id.coop_email_contact}</p>
<p>Sustainably your,</p>
<p>${object.company_id.name}.</p>
% if object.company_id.street:
${object.company_id.street}
% endif
% if object.company_id.street2:
${object.company_id.street2}<br/>
% endif
% if object.company_id.city or object.company_id.zip:
${object.company_id.zip} ${object.company_id.city}<br/>
% endif
% if object.company_id.country_id:
${object.company_id.state_id and ('%s, ' % object.company_id.state_id.name) or ''} ${object.company_id.country_id.name or ''}<br/>
% endif
% if object.company_id.phone:
Phone:&nbsp; ${object.company_id.phone}
% endif
% if object.company_id.website:
<div>
Web :&nbsp;<a href="${object.company_id.website}">${object.company_id.website}</a>
</div>
%endif
<div>
<img src=${object.company_id.logo_web}>
</div>
</div>
]]></field>
</record>
</data>
</openerp>

1
easy_my_coop_taxshelter_report/models/__init__.py

@ -1 +1,2 @@
from . import tax_shelter_declaration
from . import mail_template

50
easy_my_coop_taxshelter_report/models/mail_template.py

@ -0,0 +1,50 @@
class MailTemplate(models.Model):
"Templates for sending email"
_name = "mail.template"
@api.multi
def send_mail_with_multiple_attachments(self, res_id, additional_attachments, force_send=False, raise_exception=False):
"""Generates a new mail message for the given template and record,
and schedules it for delivery through the ``mail`` module's scheduler.
:param int res_id: id of the record to render the template with
(model is taken from the template)
:param bool force_send: if True, the generated mail.message is
immediately sent after being created, as if the scheduler
was executed for this message only.
:returns: id of the mail.message that was created
"""
self.ensure_one()
Mail = self.env['mail.mail']
Attachment = self.env['ir.attachment'] # TDE FIXME: should remove dfeault_type from context
# create a mail_mail based on values, without attachments
values = self.generate_email(res_id)
values['recipient_ids'] = [(4, pid) for pid in values.get('partner_ids', list())]
attachment_ids = values.pop('attachment_ids', [])
attachments = values.pop('attachments', [])
# add a protection against void email_from
if 'email_from' in values and not values.get('email_from'):
values.pop('email_from')
mail = Mail.create(values)
# manage attachments
attachments.extend(additional_attachments)
for attachment in attachments:
attachment_data = {
'name': attachment[0],
'datas_fname': attachment[0],
'datas': attachment[1],
'res_model': 'mail.message',
'res_id': mail.mail_message_id.id,
}
attachment_ids.append(Attachment.create(attachment_data).id)
if attachment_ids:
values['attachment_ids'] = [(6, 0, attachment_ids)]
mail.write({'attachment_ids': [(6, 0, attachment_ids)]})
if force_send:
mail.send(raise_exception=raise_exception)
return mail.id # TDE CLEANME: return mail + api.returns ?
Loading…
Cancel
Save