diff --git a/easy_my_coop_taxshelter_report/data/mail_template_data.xml b/easy_my_coop_taxshelter_report/data/mail_template_data.xml new file mode 100644 index 0000000..7e66168 --- /dev/null +++ b/easy_my_coop_taxshelter_report/data/mail_template_data.xml @@ -0,0 +1,56 @@ + + + + + Tax Shelter Certificate - Send By Email + ${(object.company_id.coop_email_contact or object.user_id.email)|safe} + Tax Shelter Certificate + ${object.partner_id.id} + ${(object.company_id.coop_email_contact or object.user_id.email)|safe} + + + ${object.lang} + +

Hello ${object.partner_id.name},

+ +

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

+

A dedicated FAQ is coming soon on ${object.company_id.website}.

+

For any additional questions, please contact ${object.company_id.coop_email_contact}

+

Sustainably your,

+

${object.company_id.name}.

+ + % if object.company_id.street: + ${object.company_id.street} + % endif + % if object.company_id.street2: + ${object.company_id.street2}
+ % endif + % if object.company_id.city or object.company_id.zip: + ${object.company_id.zip} ${object.company_id.city}
+ % 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 ''}
+ % endif + % if object.company_id.phone: + Phone:  ${object.company_id.phone} + % endif + + % if object.company_id.website: + + %endif + +
+ +
+ + ]]>
+
+ +
+
\ No newline at end of file diff --git a/easy_my_coop_taxshelter_report/models/__init__.py b/easy_my_coop_taxshelter_report/models/__init__.py index cf88ee6..ab4f736 100644 --- a/easy_my_coop_taxshelter_report/models/__init__.py +++ b/easy_my_coop_taxshelter_report/models/__init__.py @@ -1 +1,2 @@ -from . import tax_shelter_declaration \ No newline at end of file +from . import tax_shelter_declaration +from . import mail_template \ No newline at end of file diff --git a/easy_my_coop_taxshelter_report/models/mail_template.py b/easy_my_coop_taxshelter_report/models/mail_template.py new file mode 100644 index 0000000..54def59 --- /dev/null +++ b/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 ? \ No newline at end of file