Browse Source

[PEP8] make the code compliant with PEP8

pull/1/head
houssine 5 years ago
parent
commit
923daeda34
  1. 5
      easy_my_coop/models/account_journal.py
  2. 40
      easy_my_coop/models/company.py
  3. 487
      easy_my_coop/models/coop.py
  4. 262
      easy_my_coop/models/operation_request.py
  5. 96
      easy_my_coop/models/partner.py
  6. 16
      easy_my_coop/models/product.py
  7. 2
      easy_my_coop/models/res_partner_bank.py

5
easy_my_coop/models/account_journal.py

@ -2,8 +2,9 @@
from openerp import fields, models
class AccountJournal(models.Model):
_inherit = "account.journal"
get_cooperator_payment = fields.Boolean('Get cooperator payments?')
get_general_payment = fields.Boolean('Get general payments?')
get_general_payment = fields.Boolean(string='Get general payments?')

40
easy_my_coop/models/company.py

@ -1,24 +1,36 @@
# -*- coding: utf-8 -*-
from openerp import fields, models
class ResCompany(models.Model):
_inherit = 'res.company'
coop_email_contact = fields.Char(string="Contact email address for the cooperator")
subscription_maximum_amount = fields.Float(string="Maximum authorized subscription amount")
default_country_id = fields.Many2one('res.country', string="Default country", default=lambda self: self.country_id)
default_lang_id = fields.Many2one('res.lang', string="Default lang")
coop_email_contact = fields.Char(string="Contact email address for the"
" cooperator")
subscription_maximum_amount = fields.Float(string="Maximum authorised"
" subscription amount")
default_country_id = fields.Many2one('res.country',
string="Default country",
default=lambda self: self.country_id)
default_lang_id = fields.Many2one('res.lang',
string="Default lang")
board_representative = fields.Char(string="Board representative name")
signature_scan = fields.Binary(string="Board representative signature")
property_cooperator_account = fields.Many2one('account.account', company_dependent=True,
string="Cooperator Account",
domain="[('internal_type', '=', 'receivable'), ('deprecated', '=', False)]",
help="This account will be the default one as the receivable account for the cooperators",
required=True)
unmix_share_type = fields.Boolean(string="Unmix share type",
help="If checked, A cooperator will be authorized "
"to have only one type of share")
property_cooperator_account = fields.Many2one('account.account',
company_dependent=True,
string="Cooperator Account",
domain=[('internal_type', '=', 'receivable'),
('deprecated', '=', False)],
help="This account will be"
" the default one as the"
" receivable account for the"
" cooperators",
required=True)
unmix_share_type = fields.Boolean(string="Unmix share type",
help="If checked, A cooperator will be"
" authorised to have only one type"
" of share")
display_logo1 = fields.Boolean(string="Display logo 1")
display_logo2 = fields.Boolean(string="Display logo 2")
bottom_logo1 = fields.Binary(string="Bottom logo 1")
bottom_logo2 = fields.Binary(string="Bottom logo 2")
bottom_logo2 = fields.Binary(string="Bottom logo 2")

487
easy_my_coop/models/coop.py

