Browse Source

[IMP] handle case where there is no bank account defined on the partner

pull/1/head
houssine 7 years ago
parent
commit
439b17a724
  1. 17
      easy_my_coop/wizard/create_subscription_from_partner.py

17
easy_my_coop/wizard/create_subscription_from_partner.py

@ -50,6 +50,12 @@ class PartnerCreateSubscription(models.TransientModel):
else:
return partner.national_register_number
@api.model
def _get_bank_account(self):
if len(self.cooperator.bank_ids) > 0:
return self.cooperator.bank_ids[0]
return None
@api.model
def _get_possible_share(self):
domain = [('is_share','=',True)]
@ -71,6 +77,7 @@ class PartnerCreateSubscription(models.TransientModel):
cooperator = fields.Many2one('res.partner', string="Cooperator", default=_get_partner)
register_number = fields.Char(string="Register Number", required=True, default=_get_register_number)
email = fields.Char(string="Email", required=True, default=_get_email)
bank_account = fields.Char(string="Bank account", required=True, default=_get_bank_account)
share_product = fields.Many2one('product.product', string='Share Type', domain=lambda self: self._get_possible_share(),\
default=_default_product_id, required=True)
share_qty = fields.Integer(string="Share Quantity", required=True)
@ -85,6 +92,7 @@ class PartnerCreateSubscription(models.TransientModel):
'share_product_id': self.share_product.id,
'ordered_parts': self.share_qty,
'user_id': self.env.uid,
'email': self.email,
'source': 'crm'}
if self.is_company:
@ -108,9 +116,16 @@ class PartnerCreateSubscription(models.TransientModel):
coop_vals['national_register_number'] = self.register_number
else:
raise UserError(_("The national register number is not valid."))
if not self._get_bank_account():
partner_bank = self.env['res.partner.bank']
partner_bank.create({'partner_id':cooperator.id,
'acc_number':self.bank_account})
vals['iban'] = self.bank_account
if coop_vals:
cooperator.write(coop_vals)
self.env.cr.commit()
#self.env.cr.commit()
new_sub_req = sub_req.create(vals)
return {
'type': 'ir.actions.act_window',

Loading…
Cancel
Save