Browse Source

Merge pull request #37 from coopiteasy/12.0-flag-easymycoop-mail-template

[IMP] add easy my coop flag on mail template
pull/45/head
Houssine BAKKALI 4 years ago
committed by GitHub
parent
commit
b51b7bcc72
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      easy_my_coop/__manifest__.py
  2. 8
      easy_my_coop/data/mail_template_data.xml
  3. 1
      easy_my_coop/models/__init__.py
  4. 20
      easy_my_coop/models/account_invoice.py
  5. 23
      easy_my_coop/models/coop.py
  6. 12
      easy_my_coop/models/mail_template.py
  7. 43
      easy_my_coop/models/operation_request.py
  8. 4
      easy_my_coop/report/easy_my_coop_report.xml
  9. 1
      easy_my_coop/views/email_template_view.xml
  10. 2
      easy_my_coop/views/res_partner_view.xml
  11. 3
      easy_my_coop_loan/data/mail_template_data.xml
  12. 1
      easy_my_coop_loan/models/__init__.py
  13. 14
      easy_my_coop_loan/models/loan_issue_line.py
  14. 10
      easy_my_coop_loan/models/mail_template.py
  15. 6
      easy_my_coop_taxshelter_report/data/mail_template_data.xml
  16. 14
      easy_my_coop_taxshelter_report/models/mail_template.py

2
easy_my_coop/__manifest__.py

