From 4936d43567c631b8e0bb47ec2f06b23bfdfd0361 Mon Sep 17 00:00:00 2001 From: houssine Date: Mon, 25 Nov 2019 17:57:59 +0100 Subject: [PATCH] [REFACT] put the email send in a dedicated function to allow overriding. --- easy_my_coop/models/account_invoice.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/easy_my_coop/models/account_invoice.py b/easy_my_coop/models/account_invoice.py index f5a366b..6c46ae8 100644 --- a/easy_my_coop/models/account_invoice.py +++ b/easy_my_coop/models/account_invoice.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2019 Coop IT Easy SCRL fs # Houssine Bakkali # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). @@ -98,6 +97,10 @@ 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'] @@ -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)