Browse Source

Merge pull request #136 from coopiteasy/9.0-subscription_by_partner_already_in_crm

9.0 subscription by partner already in crm
pull/139/head 9.0-2020-11-24.00
Houssine BAKKALI 4 years ago
committed by GitHub
parent
commit
5cbeb41742
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      easy_my_coop/models/coop.py
  2. 18
      easy_my_coop/models/partner.py
  3. 2
      easy_my_coop/wizard/create_subscription_from_partner.py

11
easy_my_coop/models/coop.py

@ -48,18 +48,12 @@ class subscription_request(models.Model):
cooperator = partner_obj.get_cooperator_from_email( cooperator = partner_obj.get_cooperator_from_email(
vals.get('email')) vals.get('email'))
if cooperator: if cooperator:
# TODO remove the following line of code once it has
# been found a way to avoid double entry
cooperator = cooperator[0]
if cooperator.member: if cooperator.member:
vals['type'] = 'increase' vals['type'] = 'increase'
vals['already_cooperator'] = True vals['already_cooperator'] = True
else: else:
vals['type'] = 'subscription' vals['type'] = 'subscription'
vals['partner_id'] = cooperator.id vals['partner_id'] = cooperator.id
if not cooperator.cooperator:
cooperator.write({'cooperator': True})
else: else:
cooperator_id = vals.get('partner_id') cooperator_id = vals.get('partner_id')
cooperator = partner_obj.browse(cooperator_id) cooperator = partner_obj.browse(cooperator_id)
@ -80,9 +74,12 @@ class subscription_request(models.Model):
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'))
if cooperator: if cooperator:
vals['partner_id'] = cooperator.id
if cooperator.member:
vals['type'] = 'increase' vals['type'] = 'increase'
vals['already_cooperator'] = True vals['already_cooperator'] = True
else:
vals['type'] = 'subscription'
vals['partner_id'] = cooperator.id
subscr_request = super(subscription_request, self).create(vals) subscr_request = super(subscription_request, self).create(vals)
confirmation_mail_template = self.env.ref('easy_my_coop.email_template_confirmation_company', False) confirmation_mail_template = self.env.ref('easy_my_coop.email_template_confirmation_company', False)

18
easy_my_coop/models/partner.py

@ -201,9 +201,19 @@ class ResPartner(models.Model):
return self.child_ids.filtered('representative') return self.child_ids.filtered('representative')
def get_cooperator_from_email(self, email): def get_cooperator_from_email(self, email):
return self.search([('cooperator', '=', True),
('email', '=', email)])
partner = self.search([('cooperator', '=', True),
('email', '=', email)], limit=1)
if not partner:
partner = self.search([('email', '=', email)], limit=1)
return partner
def get_cooperator_from_crn(self, comp_reg_number): def get_cooperator_from_crn(self, comp_reg_number):
return self.search([('cooperator', '=', True),
('company_register_number', '=', comp_reg_number)])
partner = self.search([
('cooperator', '=', True),
('company_register_number', '=', comp_reg_number)
], limit=1)
if not partner:
partner = self.search([
('company_register_number', '=', comp_reg_number)
], limit=1)
return partner

2
easy_my_coop/wizard/create_subscription_from_partner.py

@ -133,7 +133,6 @@ class PartnerCreateSubscription(models.TransientModel):
cooperator = self.cooperator cooperator = self.cooperator
vals = {'partner_id': cooperator.id, vals = {'partner_id': cooperator.id,
'cooperator': True,
'share_product_id': self.share_product.id, 'share_product_id': self.share_product.id,
'ordered_parts': self.share_qty, 'ordered_parts': self.share_qty,
'user_id': self.env.uid, 'user_id': self.env.uid,
@ -148,6 +147,7 @@ class PartnerCreateSubscription(models.TransientModel):
if self.is_company: if self.is_company:
vals['company_name'] = cooperator.name vals['company_name'] = cooperator.name
vals['company_email'] = cooperator.email vals['company_email'] = cooperator.email
vals['email'] = self.representative_email
vals['name'] = '/' vals['name'] = '/'
vals['company_register_number'] = self.register_number vals['company_register_number'] = self.register_number
vals['is_company'] = True vals['is_company'] = True

Loading…
Cancel
Save