@ -5,7 +5,7 @@
{
'name': 'Easy My Coop',
'version': '12.0.2.0.2',
'version': '12.0.3.0.1',
'depends': [
'base',
'web',

8
easy_my_coop/data/mail_template_data.xml

@ -15,6 +15,7 @@
<field name="report_template" ref="action_cooperator_invoices"/>
<field name="report_name">${(object.number or '').replace('/','_')}_${object.state == 'draft' and 'draft' or ''}</field>
<field name="lang">${object.partner_id.lang}</field>
<field name="easy_my_coop" eval="True"/>
<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; ">
@ -65,6 +66,7 @@
<field name="model_id" ref="model_subscription_request"/>
<field name="auto_delete" eval="True"/>
<field name="lang">${object.lang}</field>
<field name="easy_my_coop" eval="True"/>
<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; ">
@ -117,6 +119,7 @@
<field name="model_id" ref="model_subscription_request"/>
<field name="auto_delete" eval="True"/>
<field name="lang">${object.lang}</field>
<field name="easy_my_coop" eval="True"/>
<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; ">
@ -166,7 +169,6 @@
<field name="name">Payment Received Confirmation - Send By Email</field>
<field name="email_from">${(object.company_id.coop_email_contact or object.user_id.email)|safe}</field>
<field name="subject">Payment Received Confirmation</field>
<!-- <field name="email_recipients">${object.partner_id.id}</field> -->
<field name="partner_to">${object.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_res_partner"/>
@ -174,6 +176,7 @@
<field name="report_template" ref="action_cooperator_report_certificat"/>
<field name="report_name">Certificat ${(object.cooperator_register_number or '')}</field>
<field name="lang">${object.lang}</field>
<field name="easy_my_coop" eval="True"/>
<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; ">
@ -228,6 +231,7 @@
<field name="report_template" ref="action_cooperator_report_certificat"/>
<field name="report_name">Certificat ${(object.cooperator_register_number or '')}</field>
<field name="lang">${object.lang}</field>
<field name="easy_my_coop" eval="True"/>
<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; ">
@ -282,6 +286,7 @@
<field name="report_template" ref="action_cooperator_report_certificat"/>
<field name="report_name">Certificat ${(object.cooperator_register_number or '')}</field>
<field name="lang">${object.lang}</field>
<field name="easy_my_coop" eval="True"/>
<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; ">
@ -336,6 +341,7 @@
<field name="report_template" ref="action_cooperator_report_certificat"/>
<field name="report_name">Certificat ${(object.cooperator_register_number or '')}</field>
<field name="lang">${object.lang}</field>
<field name="easy_my_coop" eval="True"/>
<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; ">

1
easy_my_coop/models/__init__.py

@ -6,3 +6,4 @@ from . import account_invoice
from . import company
from . import res_partner_bank
from . import account_journal
from . import mail_template

20
easy_my_coop/models/account_invoice.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2019 Coop IT Easy SCRL fs
# Houssine Bakkali <houssine@coopiteasy.be>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
@ -46,8 +45,10 @@ class account_invoice(models.Model):
def get_mail_template_certificate(self):
if self.partner_id.member:
return 'easy_my_coop.email_template_certificat_increase'
return 'easy_my_coop.email_template_certificat'
mail_template = 'easy_my_coop.email_template_certificat_increase'
else:
mail_template = 'easy_my_coop.email_template_certificat'
return self.env.ref(mail_template)
def get_sequence_register(self):
return self.env.ref('easy_my_coop.sequence_subscription', False)
@ -96,18 +97,20 @@ class account_invoice(models.Model):
return True
def send_certificate_email(self, certificate_email_template, sub_reg_line):
# we send the email with the certificate in attachment
certificate_email_template.sudo().send_mail(self.partner_id.id, False)
def set_cooperator_effective(self, effective_date):
sub_register_obj = self.env['subscription.register']
share_line_obj = self.env['share.line']
mail_template_id = self.get_mail_template_certificate()
self.set_membership()
sequence_operation = self.get_sequence_operation()
sub_reg_operation = sequence_operation.next_by_id()
certificate_email_template = self.env.ref(mail_template_id, False)
certificate_email_template = self.get_mail_template_certificate()
for line in self.invoice_line_ids:
sub_reg_vals = self.get_subscription_register_vals(line,
@ -115,7 +118,7 @@ class account_invoice(models.Model):
sub_reg_vals['name'] = sub_reg_operation
sub_reg_vals['register_number_operation'] = int(sub_reg_operation)
sub_register_obj.create(sub_reg_vals)
sub_reg_line = sub_register_obj.create(sub_reg_vals)
share_line_vals = self.get_share_line_vals(line, effective_date)
share_line_obj.create(share_line_vals)
@ -123,8 +126,7 @@ class account_invoice(models.Model):
if line.product_id.mail_template:
certificate_email_template = line.product_id.mail_template
# we send the email with the certificate in attachment
certificate_email_template.sudo().send_mail(self.partner_id.id, False)
self.send_certificate_email(certificate_email_template, sub_reg_line)
if self.company_id.create_user:
self.create_user(self.partner_id)

23
easy_my_coop/models/coop.py

@ -44,9 +44,10 @@ class SubscriptionRequest(models.Model):
def get_mail_template_notif(self, is_company=False):
if is_company:
return 'easy_my_coop.email_template_confirmation_company'
mail_template = 'easy_my_coop.email_template_confirmation_company'
else:
return 'easy_my_coop.email_template_confirmation'
mail_template = 'easy_my_coop.email_template_confirmation'
return self.env.ref(mail_template, False)
def is_member(self, vals, cooperator):
if cooperator.member:
@ -57,7 +58,7 @@ class SubscriptionRequest(models.Model):
@api.model
def create(self, vals):
partner_obj = self.env['res.partner']
mail_template = self.get_mail_template_notif(False)
mail_template_notif = self.get_mail_template_notif(False)
if not vals.get('partner_id'):
cooperator = False
@ -80,14 +81,13 @@ class SubscriptionRequest(models.Model):
cooperator.write({'cooperator': True})
subscr_request = super(SubscriptionRequest, self).create(vals)
confirmation_mail_template = self.env.ref(mail_template, False)
confirmation_mail_template.send_mail(subscr_request.id)
mail_template_notif.send_mail(subscr_request.id)
return subscr_request
@api.model
def create_comp_sub_req(self, vals):
mail_template = self.get_mail_template_notif(True)
confirmation_mail_template = self.get_mail_template_notif(True)
vals["name"] = vals['company_name']
if not vals.get('partner_id'):
cooperator = self.env['res.partner'].get_cooperator_from_crn(vals.get('company_register_number'))
@ -97,7 +97,6 @@ class SubscriptionRequest(models.Model):
vals['already_cooperator'] = True
subscr_request = super(SubscriptionRequest, self).create(vals)
confirmation_mail_template = self.env.ref(mail_template, False)
confirmation_mail_template.send_mail(subscr_request.id)
return subscr_request
@ -401,9 +400,12 @@ class SubscriptionRequest(models.Model):
}
return res
def send_capital_release_request(self, invoice):
def get_capital_release_mail_template(self):
template = 'easy_my_coop.email_template_release_capital'
email_template = self.env.ref(template, False)
return self.env.ref(template, False)
def send_capital_release_request(self, invoice):
email_template = self.get_capital_release_mail_template()
# we send the email with the capital release request in attachment
# TODO remove sudo() and give necessary access right
@ -551,6 +553,9 @@ class SubscriptionRequest(models.Model):
if domain:
partner = partner_obj.search(domain)
if not partner.cooperator:
partner.cooperator = True
if not partner:
partner = self.create_coop_partner()
else:

12
easy_my_coop/models/mail_template.py

@ -0,0 +1,12 @@
from odoo import models, fields
class MailTemplate(models.Model):
_inherit = "mail.template"
# def init(self):
# for template_id in EMAIL_TEMPLATE_IDS:
# mail_template = self.env.ref(template_id)
# mail_template.easy_my_coop = True
easy_my_coop = fields.Boolean(string="Easy my coop mail template")

43
easy_my_coop/models/operation_request.py

@ -206,6 +206,31 @@ class operation_request(models.Model):
" the information before"
" submitting"))
def get_share_trans_mail_template(self):
return self.env.ref('easy_my_coop.email_template_share_transfer',
False)
def get_share_update_mail_template(self):
return self.env.ref('easy_my_coop.email_template_share_update',
False)
def send_share_trans_mail(self, sub_register_line):
cert_email_template = self.get_share_trans_mail_template()
cert_email_template.send_mail(rec.partner_id_to.id, False)
def send_share_update_mail(self, sub_register_line):
cert_email_template = self.get_share_update_mail_template()
cert_email_template.send_mail(rec.partner_id.id, False)
def get_subscription_register_vals(self, effective_date):
return {
'partner_id': self.partner_id.id, 'quantity': self.quantity,
'share_product_id': self.share_product_id.id,
'type': self.operation_type,
'share_unit_price': self.share_unit_price,
'date': effective_date,
}
@api.multi
def execute_operation(self):
self.ensure_one()
@ -220,13 +245,7 @@ class operation_request(models.Model):
raise ValidationError(_("This operation must be approved"
" before to be executed"))
values = {
'partner_id': rec.partner_id.id, 'quantity': rec.quantity,
'share_product_id': rec.share_product_id.id,
'type': rec.operation_type,
'share_unit_price': rec.share_unit_price,
'date': effective_date,
}
values = rec.get_subscription_register_vals(effective_date)
if rec.operation_type == 'sell_back':
self.hand_share_over(rec.partner_id, rec.share_product_id,
@ -300,12 +319,8 @@ class operation_request(models.Model):
# send mail to the receiver
if rec.operation_type == 'transfer':
mail_template = 'easy_my_coop.email_template_share_transfer'
cert_email_template = self.env.ref(mail_template, False)
cert_email_template.send_mail(rec.partner_id_to.id, False)
self.send_share_trans_mail(sub_register_line)
self.env['subscription.register'].create(values)
sub_register_line = self.env['subscription.register'].create(values)
mail_template = 'easy_my_coop.email_template_share_update'
cert_email_template = self.env.ref(mail_template, False)
cert_email_template.send_mail(rec.partner_id.id, False)
self.send_share_update_mail(sub_register_line)

4
easy_my_coop/report/easy_my_coop_report.xml

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<odoo>
<data noupdate="1">
@ -46,4 +46,4 @@
menu="True"
/>
</data>
</openerp>
</odoo>

1
easy_my_coop/views/email_template_view.xml

@ -7,6 +7,7 @@
<field name="res_model">mail.template</field>
<field name="view_type">form</field>
<field name="view_mode">form,tree</field>
<field name="domain">[('easy_my_coop','=',True)]</field>
<field name="view_id" ref="mail.email_template_tree" />
<field name="search_view_id" ref="mail.view_email_template_search" />
</record>

2
easy_my_coop/views/res_partner_view.xml

@ -14,7 +14,7 @@
<header>
<button string="Create Subscription" name="%(action_view_create_subscription)d"
type="action" context="{'default_active_id': active_id}" groups="easy_my_coop.group_easy_my_coop_user"/>
<button string="Update info" name="%(action_view_update_partner_info)d"
<button id="action_view_update_partner_info" string="Update info" name="%(action_view_update_partner_info)d"
type="action" context="{'default_active_id': active_id}" groups="easy_my_coop.group_easy_my_coop_user"/>
</header>
</sheet>

3
easy_my_coop_loan/data/mail_template_data.xml

@ -3,7 +3,6 @@
<!-- Mail template are declared in a NOUPDATE block
so users can freely customize/delete them -->
<data noupdate="1">
<!--<data>-->
<record id="loan_subscription_confirmation" model="mail.template">
<field name="name">Loan Subscription Confirmation Email</field>
<field name="email_from">${(object.company_id.coop_email_contact or object.loan_issue_id.user_id.email)|safe}</field>
@ -13,6 +12,7 @@
<field name="model_id" ref="easy_my_coop_loan.model_loan_issue_line"/>
<field name="auto_delete" eval="True"/>
<field name="lang">${object.partner_id.lang}</field>
<field name="easy_my_coop" eval="True"/>
<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; ">
@ -65,6 +65,7 @@
<field name="model_id" ref="easy_my_coop_loan.model_loan_issue_line"/>
<field name="auto_delete" eval="True"/>
<field name="lang">${object.partner_id.lang}</field>
<field name="easy_my_coop" eval="True"/>
<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; ">

1
easy_my_coop_loan/models/__init__.py

@ -2,3 +2,4 @@ from . import loan
from . import loan_issue_line
from . import interest_line
from . import partner
from . import mail_template

14
easy_my_coop_loan/models/loan_issue_line.py

@ -57,10 +57,17 @@ class LoanIssueLine(models.Model):
string="Company",
readonly=True)
def get_loan_sub_mail_template(self):
return self.env.ref('easy_my_coop_loan.loan_subscription_confirmation',
False)
def get_loan_pay_req_mail_template(self):
return self.env.ref('easy_my_coop_loan.loan_issue_payment_request',
False)
@api.model
def create(self, vals):
mail_template = 'easy_my_coop_loan.loan_subscription_confirmation'
confirmation_mail_template = self.env.ref(mail_template, False)
confirmation_mail_template = self.get_loan_sub_mail_template()
line = super(LoanIssueLine, self).create(vals)
confirmation_mail_template.send_mail(line.id)
@ -79,8 +86,7 @@ class LoanIssueLine(models.Model):
@api.multi
def action_request_payment(self):
mail_template = 'easy_my_coop_loan.loan_issue_payment_request'
pay_req_mail_template = self.env.ref(mail_template, False)
pay_req_mail_template = self.get_loan_pay_req_mail_template()
for line in self:
pay_req_mail_template.send_mail(line.id)

10
easy_my_coop_loan/models/mail_template.py

@ -0,0 +1,10 @@
from odoo import models
class MailTemplate(models.Model):
_inherit = "mail.template"
# def init(self):
# for template_id in EMAIL_TEMPLATE_IDS:
# mail_template = self.env.ref(template_id)
# mail_template.easy_my_coop = True

6
easy_my_coop_taxshelter_report/data/mail_template_data.xml

@ -1,4 +1,4 @@
<openerp>
<odoo>
<!-- Mail template are declared in a NOUPDATE block
so users can freely customize/delete them -->
<data noupdate="1">
@ -11,6 +11,7 @@
<field name="model_id" ref="model_tax_shelter_certificate"/>
<field name="auto_delete" eval="True"/>
<field name="lang">${object.partner_id.lang}</field>
<field name="easy_my_coop" eval="True"/>
<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>
@ -51,6 +52,5 @@
</div>
]]></field>
</record>
</data>
</openerp>
</odoo>

14
easy_my_coop_taxshelter_report/models/mail_template.py

@ -1,18 +1,21 @@
# -*- coding: utf-8 -*-
from openerp import api, models
from odoo import api, models
class MailTemplate(models.Model):
_inherit = "mail.template"
# def init(self):
# for template_id in EMAIL_TEMPLATE_IDS:
# mail_template = self.env.ref(template_id)
# mail_template.easy_my_coop = True
@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``
and schedules it for delivery through the ``mail``
module's scheduler.
:param int res_id: id of the record to render the template with
@ -24,7 +27,8 @@ class MailTemplate(models.Model):
"""
self.ensure_one()
Mail = self.env['mail.mail']
Attachment = self.env['ir.attachment'] # TDE FIXME: should remove dfeault_type from context
# TDE FIXME: should remove dfeault_type from context
Attachment = self.env['ir.attachment']
# create a mail_mail based on values, without attachments
values = self.generate_email(res_id)

Loading…
Cancel
Save