Browse Source

[PEP8] make the code compliant with PEP8

pull/1/head
houssine 6 years ago
parent
commit
923daeda34
  1. 3
      easy_my_coop/models/account_journal.py
  2. 30
      easy_my_coop/models/company.py
  3. 389
      easy_my_coop/models/coop.py
  4. 194
      easy_my_coop/models/operation_request.py
  5. 74
      easy_my_coop/models/partner.py
  6. 12
      easy_my_coop/models/product.py

3
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?')

30
easy_my_coop/models/company.py

@ -1,23 +1,35 @@
# -*- 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,
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",
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")
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")

389
easy_my_coop/models/coop.py

@ -5,13 +5,26 @@ 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'
@ -20,11 +33,13 @@ class subscription_request(models.Model):
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
# been founded a way to avoid dubble entry
@ -37,10 +52,10 @@ 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
@ -84,12 +99,12 @@ class subscription_request(models.Model):
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
@ -99,89 +114,122 @@ class subscription_request(models.Model):
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)
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')],
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")
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)
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'))
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,
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
@ -219,25 +268,28 @@ class subscription_request(models.Model):
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')
@ -247,23 +299,31 @@ class subscription_request(models.Model):
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):
@ -275,8 +335,11 @@ class subscription_request(models.Model):
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})
if self.iban:
self.env['res.partner.bank'].create({
'partner_id': partner.id,
'acc_number': self.iban
})
return partner
def create_user(self, partner):
@ -286,9 +349,9 @@ class subscription_request(models.Model):
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()
@ -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
@ -323,29 +387,44 @@ class subscription_request(models.Model):
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,22 +432,23 @@ class subscription_request(models.Model):
@api.one
def block_subscription_request(self):
self.write({'state':'block'})
self.write({'state': 'block'})
@api.one
def unblock_subscription_request(self):
self.write({'state':'draft'})
self.write({'state': 'draft'})
@api.one
def cancel_subscription_request(self):
self.write({'state':'cancelled'})
self.write({'state': 'cancelled'})
@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):
@ -377,56 +457,107 @@ class share_line(models.Model):
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')
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'
_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:

194
easy_my_coop/models/operation_request.py

@ -4,6 +4,7 @@ from datetime import datetime
from openerp import api, fields, models, _
from openerp.exceptions import ValidationError
class operation_request(models.Model):
_name = 'operation.request'
@ -11,74 +12,106 @@ class operation_request(models.Model):
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',
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.")
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
@ -107,12 +140,13 @@ 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:
@ -121,49 +155,56 @@ 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 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 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."))
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.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)
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)
@ -176,19 +217,20 @@ 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)
@ -198,30 +240,35 @@ class operation_request(models.Model):
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."))
raise ValidationError(_("This operation is not yet"
" implemented."))
#sequence_operation = ir_sequence.search([('name','=','Register Operation')])[0]
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':
@ -232,4 +279,3 @@ class operation_request(models.Model):
certificat_email_template = self.env.ref('easy_my_coop.email_template_share_update', False)
certificat_email_template.send_mail(rec.partner_id.id, False)

74
easy_my_coop/models/partner.py

@ -23,7 +23,6 @@ class ResPartner(models.Model):
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,15 +60,16 @@ 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
@ -94,22 +96,48 @@ class ResPartner(models.Model):
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')
@ -120,7 +148,7 @@ 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
@ -134,7 +162,9 @@ class ResPartner(models.Model):
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)])

12
easy_my_coop/models/product.py

@ -17,8 +17,14 @@ class ProductTemplate(models.Model):
@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
Loading…
Cancel
Save