Browse Source

[REFACT] get mail template from function in order to allow override.

pull/37/head
houssine 5 years ago
committed by Rémy Taymans
parent
commit
9a7cc8f5ff
  1. 10
      easy_my_coop/models/account_invoice.py
  2. 20
      easy_my_coop/models/coop.py
  3. 14
      easy_my_coop/models/operation_request.py
  4. 14
      easy_my_coop_loan/models/loan_issue_line.py

10
easy_my_coop/models/account_invoice.py

@ -46,8 +46,10 @@ class account_invoice(models.Model):
def get_mail_template_certificate(self): def get_mail_template_certificate(self):
if self.partner_id.member: 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): def get_sequence_register(self):
return self.env.ref('easy_my_coop.sequence_subscription', False) return self.env.ref('easy_my_coop.sequence_subscription', False)
@ -100,14 +102,12 @@ class account_invoice(models.Model):
sub_register_obj = self.env['subscription.register'] sub_register_obj = self.env['subscription.register']
share_line_obj = self.env['share.line'] share_line_obj = self.env['share.line']
mail_template_id = self.get_mail_template_certificate()
self.set_membership() self.set_membership()
sequence_operation = self.get_sequence_operation() sequence_operation = self.get_sequence_operation()
sub_reg_operation = sequence_operation.next_by_id() 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: for line in self.invoice_line_ids:
sub_reg_vals = self.get_subscription_register_vals(line, sub_reg_vals = self.get_subscription_register_vals(line,

20
easy_my_coop/models/coop.py

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

14
easy_my_coop/models/operation_request.py

@ -206,6 +206,14 @@ class operation_request(models.Model):
" the information before" " the information before"
" submitting")) " 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)
@api.multi @api.multi
def execute_operation(self): def execute_operation(self):
self.ensure_one() self.ensure_one()
@ -300,12 +308,10 @@ class operation_request(models.Model):
# send mail to the receiver # send mail to the receiver
if rec.operation_type == 'transfer': 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 = self.get_share_trans_mail_template()
cert_email_template.send_mail(rec.partner_id_to.id, False) cert_email_template.send_mail(rec.partner_id_to.id, False)
self.env['subscription.register'].create(values) 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 = self.get_share_update_mail_template()
cert_email_template.send_mail(rec.partner_id.id, False) cert_email_template.send_mail(rec.partner_id.id, False)

14
easy_my_coop_loan/models/loan_issue_line.py

@ -57,10 +57,17 @@ class LoanIssueLine(models.Model):
string="Company", string="Company",
readonly=True) 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 @api.model
def create(self, vals): 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) line = super(LoanIssueLine, self).create(vals)
confirmation_mail_template.send_mail(line.id) confirmation_mail_template.send_mail(line.id)
@ -79,8 +86,7 @@ class LoanIssueLine(models.Model):
@api.multi @api.multi
def action_request_payment(self): 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: for line in self:
pay_req_mail_template.send_mail(line.id) pay_req_mail_template.send_mail(line.id)

Loading…
Cancel
Save