Browse Source

[PEP8] fix pep8

pull/1/head
houssine 6 years ago
parent
commit
37f5ed6de3
  1. 100
      easy_my_coop/wizard/create_subscription_from_partner.py

100
easy_my_coop/wizard/create_subscription_from_partner.py

@ -1,11 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import time
from openerp import api, fields, models, _ from openerp import api, fields, models, _
import openerp.addons.decimal_precision as dp import openerp.addons.decimal_precision as dp
from openerp.exceptions import UserError from openerp.exceptions import UserError
class PartnerCreateSubscription(models.TransientModel): class PartnerCreateSubscription(models.TransientModel):
_name = "partner.create.subscription" _name = "partner.create.subscription"
_description = "Create Subscription From Partner" _description = "Create Subscription From Partner"
@ -17,22 +15,23 @@ class PartnerCreateSubscription(models.TransientModel):
@api.model @api.model
def _default_product_id(self): def _default_product_id(self):
domain = [('is_share','=',True),('default_share_product','=',True)]
domain = [('is_share', '=', True),
('default_share_product', '=', True)]
active_id = self.env.context.get('active_id') active_id = self.env.context.get('active_id')
if active_id: if active_id:
partner = self.env['res.partner'].browse(active_id) partner = self.env['res.partner'].browse(active_id)
if partner.is_company: if partner.is_company:
domain.append(('by_company','=',True))
domain.append(('by_company', '=', True))
else: else:
domain.append(('by_individual','=',True))
domain.append(('by_individual', '=', True))
return self.env['product.product'].search(domain)[0] return self.env['product.product'].search(domain)[0]
def _get_representative(self): def _get_representative(self):
partner = self._get_partner() partner = self._get_partner()
if partner.is_company: if partner.is_company:
return self.env['res.partner'].search([('parent_id','=',partner.id),
('representative','=',True)])
return self.env['res.partner'].search([('parent_id', '=', partner.id),
('representative', '=', True)])
return False return False
@api.model @api.model
@ -80,12 +79,12 @@ class PartnerCreateSubscription(models.TransientModel):
@api.model @api.model
def _get_possible_share(self): def _get_possible_share(self):
domain = [('is_share','=',True)]
domain = [('is_share', '=', True)]
partner = self._get_partner() partner = self._get_partner()
if partner.is_company: if partner.is_company:
domain.append(('by_company','=',True))
domain.append(('by_company', '=', True))
else: else:
domain.append(('by_individual','=',True))
domain.append(('by_individual', '=', True))
return domain return domain
@ -93,23 +92,47 @@ class PartnerCreateSubscription(models.TransientModel):
@api.depends('share_product', 'share_qty') @api.depends('share_product', 'share_qty')
def _compute_subscription_amount(self): def _compute_subscription_amount(self):
for sub_request in self: for sub_request in self:
sub_request.subscription_amount = sub_request.share_product.list_price * sub_request.share_qty
is_company = fields.Boolean(String="Is company?", default=_get_is_company)
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)
share_unit_price = fields.Float(related='share_product.list_price', string='Share price', readonly=True)
subscription_amount = fields.Float(compute='_compute_subscription_amount', string='Subscription amount', digits=dp.get_precision('Account'), readonly=True)
representative_name = fields.Char(string='Representative name', default=_get_representative_name)
representative_number = fields.Char(string='Representative national register number', default=_get_representative_number)
sub_request.subscription_amount = (sub_request.
share_product.list_price *
sub_request.share_qty)
is_company = fields.Boolean(String="Is company?",
default=_get_is_company)
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=_get_possible_share,
default=_default_product_id,
required=True)
share_qty = fields.Integer(string="Share Quantity",
required=True)
share_unit_price = fields.Float(related='share_product.list_price',
string='Share price',
readonly=True)
subscription_amount = fields.Float(compute='_compute_subscription_amount',
string='Subscription amount',
digits=dp.get_precision('Account'),
readonly=True)
representative_name = fields.Char(string='Representative name',
default=_get_representative_name)
representative_number = fields.Char(string='Representative national '
'register number',
default=_get_representative_number)
def check_belgian_ident_id(self, register_number): def check_belgian_ident_id(self, register_number):
if self.env['subscription.request'].check_belgian_identification_id(register_number):
sub_req = self.env['subscription.request']
if sub_req.check_belgian_identification_id(register_number):
return True return True
else: else:
raise UserError(_("The national register number is not valid.")) raise UserError(_("The national register number is not valid."))
@ -130,7 +153,7 @@ class PartnerCreateSubscription(models.TransientModel):
'zip_code': self.cooperator.zip, 'zip_code': self.cooperator.zip,
'city': self.cooperator.city, 'city': self.cooperator.city,
'country_id': self.cooperator.country_id.id 'country_id': self.cooperator.country_id.id
}
}
if self.is_company: if self.is_company:
vals['company_name'] = cooperator.name vals['company_name'] = cooperator.name
@ -157,25 +180,31 @@ class PartnerCreateSubscription(models.TransientModel):
representative = False representative = False
if self.representative_number: if self.representative_number:
representative_number = self.representative_number representative_number = self.representative_number
representative = partner_obj.search([('national_register_number','=',representative_number)])
representative = partner_obj.search([('national_register_number', '=', representative_number)])
if representative: if representative:
if len(representative) > 1: if len(representative) > 1:
raise UserError(_('There is two different persons with the same national register number. Please proceed to a merge before to continue'))
raise UserError(_('There is two different persons with '
'the same national register number. '
'Please proceed to a merge before to '
'continue'))
if representative.parent_id: if representative.parent_id:
raise UserError(_("A person can't be representative of two differents companies."))
raise UserError(_("A person can't be representative of "
"two different companies."))
representative.parent_id = cooperator.id representative.parent_id = cooperator.id
else: else:
if self.check_belgian_ident_id(representative_number): if self.check_belgian_ident_id(representative_number):
represent_vals = {'name':self.representative_name,'cooperator':True,
'national_register_number':representative_number,
'parent_id':cooperator.id,'representative':True}
represent_vals = {'name': self.representative_name,
'cooperator': True,
'national_register_number': representative_number,
'parent_id': cooperator.id,
'representative': True}
partner_obj.create(represent_vals) partner_obj.create(represent_vals)
if not self._get_bank_account(): if not self._get_bank_account():
partner_bank = self.env['res.partner.bank'] partner_bank = self.env['res.partner.bank']
partner_bank.create({'partner_id':cooperator.id,
'acc_number':self.bank_account})
partner_bank.create({'partner_id': cooperator.id,
'acc_number': self.bank_account})
vals['iban'] = self.bank_account vals['iban'] = self.bank_account
if self.is_company: if self.is_company:
representative = self._get_representative() representative = self._get_representative()
@ -195,4 +224,3 @@ class PartnerCreateSubscription(models.TransientModel):
'res_id': new_sub_req.id, 'res_id': new_sub_req.id,
'target': 'current', 'target': 'current',
} }
Loading…
Cancel
Save