From 62381a191ac9a054525152b69c2bd909b7b14e6e Mon Sep 17 00:00:00 2001 From: houssine Date: Fri, 5 Apr 2019 17:36:56 +0200 Subject: [PATCH] [IMP] make user creation conditional and moving code to invoice payment --- easy_my_coop/models/account_invoice.py | 19 +++++++++++++++++++ easy_my_coop/models/company.py | 1 + easy_my_coop/models/coop.py | 18 ------------------ easy_my_coop/view/res_company_view.xml | 1 + 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/easy_my_coop/models/account_invoice.py b/easy_my_coop/models/account_invoice.py index 96bb6e1..47d20d1 100644 --- a/easy_my_coop/models/account_invoice.py +++ b/easy_my_coop/models/account_invoice.py @@ -21,6 +21,22 @@ class account_invoice(models.Model): return values + def create_user(self, partner): + user_obj = self.env['res.users'] + # TODO replace self by partner + email = self.email + if self.is_company: + email = self.company_email + + user = user_obj.search([('login', '=', email)]) + if not user: + user_values = {'partner_id': partner.id, 'login': email} + user_id = user_obj.sudo()._signup_create_user(user_values) + user = user_obj.browse(user_id) + user.sudo().with_context({'create_user': True}).action_reset_password() + + return True + def set_cooperator_effective(self, effective_date): # flag the partner as a effective member mail_template_id = 'easy_my_coop.email_template_certificat' @@ -62,6 +78,9 @@ class account_invoice(models.Model): # we send the email with the certificat in attachment certificat_email_template.send_mail(self.partner_id.id, False) + if self.company_id.create_user: + self.create_user(self.partner_id) + return True def post_process_confirm_paid(self, effective_date): diff --git a/easy_my_coop/models/company.py b/easy_my_coop/models/company.py index cb23397..37bd7c4 100644 --- a/easy_my_coop/models/company.py +++ b/easy_my_coop/models/company.py @@ -15,6 +15,7 @@ class ResCompany(models.Model): default_lang_id = fields.Many2one('res.lang', string="Default lang") allow_id_card_upload = fields.Boolean(string="Allow ID Card upload") + create_user = fields.Boolean(string="Create user for cooperator") board_representative = fields.Char(string="Board representative name") signature_scan = fields.Binary(string="Board representative signature") property_cooperator_account = fields.Many2one('account.account', diff --git a/easy_my_coop/models/coop.py b/easy_my_coop/models/coop.py index 75775ca..234cee7 100644 --- a/easy_my_coop/models/coop.py +++ b/easy_my_coop/models/coop.py @@ -472,22 +472,6 @@ class subscription_request(models.Model): }) return partner - def create_user(self, partner): - user_obj = self.env['res.users'] - # TODO replace self by partner - email = self.email - if self.is_company: - email = self.company_email - - user = user_obj.search([('login', '=', email)]) - if not user: - user_values = {'partner_id': partner.id, 'login': email} - user_id = user_obj.sudo()._signup_create_user(user_values) - user = user_obj.browse(user_id) - user.sudo().with_context({'create_user': True}).action_reset_password() - - return True - @api.one def validate_subscription_request(self): partner_obj = self.env['res.partner'] @@ -558,8 +542,6 @@ class subscription_request(models.Model): invoice = self.create_invoice(partner) self.write({'partner_id': partner.id, 'state': 'done'}) - self.create_user(partner) - return invoice @api.one diff --git a/easy_my_coop/view/res_company_view.xml b/easy_my_coop/view/res_company_view.xml index b5de69a..3bfdd48 100644 --- a/easy_my_coop/view/res_company_view.xml +++ b/easy_my_coop/view/res_company_view.xml @@ -9,6 +9,7 @@ +