@ -5,30 +5,45 @@ from openerp import api, fields, models, _
from openerp.addons.base_iban import base_iban
from openerp.exceptions import UserError, ValidationError
_REQUIRED = ['email','firstname','lastname','birthdate','address','share_product_id','ordered_parts','zip_code','city','iban','no_registre','gender'] # Could be improved including required from model
_REQUIRED = ['email',
'firstname',
'lastname',
'birthdate',
'address',
'share_product_id',
'ordered_parts',
'zip_code',
'city',
'iban',
'no_registre',
'gender'] # Could be improved including required from model
@api.model
def _lang_get(self):
languages = self.env['res.lang'].search([])
return [(language.code, language.name) for language in languages]
class subscription_request(models.Model):
_name = 'subscription.request'
_description = 'Subscription Request'
def get_required_field(self):
return _REQUIRED
@api.model
def create(self,vals):
def create(self, vals):
partner_obj = self.env['res.partner']
if not vals.get('partner_id'):
cooperator = False
if vals.get('no_registre'):
cooperator = self.env['res.partner'].get_cooperator_from_nin(vals.get('no_registre'))
cooperator = partner_obj.get_cooperator_from_nin(
vals.get('no_registre'))
if cooperator:
# TODO remove the following line of code once it has
# TODO remove the following line of code once it has
# been founded a way to avoid dubble entry
cooperator = cooperator[0]
cooperator = cooperator[0]
if cooperator.member:
vals['type'] = 'increase'
vals['already_cooperator'] = True
@ -37,21 +52,21 @@ class subscription_request(models.Model):
vals['partner_id'] = cooperator.id
if not cooperator.cooperator:
cooperator.write({'cooperator':True})
cooperator.write({'cooperator': True})
else:
cooperator_id = vals.get('partner_id')
cooperator = self.env['res.partner'].browse(cooperator_id)
cooperator = partner_obj.browse(cooperator_id)
if cooperator.member:
vals['type'] = 'increase'
vals['already_cooperator'] = True
subscr_request = super(subscription_request, self).create(vals)
confirmation_mail_template = self.env.ref('easy_my_coop.email_template_confirmation', False)
confirmation_mail_template.send_mail(subscr_request.id)
return subscr_request
@api.model
def create_comp_sub_req(self, vals):
if not vals.get('partner_id'):
@ -64,9 +79,9 @@ class subscription_request(models.Model):
confirmation_mail_template = self.env.ref('easy_my_coop.email_template_confirmation_company', False)
confirmation_mail_template.send_mail(subscr_request.id, True)
return subscr_request
def check_belgian_identification_id(self, nat_register_num):
if not self.check_empty_string(nat_register_num):
return False
@ -82,14 +97,14 @@ class subscription_request(models.Model):
if int(check_controle) != int(controle):
return False
return True
def check_empty_string(self, value):
if value == None or value == False or value == '':
if value is None or value is False or value == '':
return False
return True
@api.multi
@api.depends('iban', 'no_registre','skip_control_ng','is_company',)
@api.depends('iban', 'no_registre', 'skip_control_ng', 'is_company')
def _validated_lines(self):
for sub_request in self:
validated = False
@ -98,90 +113,123 @@ class subscription_request(models.Model):
validated = True
except ValidationError:
validated = False
#if not sub_request.is_company:
if sub_request.skip_control_ng or self.check_belgian_identification_id(sub_request.no_registre):
# if not sub_request.is_company:
if sub_request.skip_control_ng \
or self.check_belgian_identification_id(
sub_request.no_registre):
validated = True
else:
validated = False
sub_request.validated = validated
@api.multi
@api.depends('share_product_id', 'share_product_id.list_price','ordered_parts')
@api.depends('share_product_id',
'share_product_id.list_price',
'ordered_parts')
def _compute_subscription_amount(self):
for sub_request in self:
sub_request.subscription_amount = sub_request.share_product_id.list_price * sub_request.ordered_parts
already_cooperator = fields.Boolean(string="I'm already cooperator")
name = fields.Char(string='Name', required=True)
already_cooperator = fields.Boolean(string="I'm already cooperator")
name = fields.Char(string='Name',
required=True)
firstname = fields.Char(string='Firstname')
lastname = fields.Char(string='Lastname')
birthdate = fields.Date(string="Birthdate")
gender = fields.Selection([('male', _('Male')),
('female', _('Female')),
('other', _('Other'))], string='Gender')
type = fields.Selection([('new','New Cooperator'),
('subscription','Subscription'),
('increase','Increase number of share')],
string='Type', default="new")
state = fields.Selection([('draft','Draft'),
('block','Blocked'),
('done','Done'),
('waiting','Waiting'),
('transfer','Transfer'),
('cancelled','Cancelled'),
('paid','paid')],
string='State',required=True, default="draft")
type = fields.Selection([('new', 'New Cooperator'),
('subscription', 'Subscription'),
('increase', 'Increase number of share')],
string='Type', default="new")
state = fields.Selection([('draft', 'Draft'),
('block', 'Blocked'),
('done', 'Done'),
('waiting', 'Waiting'),
('transfer', 'Transfer'),
('cancelled', 'Cancelled'),
('paid', 'paid')],
string='State', required=True, default="draft")
email = fields.Char(string='Email')
iban = fields.Char(string='Account Number')
partner_id = fields.Many2one('res.partner',string='Cooperator')
share_product_id = fields.Many2one('product.product', string='Share type', domain=[('is_share','=',True)])
share_short_name = fields.Char(related='share_product_id.short_name', string='Share type name')
share_unit_price = fields.Float(related='share_product_id.list_price', string='Share price')
subscription_amount = fields.Float(compute='_compute_subscription_amount', string='Subscription amount')
partner_id = fields.Many2one('res.partner',
string='Cooperator')
share_product_id = fields.Many2one('product.product',
string='Share type',
domain=[('is_share', '=', True)])
share_short_name = fields.Char(related='share_product_id.short_name',
string='Share type name')
share_unit_price = fields.Float(related='share_product_id.list_price',
string='Share price')
subscription_amount = fields.Float(compute='_compute_subscription_amount',
string='Subscription amount')
ordered_parts = fields.Integer(string='Number of Share')
address = fields.Char(string='Address')
city = fields.Char(string='City')
zip_code = fields.Char(string='Zip Code')
country_id = fields.Many2one('res.country', string='Country', ondelete='restrict')
country_id = fields.Many2one('res.country',
string='Country',
ondelete='restrict')
phone = fields.Char(string='Phone')
no_registre = fields.Char(string='National Register Number')
user_id = fields.Many2one('res.users', string='Responsible', readonly=True)
validated = fields.Boolean(compute='_validated_lines', string='Valid Line?', readonly=True)
skip_control_ng = fields.Boolean(string="Skip control",
help="if this field is checked then no control will be done on the national register number and on the iban bank account. To be done in case of the id card is from abroad or in case of a passport")
lang = fields.Selection(_lang_get, 'Language', default=lambda self: self.env['res.company']._company_default_get().default_lang_id.code,
help="If the selected language is loaded in the system, all documents related to this contact will be printed in this language. If not, it will be English.")
date = fields.Date(string='Subscription date request', default=lambda self: datetime.strftime(datetime.now(), '%Y-%m-%d'))
company_id = fields.Many2one('res.company', string='Company', required=True,
change_default=True, readonly=True,
user_id = fields.Many2one('res.users',
string='Responsible',
readonly=True)
validated = fields.Boolean(compute='_validated_lines',
string='Valid Line?',
readonly=True)
skip_control_ng = fields.Boolean(string="Skip control",
help="if this field is checked then no"
" control will be done on the national"
" register number and on the iban bank"
" account. To be done in case of the id"
" card is from abroad or in case of"
" a passport")
lang = fields.Selection(_lang_get,
string='Language',
default=lambda self: self.env['res.company']._company_default_get().default_lang_id.code)
date = fields.Date(string='Subscription date request',
default=lambda self: datetime.strftime(datetime.now(), '%Y-%m-%d'))
company_id = fields.Many2one('res.company', string='Company', required=True,
change_default=True,
readonly=True,
default=lambda self: self.env['res.company']._company_default_get())
is_company = fields.Boolean(string='Is a company')
is_operation = fields.Boolean(string='Is an operation')
company_name = fields.Char(string="Company name")
company_email = fields.Char(string="Company email")
company_register_number = fields.Char(string='Company register number')
company_type = fields.Selection([('scrl','SCRL'),
('asbl','ASBL'),
('sprl','SPRL'),
('sa','SA'),
('other','Other')])
company_type = fields.Selection([('scrl', 'SCRL'),
('asbl', 'ASBL'),
('sprl', 'SPRL'),
('sa', 'SA'),
('other', 'Other')])
same_address = fields.Boolean(string='Same address')
activities_address = fields.Char(string='Activities address')
activities_city = fields.Char(string='Activities city')
activities_zip_code = fields.Char(string='Activities zip Code')
activities_country_id = fields.Many2one('res.country', string='Activities country', ondelete='restrict')
activities_country_id = fields.Many2one('res.country',
string='Activities country',
ondelete='restrict')
contact_person_function = fields.Char(string='Function')
operation_request_id = fields.Many2one('operation.request', string="Operation Request")
operation_request_id = fields.Many2one('operation.request',
string="Operation Request")
is_operation = fields.Boolean(string="Is Operation request")
capital_release_request = fields.One2many('account.invoice','subscription_request',
capital_release_request = fields.One2many('account.invoice',
'subscription_request',
string='Capital release request',
readonly=True)
capital_release_request_date = fields.Date(string="Force the capital release request date",
help="Keep empty to use the current date", copy=False)
source = fields.Selection([('website','Website'),
('crm','CRM'),
('manual','Manual'),
('operation','Operation')], string="Source", default="website")
help="Keep empty to use the current date",
copy=False)
source = fields.Selection([('website', 'Website'),
('crm', 'CRM'),
('manual', 'Manual'),
('operation', 'Operation')],
string="Source",
default="website")
_order = "id desc"
# declare this function in order to be overriden
@ -190,10 +238,11 @@ class subscription_request(models.Model):
def _prepare_invoice_line(self, product, partner, qty):
self.ensure_one()
res = {}
account = product.property_account_income_id or product.categ_id.property_account_income_categ_id
account = product.property_account_income_id \
or product.categ_id.property_account_income_categ_id
if not account:
raise UserError(_('Please define income account for this product: "%s" (id:%d) - or for its category: "%s".') % \
raise UserError(_('Please define income account for this product:'
' "%s" (id:%d) - or for its category: "%s".') %
(product.name, product.id, product.categ_id.name))
fpos = partner.property_account_position_id
@ -209,96 +258,110 @@ class subscription_request(models.Model):
'product_id': product.id or False,
}
return res
def send_capital_release_request(self, invoice):
invoice_email_template = self.env['mail.template'].search([('name', '=', 'Request to Release Capital - Send by Email')])[0]
# we send the email with the capital release request in attachment
invoice_email_template.send_mail(invoice.id, True)
invoice.sent = True
def create_invoice(self, partner):
# get subscription journal
journal = self.env['account.journal'].search([('code','=','SUBJ')])[0]
journal = self.env['account.journal'].search([('code', '=', 'SUBJ')])[0]
# get the account for associate
# TODO this should be defined in configuration
if self.company_id.property_cooperator_account:
account = self.company_id.property_cooperator_account
else:
account = self.env['account.account'].search([('code','=','416000')])[0]
account = self.env['account.account'].search([('code', '=', '416000')])[0]
# creating invoice and invoice lines
invoice_vals = {'partner_id':partner.id,
'journal_id':journal.id,'account_id':account.id,
'type': 'out_invoice', 'release_capital_request':True,
'subscription_request':self.id}
invoice_vals = {'partner_id': partner.id,
'journal_id': journal.id,
'account_id': account.id,
'type': 'out_invoice',
'release_capital_request': True,
'subscription_request': self.id}
if self.capital_release_request_date:
invoice_vals['date_invoice'] = self.capital_release_request_date
invoice = self.env['account.invoice'].create(invoice_vals)
vals = self._prepare_invoice_line(self.share_product_id, partner, self.ordered_parts)
vals = self._prepare_invoice_line(self.share_product_id, partner,
self.ordered_parts)
vals['invoice_id'] = invoice.id
line = self.env['account.invoice.line'].create(vals)
self.env['account.invoice.line'].create(vals)
# validate the capital release request
invoice.signal_workflow('invoice_open')
self.send_capital_release_request(invoice)
return invoice
return invoice
def get_partner_company_vals(self):
# this should go to the many2many tag field
#'title':'company',
#self.env['res.partner.title'].search([('shortcut','=',self.company_type)])
partner_vals = {'name':self.company_name, 'is_company': self.is_company,
'company_register_number':self.company_register_number, 'customer':False,
'cooperator':True, 'street':self.address, 'zip':self.zip_code,
'city': self.city,'email':self.company_email, 'out_inv_comm_type':'bba','customer': self.share_product_id.customer,
'out_inv_comm_algorithm':'random', 'country_id': self.country_id.id, 'lang':self.lang}
partner_vals = {'name': self.company_name,
'is_company': self.is_company,
'company_register_number': self.company_register_number,
'customer': False, 'cooperator': True,
'street': self.address, 'zip': self.zip_code,
'city': self.city, 'email': self.company_email,
'out_inv_comm_type': 'bba',
'customer': self.share_product_id.customer,
'out_inv_comm_algorithm': 'random',
'country_id': self.country_id.id,
'lang': self.lang}
return partner_vals
def get_partner_vals(self):
partner_vals = {'name':self.name, 'first_name':self.firstname, 'last_name': self.lastname,
'gender':self.gender,'cooperator':True, 'street':self.address,'zip':self.zip_code,
'city': self.city, 'phone': self.phone, 'email':self.email,
'national_register_number':self.no_registre, 'out_inv_comm_type':'bba',
'out_inv_comm_algorithm':'random', 'country_id': self.country_id.id,
'lang':self.lang, 'birthdate':self.birthdate, 'customer': self.share_product_id.customer}
partner_vals = {'name': self.name, 'first_name': self.firstname,
'last_name': self.lastname, 'street': self.address,
'zip': self.zip_code, 'email': self.email,
'gender': self.gender, 'cooperator': True,
'city': self.city, 'phone': self.phone,
'national_register_number': self.no_registre,
'out_inv_comm_type': 'bba',
'out_inv_comm_algorithm': 'random',
'country_id': self.country_id.id, 'lang': self.lang,
'birthdate': self.birthdate,
'customer': self.share_product_id.customer}
return partner_vals
def create_coop_partner(self):
partner_obj = self.env['res.partner']
if self.is_company:
partner_vals = self.get_partner_company_vals()
else:
else:
partner_vals = self.get_partner_vals()
partner = partner_obj.create(partner_vals)
if self.iban :
self.env['res.partner.bank'].create({'partner_id':partner.id,'acc_number':self.iban})
return partner
if self.iban:
self.env['res.partner.bank'].create({
'partner_id': partner.id,
'acc_number': self.iban
})
return partner
def create_user(self, partner):
user_obj = self.env['res.users']
email = self.email
if self.is_company:
email = self.company_email
user = user_obj.search([('login','=',email)])
user = user_obj.search([('login', '=', email)])
if not user:
user_values = {'partner_id': partner.id,'login':email}
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']
if self.ordered_parts <= 0:
raise UserError(_('Number of share must be greater than 0.'))
if self.partner_id:
@ -307,11 +370,12 @@ class subscription_request(models.Model):
partner = self.partner_id
else:
if self.already_cooperator:
raise UserError(_('The checkbox already cooperator is checked please select a cooperator.'))
raise UserError(_('The checkbox already cooperator is'
' checked please select a cooperator.'))
elif self.is_company and self.company_register_number:
partner = partner_obj.search([('company_register_number','=',self.company_register_number)])
partner = partner_obj.search([('company_register_number', '=', self.company_register_number)])
elif self.no_registre:
partner = partner_obj.search([('national_register_number','=',self.no_registre)])
partner = partner_obj.search([('national_register_number', '=', self.no_registre)])
else:
partner = None
@ -320,32 +384,47 @@ class subscription_request(models.Model):
else:
partner = partner[0]
if self.is_company and not partner.has_representative():
if self.is_company and not partner.has_representative():
contact = False
if self.no_registre:
contact = partner_obj.search([('national_register_number','=',self.no_registre)])
contact = partner_obj.search([('national_register_number', '=', self.no_registre)])
if contact:
contact.type = 'representative'
if not contact:
contact_vals = {'name':self.name, 'first_name':self.firstname, 'last_name': self.lastname,
'customer':False, 'is_company':False, 'cooperator':True,
'street':self.address,'zip':self.zip_code,'gender':self.gender,
'city': self.city, 'phone': self.phone, 'email':self.email,
'national_register_number':self.no_registre, 'out_inv_comm_type':'bba',
'out_inv_comm_algorithm':'random', 'country_id': self.country_id.id,
'lang':self.lang, 'birthdate_date':self.birthdate, 'parent_id': partner.id,
'function':self.contact_person_function,'representative':True,'type':'representative'}
contact_vals = {'name': self.name,
'first_name': self.firstname,
'last_name': self.lastname, 'customer': False,
'is_company': False, 'cooperator': True,
'street': self.address, 'gender': self.gender,
'zip': self.zip_code, 'city': self.city,
'phone': self.phone, 'email': self.email,
'national_register_number': self.no_registre,
'country_id': self.country_id.id,
'out_inv_comm_type': 'bba',
'out_inv_comm_algorithm': 'random',
'lang': self.lang,
'birthdate_date': self.birthdate,
'parent_id': partner.id,
'representative': True,
'function': self.contact_person_function,
'type': 'representative'}
contact = partner_obj.create(contact_vals)
else:
if len(contact) > 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 contact.parent_id and contact.parent_id.id != partner.id:
raise UserError(_('This contact person is already defined for another company. Please select another contact'))
raise UserError(_('This contact person is already defined'
' for another company. Please select'
' another contact'))
else:
contact.write({'parent_id':partner.id,'representative':True})
contact.write({'parent_id': partner.id,
'representative': True})
invoice = self.create_invoice(partner)
self.write({'partner_id':partner.id, 'state':'done'})
self.write({'partner_id': partner.id, 'state': 'done'})
self.create_user(partner)
@ -353,80 +432,132 @@ class subscription_request(models.Model):
@api.one
def block_subscription_request(self):
self.write({'state':'block'})
@api.one
self.write({'state': 'block'})
@api.one
def unblock_subscription_request(self):
self.write({'state':'draft'})
@api.one
self.write({'state': 'draft'})
@api.one
def cancel_subscription_request(self):
self.write({'state':'cancelled'})
self.write({'state': 'cancelled'})
@api.one
@api.one
def put_on_waiting_list(self):
self.write({'state':'waiting'})
self.write({'state': 'waiting'})
class share_line(models.Model):
_name='share.line'
_name = 'share.line'
@api.multi
def _compute_total_line(self):
res = {}
for line in self:
line.total_amount_line = line.share_unit_price * line.share_number
return res
share_product_id = fields.Many2one('product.product', string='Share type', required=True, readonly=True)
share_number = fields.Integer(string='Number of Share', required=True, readonly=True)
share_short_name = fields.Char(related='share_product_id.short_name', string='Share type name')
share_unit_price = fields.Float(string='Share price', readonly=True)
effective_date = fields.Date(string='Effective Date', readonly=True)
partner_id = fields.Many2one('res.partner',string='Cooperator', required=True, ondelete='cascade', readonly=True)
total_amount_line = fields.Float(compute='_compute_total_line', string='Total amount line')
class subscription_register(models.Model):
_name= 'subscription.register'
share_product_id = fields.Many2one('product.product',
string='Share type',
required=True,
readonly=True)
share_number = fields.Integer(string='Number of Share',
required=True,
readonly=True)
share_short_name = fields.Char(related='share_product_id.short_name',
string='Share type name')
share_unit_price = fields.Float(string='Share price',
readonly=True)
effective_date = fields.Date(string='Effective Date',
readonly=True)
partner_id = fields.Many2one('res.partner',
string='Cooperator',
required=True,
ondelete='cascade',
readonly=True)
total_amount_line = fields.Float(compute='_compute_total_line',
string='Total amount line')
class subscription_register(models.Model):
_name = 'subscription.register'
@api.multi
def _compute_total_line(self):
res = {}
for register_line in self:
register_line.total_amount_line = register_line.share_unit_price * register_line.quantity
name = fields.Char(string='Register Number Operation', required=True, readonly=True)
register_number_operation = fields.Integer(string='Register Number Operation', required=True, readonly=True)
partner_id = fields.Many2one('res.partner',string='Cooperator', required=True, readonly=True)
partner_id_to = fields.Many2one('res.partner',string='Transfered to', readonly=True)
date = fields.Date(string='Subscription Date', required= True, readonly=True)
quantity = fields.Integer(string='Number of share', readonly=True)
share_unit_price = fields.Float(string='Share price', readonly=True)
total_amount_line = fields.Float(compute='_compute_total_line', string='Total amount line')
share_product_id = fields.Many2one('product.product', string='Share type', required=True, readonly=True, domain=[('is_share','=',True)])
share_short_name = fields.Char(related='share_product_id.short_name', string='Share type name', readonly=True)
share_to_product_id = fields.Many2one('product.product', string='Share to type', readonly=True, domain=[('is_share','=',True)])
share_to_short_name = fields.Char(related='share_to_product_id.short_name', string='Share to type name', readonly=True)
quantity_to = fields.Integer(string='Number of share to', readonly=True)
share_to_unit_price = fields.Float(string='Share to price', readonly=True)
type = fields.Selection([('subscription','Subscription'),
('transfer','Transfer'),
('sell_back','Sell Back'),
('convert','Conversion')],
name = fields.Char(string='Register Number Operation',
required=True,
readonly=True)
register_number_operation = fields.Integer(string='Register Number Operation',
required=True,
readonly=True)
partner_id = fields.Many2one('res.partner',
string='Cooperator',
required=True,
readonly=True)
partner_id_to = fields.Many2one('res.partner',
string='Transfered to',
readonly=True)
date = fields.Date(string='Subscription Date',
required=True,
readonly=True)
quantity = fields.Integer(string='Number of share',
readonly=True)
share_unit_price = fields.Float(string='Share price',
readonly=True)
total_amount_line = fields.Float(compute='_compute_total_line',
string='Total amount line')
share_product_id = fields.Many2one('product.product',
string='Share type',
required=True,
readonly=True,
domain=[('is_share', '=', True)])
share_short_name = fields.Char(related='share_product_id.short_name',
string='Share type name',
readonly=True)
share_to_product_id = fields.Many2one('product.product',
string='Share to type',
readonly=True,
domain=[('is_share', '=', True)])
share_to_short_name = fields.Char(related='share_to_product_id.short_name',
string='Share to type name',
readonly=True)
quantity_to = fields.Integer(string='Number of share to',
readonly=True)
share_to_unit_price = fields.Float(string='Share to price',
readonly=True)
type = fields.Selection([('subscription', 'Subscription'),
('transfer', 'Transfer'),
('sell_back', 'Sell Back'),
('convert', 'Conversion')],
string='Operation Type', readonly=True)
company_id = fields.Many2one('res.company', string='Company', required=True,
company_id = fields.Many2one('res.company', string='Company',
required=True,
change_default=True, readonly=True,
default=lambda self: self.env['res.company']._company_default_get())
user_id = fields.Many2one('res.users', string='Responsible', readonly=True, default=lambda self: self.env.user)
user_id = fields.Many2one('res.users',
string='Responsible',
readonly=True,
default=lambda self: self.env.user)
_order = "register_number_operation asc"
@api.model
def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True):
def read_group(self, domain, fields, groupby, offset=0, limit=None,
orderby=False,
lazy=True):
if 'share_unit_price' in fields:
fields.remove('share_unit_price')
if 'register_number_operation' in fields:
fields.remove('register_number_operation')
res = super(subscription_register, self).read_group(domain, fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy)
res = super(subscription_register, self).read_group(domain, fields,
groupby,
offset=offset,
limit=limit,
orderby=orderby,
lazy=lazy)
if 'total_amount_line' in fields:
for line in res:
if '__domain' in line:

262
easy_my_coop/models/operation_request.py

@ -4,96 +4,129 @@ from datetime import datetime
from openerp import api, fields, models, _
from openerp.exceptions import ValidationError
class operation_request(models.Model):
_name = 'operation.request'
def get_date_now(self):
return datetime.strftime(datetime.now(), '%Y-%m-%d')
@api.multi
@api.depends('share_product_id', 'share_product_id.list_price','quantity')
@api.depends('share_product_id', 'share_product_id.list_price', 'quantity')
def _compute_subscription_amount(self):
for operation_request in self:
operation_request.subscription_amount = operation_request.share_product_id.list_price * operation_request.quantity
request_date = fields.Date(string='Request date', default=lambda self: self.get_date_now())
partner_id = fields.Many2one('res.partner', string='Cooperator', domain=[('member','=',True)],required=True)
partner_id_to = fields.Many2one('res.partner',string='Transfered to', domain=[('cooperator','=',True)])
operation_type = fields.Selection([('subscription','Subscription'),
('transfer','Transfer'),
('sell_back','Sell Back'),
('convert','Conversion')],string='Operation Type', required=True)
share_product_id = fields.Many2one('product.product', string='Share type', domain=[('is_share','=',True)], required=True)
share_to_product_id = fields.Many2one('product.product', string='Convert to this share type', domain=[('is_share','=',True)])
share_short_name = fields.Char(related='share_product_id.short_name', string='Share type name')
share_to_short_name = fields.Char(related='share_to_product_id.short_name', string='Share to type name')
share_unit_price = fields.Float(related='share_product_id.list_price', string='Share price')
share_to_unit_price = fields.Float(related='share_to_product_id.list_price', string='Share to price')
subscription_amount = fields.Float(compute='_compute_subscription_amount', string='Operation amount')
quantity = fields.Integer(string='Number of share', required=True)
state = fields.Selection([('draft','Draft'),
('waiting','Waiting'),
('approved','Approved'),
('done','Done'),
('cancelled','Cancelled'),
('refused','Refused')], string='State',required=True, default='draft')
user_id = fields.Many2one('res.users', string='Responsible', readonly=True, default=lambda self: self.env.user)
subscription_request = fields.One2many('subscription.request','operation_request_id',
string="Share Receiver Info",
help="In case on a transfer of share. "
"If the share receiver isn't a effective member "
"then a subscription form should be filled.")
request_date = fields.Date(string='Request date',
default=lambda self: self.get_date_now())
partner_id = fields.Many2one('res.partner',
string='Cooperator',
domain=[('member', '=', True)],
required=True)
partner_id_to = fields.Many2one('res.partner',
string='Transfered to',
domain=[('cooperator', '=', True)])
operation_type = fields.Selection([('subscription', 'Subscription'),
('transfer', 'Transfer'),
('sell_back', 'Sell Back'),
('convert', 'Conversion')],
string='Operation Type',
required=True)
share_product_id = fields.Many2one('product.product',
string='Share type',
domain=[('is_share', '=', True)],
required=True)
share_to_product_id = fields.Many2one('product.product',
string='Convert to this share type',
domain=[('is_share', '=', True)])
share_short_name = fields.Char(related='share_product_id.short_name',
string='Share type name')
share_to_short_name = fields.Char(related='share_to_product_id.short_name',
string='Share to type name')
share_unit_price = fields.Float(related='share_product_id.list_price',
string='Share price')
share_to_unit_price = fields.Float(related='share_to_product_id.list_price',
string='Share to price')
subscription_amount = fields.Float(compute='_compute_subscription_amount',
string='Operation amount')
quantity = fields.Integer(string='Number of share',
required=True)
state = fields.Selection([('draft', 'Draft'),
('waiting', 'Waiting'),
('approved', 'Approved'),
('done', 'Done'),
('cancelled', 'Cancelled'),
('refused', 'Refused')],
string='State',
required=True,
default='draft')
user_id = fields.Many2one('res.users',
string='Responsible',
readonly=True,
default=lambda self: self.env.user)
subscription_request = fields.One2many('subscription.request',
'operation_request_id',
string="Share Receiver Info",
help="In case on a transfer of"
" share. If the share receiver"
" isn't a effective member then a"
" subscription form should"
" be filled.")
receiver_not_member = fields.Boolean(string='Receiver is not a member')
company_id = fields.Many2one('res.company', string='Company', required=True,
change_default=True, readonly=True,
company_id = fields.Many2one('res.company',
string='Company',
required=True,
change_default=True,
readonly=True,
default=lambda self: self.env['res.company']._company_default_get())
invoice = fields.Many2one('account.invoice', string="Invoice")
invoice = fields.Many2one('account.invoice',
string="Invoice")
@api.multi
def approve_operation(self):
for rec in self:
rec.write({'state':'approved'})
rec.write({'state': 'approved'})
@api.multi
def refuse_operation(self):
for rec in self:
rec.write({'state':'refused'})
rec.write({'state': 'refused'})
@api.multi
def submit_operation(self):
for rec in self:
rec.validate()
rec.write({'state':'waiting'})
rec.write({'state': 'waiting'})
@api.multi
def cancel_operation(self):
for rec in self:
rec.write({'state':'cancelled'})
rec.write({'state': 'cancelled'})
@api.multi
def reset_to_draft(self):
for rec in self:
rec.write({'state':'draft'})
rec.write({'state': 'draft'})
def get_total_share_dic(self, partner):
total_share_dic = {}
share_products = self.env['product.template'].search([('is_share','=',True)])
share_products = self.env['product.template'].search([('is_share', '=', True)])
for share_product in share_products:
total_share_dic[share_product.id] = 0
for line in partner.share_ids:
total_share_dic[line.share_product_id.id] += line.share_number
return total_share_dic
# This function doesn't handle the case of a cooperator can own
# This function doesn't handle the case of a cooperator can own
# different kinds of share type
def hand_share_over(self, partner, share_product_id, quantity):
if not partner.member:
raise ValidationError(_("This operation can't be executed if the cooperator is not an effective member"))
share_ind = len(partner.share_ids)
i = 1
while quantity > 0:
@ -107,13 +140,14 @@ class operation_request(models.Model):
quantity = 0
line.write({'share_number': share_left})
i += 1
# if the cooperator sold all his shares he's no more an effective member
# if the cooperator sold all his shares he's no more
# an effective member
remaning_share_dict = 0
for share_quant in self.get_total_share_dic(partner).values():
remaning_share_dict += share_quant
if remaning_share_dict == 0:
self.partner_id.write({'member': False,'old_member':True})
self.partner_id.write({'member': False, 'old_member': True})
def has_share_type(self):
for line in self.partner_id.share_ids:
if line.share_product_id.id == self.share_product_id.id:
@ -121,54 +155,61 @@ class operation_request(models.Model):
return False
def validate(self):
if not self.has_share_type() and self.operation_type in ['sell_back', 'transfer']:
raise ValidationError(_("The cooperator doesn't own this share type. Please choose the appropriate share type."))
if self.operation_type in ['sell_back','convert','transfer']:
if not self.has_share_type() and \
self.operation_type in ['sell_back', 'transfer']:
raise ValidationError(_("The cooperator doesn't own this share"
" type. Please choose the appropriate"
" share type."))
if self.operation_type in ['sell_back', 'convert', 'transfer']:
total_share_dic = self.get_total_share_dic(self.partner_id)
if self.quantity > total_share_dic[self.share_product_id.id]:
raise ValidationError(_("The cooperator can't hand over more shares that he/she owns."))
if self.operation_type == 'convert' and self.company_id.unmix_share_type:
raise ValidationError(_("The cooperator can't hand over more"
" shares that he/she owns."))
if self.operation_type == 'convert' and \
self.company_id.unmix_share_type:
if self.share_product_id.code == self.share_to_product_id.code:
raise ValidationError(_("You can't convert the share to the same share type."))
if self.subscription_amount != self.partner_id.total_value :
raise ValidationError(_("You must convert all the shares to the selected type."))
raise ValidationError(_("You can't convert the share to"
" the same share type."))
if self.subscription_amount != self.partner_id.total_value:
raise ValidationError(_("You must convert all the shares"
" to the selected type."))
elif self.operation_type == 'transfer':
if not self.receiver_not_member and self.company_id.unmix_share_type \
and (self.partner_id_to.cooperator_type \
and (self.partner_id_to.cooperator_type
and self.partner_id.cooperator_type != self.partner_id_to.cooperator_type):
raise ValidationError(_("This share type could not be transfered "
"to " + self.partner_id_to.name))
raise ValidationError(_("This share type could not be"
" transfered to " +
self.partner_id_to.name))
@api.multi
def execute_operation(self):
effective_date = self.get_date_now()
ir_sequence = self.env['ir.sequence']
sub_request = self.env['subscription.request']
email_template_obj = self.env['mail.template']
for rec in self:
rec.validate()
if rec.state != 'approved':
raise ValidationError(_("This operation must be approved before to be executed"))
raise ValidationError(_("This operation must be approved"
" before to be executed"))
values = {
'partner_id':rec.partner_id.id, 'quantity':rec.quantity,
'share_product_id':rec.share_product_id.id, 'type':rec.operation_type,
'share_unit_price': rec.share_unit_price, 'date':effective_date,
'partner_id': rec.partner_id.id, 'quantity': rec.quantity,
'share_product_id': rec.share_product_id.id, 'type': rec.operation_type,
'share_unit_price': rec.share_unit_price, 'date': effective_date,
}
if rec.operation_type == 'sell_back':
self.hand_share_over(rec.partner_id, rec.share_product_id, rec.quantity)
if rec.operation_type == 'sell_back':
self.hand_share_over(rec.partner_id, rec.share_product_id,
rec.quantity)
elif rec.operation_type == 'convert':
amount_to_convert = rec.share_unit_price * rec.quantity
convert_quant = int(amount_to_convert / rec.share_to_product_id.list_price)
remainder = amount_to_convert % rec.share_to_product_id.list_price
if rec.company_id.unmix_share_type:
if convert_quant > 0 and remainder == 0:
share_ids = rec.partner_id.share_ids
@ -176,60 +217,65 @@ class operation_request(models.Model):
if len(share_ids) > 1:
share_ids[1:len(share_ids)].unlink()
line.write({
'share_number':convert_quant,
'share_product_id':rec.share_to_product_id.id,
'share_number': convert_quant,
'share_product_id': rec.share_to_product_id.id,
'share_unit_price': rec.share_to_unit_price,
'share_short_name': rec.share_to_short_name
})
values['share_to_product_id'] = rec.share_to_product_id.id
values['quantity_to'] = convert_quant
else:
raise ValidationError(_("Converting just part of the shares is not yet implemented"))
raise ValidationError(_("Converting just part of the"
" shares is not yet implemented"))
elif rec.operation_type == 'transfer':
if rec.receiver_not_member:
partner = rec.subscription_request.create_coop_partner()
#get cooperator number
# get cooperator number
sequence_id = self.env.ref('easy_my_coop.sequence_subscription', False)
sub_reg_num = sequence_id.next_by_id()
partner_vals = sub_request.get_eater_vals(partner, rec.share_product_id)
partner_vals['member'] = True
partner_vals['cooperator_register_number'] = int(sub_reg_num)
partner.write(partner_vals)
rec.partner_id_to = partner
rec.partner_id_to = partner
else:
if not rec.partner_id_to.member:
partner_vals = sub_request.get_eater_vals(rec.partner_id_to, rec.share_product_id)
partner_vals = sub_request.get_eater_vals(
rec.partner_id_to,
rec.share_product_id)
partner_vals['member'] = True
partner_vals['old_member'] = False
rec.partner_id_to.write(partner_vals)
#remove the parts to the giver
self.hand_share_over(rec.partner_id, rec.share_product_id, rec.quantity)
#give the share to the receiver
self.env['share.line'].create({'share_number':rec.quantity,
'partner_id':rec.partner_id_to.id,
'share_product_id':rec.share_product_id.id,
'share_unit_price':rec.share_unit_price,
'effective_date':effective_date})
# remove the parts to the giver
self.hand_share_over(rec.partner_id,
rec.share_product_id,
rec.quantity)
# give the share to the receiver
self.env['share.line'].create({
'share_number': rec.quantity,
'partner_id': rec.partner_id_to.id,
'share_product_id': rec.share_product_id.id,
'share_unit_price': rec.share_unit_price,
'effective_date': effective_date})
values['partner_id_to'] = rec.partner_id_to.id
else:
raise ValidationError(_("This operation is not yet implemented."))
#sequence_operation = ir_sequence.search([('name','=','Register Operation')])[0]
raise ValidationError(_("This operation is not yet"
" implemented."))
sequence_operation = self.env.ref('easy_my_coop.sequence_register_operation', False)
sub_reg_operation = sequence_operation.next_by_id()
values['name'] = sub_reg_operation
values['register_number_operation'] = int(sub_reg_operation)
rec.write({'state':'done'})
rec.write({'state': 'done'})
# send mail and to the receiver
if rec.operation_type == 'transfer':
certificat_email_template = self.env.ref('easy_my_coop.email_template_share_transfer', False)
certificat_email_template.send_mail(rec.partner_id_to.id, False)
self.env['subscription.register'].create(values)
certificat_email_template = self.env.ref('easy_my_coop.email_template_share_update', False)
certificat_email_template.send_mail(rec.partner_id.id, False)

96
easy_my_coop/models/partner.py

@ -13,7 +13,7 @@ class ResPartner(models.Model):
# res = cr.fetchone()
# if not 'date' in res:
# cr.execute("ALTER TABLE res_partner ALTER COLUMN birthdate TYPE date USING birthdate::date;")
#
#
# return super(ResPartner, self)._auto_init(cr, context=context)
@api.multi
@ -22,8 +22,7 @@ class ResPartner(models.Model):
if not self.ids:
self.total_invoiced = 0.0
return True
user_currency_id = self.env.user.company_id.currency_id.id
all_partners_and_children = {}
all_partner_ids = []
for partner in self:
@ -38,9 +37,11 @@ class ResPartner(models.Model):
# generate where clause to include multicompany rules
where_query = account_invoice_report._where_calc([
('partner_id', 'in', all_partner_ids), ('state', 'not in', ['draft', 'cancel']), ('company_id', '=', self.env.user.company_id.id),
('partner_id', 'in', all_partner_ids),
('state', 'not in', ['draft', 'cancel']),
('company_id', '=', self.env.user.company_id.id),
('type', 'in', ('out_invoice', 'out_refund')),
('release_capital_request','=',False),
('release_capital_request', '=', False),
])
account_invoice_report._apply_ir_rules(where_query, 'read')
from_clause, where_clause, where_clause_params = where_query.get_sql()
@ -59,19 +60,20 @@ class ResPartner(models.Model):
@api.multi
def _get_share_type(self):
share_type_list = [('','')]
for share_type in self.env['product.product'].search([('is_share','=',True)]):
share_type_list.append((str(share_type.id),share_type.short_name))
product_obj = self.env['product.product']
share_type_list = [('', '')]
for share_type in product_obj.search([('is_share', '=', True)]):
share_type_list.append((str(share_type.id), share_type.short_name))
return share_type_list
@api.multi
@api.depends('share_ids')
def _compute_effective_date(self):
#TODO change it to compute it from the share register
# TODO change it to compute it from the share register
for partner in self:
if partner.share_ids:
partner.effective_date = partner.share_ids[0].effective_date
partner.effective_date = partner.share_ids[0].effective_date
@api.multi
@api.depends('share_ids')
def _compute_cooperator_type(self):
@ -87,30 +89,56 @@ class ResPartner(models.Model):
def _compute_share_info(self):
for partner in self:
number_of_share = 0
total_value = 0.0
total_value = 0.0
for line in partner.share_ids:
number_of_share += line.share_number
total_value += line.share_unit_price * line.share_number
partner.number_of_share = number_of_share
partner.total_value = total_value
cooperator = fields.Boolean(string='Cooperator', help="Check this box if this contact is a cooperator(effective or not).")
member = fields.Boolean(string='Effective cooperator', help="Check this box if this cooperator is an effective member.")
coop_candidate = fields.Boolean(string="Cooperator candidate", compute="_compute_coop_candidate", store=True, readonly=True)
old_member = fields.Boolean(string='Old cooperator', help="Check this box if this cooperator is no more an effective member.")
gender = fields.Selection([('male', 'Male'), ('female', 'Female'), ('other', 'Other')], string='Gender')
cooperator = fields.Boolean(string='Cooperator',
help="Check this box if this contact is a"
" cooperator(effective or not).")
member = fields.Boolean(string='Effective cooperator',
help="Check this box if this cooperator"
" is an effective member.")
coop_candidate = fields.Boolean(string="Cooperator candidate",
compute="_compute_coop_candidate",
store=True,
readonly=True)
old_member = fields.Boolean(string='Old cooperator',
help="Check this box if this cooperator is"
" no more an effective member.")
gender = fields.Selection([('male', 'Male'),
('female', 'Female'),
('other', 'Other')],
string='Gender')
national_register_number = fields.Char(string='National Register Number')
share_ids = fields.One2many('share.line','partner_id',string='Share Lines')
share_ids = fields.One2many('share.line',
'partner_id',
string='Share Lines')
cooperator_register_number = fields.Integer(string='Cooperator Number')
#birthdate = fields.Date(string="Birthdate")
number_of_share = fields.Integer(compute="_compute_share_info", multi='share', string='Number of share', readonly=True)
total_value = fields.Float(compute="_compute_share_info", multi='share', string='Total value of shares', readonly=True)
number_of_share = fields.Integer(compute="_compute_share_info",
multi='share',
string='Number of share',
readonly=True)
total_value = fields.Float(compute="_compute_share_info",
multi='share',
string='Total value of shares',
readonly=True)
company_register_number = fields.Char(string='Company Register Number')
cooperator_type = fields.Selection(selection='_get_share_type', compute='_compute_cooperator_type', string='Cooperator Type', store=True)
effective_date = fields.Date(sting="Effective Date", compute='_compute_effective_date', store=True)
cooperator_type = fields.Selection(selection='_get_share_type',
compute=_compute_cooperator_type,
string='Cooperator Type',
store=True)
effective_date = fields.Date(sting="Effective Date",
compute=_compute_effective_date,
store=True)
representative = fields.Boolean(string="Legal Representative")
subscription_request_ids = fields.One2many('subscription.request', 'partner_id', string="Subscription request")
subscription_request_ids = fields.One2many('subscription.request',
'partner_id',
string="Subscription request")
@api.multi
@api.depends('subscription_request_ids.state')
def _compute_coop_candidate(self):
@ -120,21 +148,23 @@ class ResPartner(models.Model):
else:
if len(partner.subscription_request_ids.filtered(lambda record: record.state == 'done')) > 0:
is_candidate = True
else :
else:
is_candidate = False
partner.coop_candidate = is_candidate
def has_representative(self):
if self.child_ids.filtered('representative'):
return True
return False
def get_representative(self):
return self.child_ids.filtered('representative')
def get_cooperator_from_nin(self, national_id_number):
return self.search([('cooperator','=',True),('national_register_number','=',national_id_number)])
return self.search([('cooperator', '=', True),
('national_register_number', '=', national_id_number)])
def get_cooperator_from_crn(self, company_register_number):
return self.search([('cooperator','=',True),('company_register_number','=',company_register_number)])
return self.search([('cooperator', '=', True),
('company_register_number', '=', company_register_number)])

16
easy_my_coop/models/product.py

@ -4,7 +4,7 @@ from openerp import api, fields, models
class ProductTemplate(models.Model):
_inherit = 'product.template'
is_share = fields.Boolean(string='Is share?')
short_name = fields.Char(string='Short name')
display_on_website = fields.Boolean(string='Display on website')
@ -14,11 +14,17 @@ class ProductTemplate(models.Model):
by_company = fields.Boolean(string="Can be subscribed by companies?")
by_individual = fields.Boolean(string="Can be subscribed by individuals?")
customer = fields.Boolean(string='Become customer')
@api.multi
def get_web_share_products(self, is_company):
if is_company == True:
product_templates = self.env['product.template'].search([('is_share','=',True), ('display_on_website','=',True),('by_company','=',True)])
if is_company is True:
product_templates = self.env['product.template'].search([
('is_share', '=', True),
('display_on_website', '=', True),
('by_company', '=', True)])
else:
product_templates = self.env['product.template'].search([('is_share','=',True), ('display_on_website','=',True),('by_individual','=',True)])
product_templates = self.env['product.template'].search([
('is_share', '=', True),
('display_on_website', '=', True),
('by_individual', '=', True)])
return product_templates

2
easy_my_coop/models/res_partner_bank.py

@ -7,4 +7,4 @@ class ResPartnerBank(models.Model):
_sql_constraints = [
('unique_number', 'Check(1=1)', 'Account Number must be unique!'),
]
]
Loading…
Cancel
Save