Browse Source

[IMP] make user creation conditional and moving code to invoice payment

pull/1/head
houssine 6 years ago
parent
commit
62381a191a
  1. 19
      easy_my_coop/models/account_invoice.py
  2. 1
      easy_my_coop/models/company.py
  3. 18
      easy_my_coop/models/coop.py
  4. 1
      easy_my_coop/view/res_company_view.xml

19
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):

1
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',

18
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

1
easy_my_coop/view/res_company_view.xml

@ -9,6 +9,7 @@
<group name="coop_grp" string="EasyMy Coop" groups="easy_my_coop.group_energiris_manager">
<field name="unmix_share_type"/>
<field name="allow_id_card_upload"/>
<field name="create_user"/>
<field name="display_logo1"/>
<field name="bottom_logo1"/>
<field name="display_logo2"/>

Loading…
Cancel
Save