@ -5,30 +5,45 @@ from openerp import api, fields, models, _
from openerp.addons.base_iban import base_iban
from openerp.addons.base_iban import base_iban
from openerp.exceptions import UserError , ValidationError
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
@api.model
def _lang_get ( self ) :
def _lang_get ( self ) :
languages = self . env [ ' res.lang ' ] . search ( [ ] )
languages = self . env [ ' res.lang ' ] . search ( [ ] )
return [ ( language . code , language . name ) for language in languages ]
return [ ( language . code , language . name ) for language in languages ]
class subscription_request ( models . Model ) :
class subscription_request ( models . Model ) :
_name = ' subscription.request '
_name = ' subscription.request '
_description = ' Subscription Request '
_description = ' Subscription Request '
def get_required_field ( self ) :
def get_required_field ( self ) :
return _REQUIRED
return _REQUIRED
@api.model
@api.model
def create ( self , vals ) :
def create ( self , vals ) :
partner_obj = self . env [ ' res.partner ' ]
if not vals . get ( ' partner_id ' ) :
if not vals . get ( ' partner_id ' ) :
cooperator = False
cooperator = False
if vals . get ( ' no_registre ' ) :
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 :
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
# been founded a way to avoid dubble entry
cooperator = cooperator [ 0 ]
cooperator = cooperator [ 0 ]
if cooperator . member :
if cooperator . member :
vals [ ' type ' ] = ' increase '
vals [ ' type ' ] = ' increase '
vals [ ' already_cooperator ' ] = True
vals [ ' already_cooperator ' ] = True
@ -37,21 +52,21 @@ class subscription_request(models.Model):
vals [ ' partner_id ' ] = cooperator . id
vals [ ' partner_id ' ] = cooperator . id
if not cooperator . cooperator :
if not cooperator . cooperator :
cooperator . write ( { ' cooperator ' : True } )
cooperator . write ( { ' cooperator ' : True } )
else :
else :
cooperator_id = vals . get ( ' partner_id ' )
cooperator_id = vals . get ( ' partner_id ' )
cooperator = self . env [ ' res.partner ' ] . browse ( cooperator_id )
cooperator = partner_obj . browse ( cooperator_id )
if cooperator . member :
if cooperator . member :
vals [ ' type ' ] = ' increase '
vals [ ' type ' ] = ' increase '
vals [ ' already_cooperator ' ] = True
vals [ ' already_cooperator ' ] = True
subscr_request = super ( subscription_request , self ) . create ( vals )
subscr_request = super ( subscription_request , self ) . create ( vals )
confirmation_mail_template = self . env . ref ( ' easy_my_coop.email_template_confirmation ' , False )
confirmation_mail_template = self . env . ref ( ' easy_my_coop.email_template_confirmation ' , False )
confirmation_mail_template . send_mail ( subscr_request . id )
confirmation_mail_template . send_mail ( subscr_request . id )
return subscr_request
return subscr_request
@api.model
@api.model
def create_comp_sub_req ( self , vals ) :
def create_comp_sub_req ( self , vals ) :
if not vals . get ( ' partner_id ' ) :
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 = self . env . ref ( ' easy_my_coop.email_template_confirmation_company ' , False )
confirmation_mail_template . send_mail ( subscr_request . id , True )
confirmation_mail_template . send_mail ( subscr_request . id , True )
return subscr_request
return subscr_request
def check_belgian_identification_id ( self , nat_register_num ) :
def check_belgian_identification_id ( self , nat_register_num ) :
if not self . check_empty_string ( nat_register_num ) :
if not self . check_empty_string ( nat_register_num ) :
return False
return False
@ -82,14 +97,14 @@ class subscription_request(models.Model):
if int ( check_controle ) != int ( controle ) :
if int ( check_controle ) != int ( controle ) :
return False
return False
return True
return True
def check_empty_string ( self , value ) :
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 False
return True
return True
@api.multi
@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 ) :
def _validated_lines ( self ) :
for sub_request in self :
for sub_request in self :
validated = False
validated = False
@ -98,90 +113,123 @@ class subscription_request(models.Model):
validated = True
validated = True
except ValidationError :
except ValidationError :
validated = False
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
validated = True
else :
else :
validated = False
validated = False
sub_request . validated = validated
sub_request . validated = validated
@api.multi
@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 ) :
def _compute_subscription_amount ( self ) :
for sub_request in self :
for sub_request in self :
sub_request . subscription_amount = sub_request . share_product_id . list_price * sub_request . ordered_parts
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 ' )
firstname = fields . Char ( string = ' Firstname ' )
lastname = fields . Char ( string = ' Lastname ' )
lastname = fields . Char ( string = ' Lastname ' )
birthdate = fields . Date ( string = " Birthdate " )
birthdate = fields . Date ( string = " Birthdate " )
gender = fields . Selection ( [ ( ' male ' , _ ( ' Male ' ) ) ,
gender = fields . Selection ( [ ( ' male ' , _ ( ' Male ' ) ) ,
( ' female ' , _ ( ' Female ' ) ) ,
( ' female ' , _ ( ' Female ' ) ) ,
( ' other ' , _ ( ' Other ' ) ) ] , string = ' Gender ' )
( ' 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 ' )
email = fields . Char ( string = ' Email ' )
iban = fields . Char ( string = ' Account Number ' )
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 ' )
ordered_parts = fields . Integer ( string = ' Number of Share ' )
address = fields . Char ( string = ' Address ' )
address = fields . Char ( string = ' Address ' )
city = fields . Char ( string = ' City ' )
city = fields . Char ( string = ' City ' )
zip_code = fields . Char ( string = ' Zip Code ' )
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 ' )
phone = fields . Char ( string = ' Phone ' )
no_registre = fields . Char ( string = ' National Register Number ' )
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 ( ) )
default = lambda self : self . env [ ' res.company ' ] . _company_default_get ( ) )
is_company = fields . Boolean ( string = ' Is a company ' )
is_company = fields . Boolean ( string = ' Is a company ' )
is_operation = fields . Boolean ( string = ' Is an operation ' )
is_operation = fields . Boolean ( string = ' Is an operation ' )
company_name = fields . Char ( string = " Company name " )
company_name = fields . Char ( string = " Company name " )
company_email = fields . Char ( string = " Company email " )
company_email = fields . Char ( string = " Company email " )
company_register_number = fields . Char ( string = ' Company register number ' )
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 ' )
same_address = fields . Boolean ( string = ' Same address ' )
activities_address = fields . Char ( string = ' Activities address ' )
activities_address = fields . Char ( string = ' Activities address ' )
activities_city = fields . Char ( string = ' Activities city ' )
activities_city = fields . Char ( string = ' Activities city ' )
activities_zip_code = fields . Char ( string = ' Activities zip Code ' )
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 ' )
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 " )
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 ' ,
string = ' Capital release request ' ,
readonly = True )
readonly = True )
capital_release_request_date = fields . Date ( string = " Force the capital release request date " ,
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 "
_order = " id desc "
# declare this function in order to be overriden
# 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 ) :
def _prepare_invoice_line ( self , product , partner , qty ) :
self . ensure_one ( )
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 :
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 ) )
( product . name , product . id , product . categ_id . name ) )
fpos = partner . property_account_position_id
fpos = partner . property_account_position_id
@ -209,96 +258,110 @@ class subscription_request(models.Model):
' product_id ' : product . id or False ,
' product_id ' : product . id or False ,
}
}
return res
return res
def send_capital_release_request ( self , invoice ) :
def send_capital_release_request ( self , invoice ) :
invoice_email_template = self . env [ ' mail.template ' ] . search ( [ ( ' name ' , ' = ' , ' Request to Release Capital - Send by Email ' ) ] ) [ 0 ]
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
# we send the email with the capital release request in attachment
invoice_email_template . send_mail ( invoice . id , True )
invoice_email_template . send_mail ( invoice . id , True )
invoice . sent = True
invoice . sent = True
def create_invoice ( self , partner ) :
def create_invoice ( self , partner ) :
# get subscription journal
# 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
# get the account for associate
# TODO this should be defined in configuration
# TODO this should be defined in configuration
if self . company_id . property_cooperator_account :
if self . company_id . property_cooperator_account :
account = self . company_id . property_cooperator_account
account = self . company_id . property_cooperator_account
else :
else :
account = self . env [ ' account.account ' ] . search ( [ ( ' code ' , ' = ' , ' 416000 ' ) ] ) [ 0 ]
account = self . env [ ' account.account ' ] . search ( [ ( ' code ' , ' = ' , ' 416000 ' ) ] ) [ 0 ]
# creating invoice and invoice lines
# 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 :
if self . capital_release_request_date :
invoice_vals [ ' date_invoice ' ] = self . capital_release_request_date
invoice_vals [ ' date_invoice ' ] = self . capital_release_request_date
invoice = self . env [ ' account.invoice ' ] . create ( invoice_vals )
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
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
# validate the capital release request
invoice . signal_workflow ( ' invoice_open ' )
invoice . signal_workflow ( ' invoice_open ' )
self . send_capital_release_request ( invoice )
self . send_capital_release_request ( invoice )
return invoice
return invoice
def get_partner_company_vals ( self ) :
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
return partner_vals
def get_partner_vals ( self ) :
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
return partner_vals
def create_coop_partner ( self ) :
def create_coop_partner ( self ) :
partner_obj = self . env [ ' res.partner ' ]
partner_obj = self . env [ ' res.partner ' ]
if self . is_company :
if self . is_company :
partner_vals = self . get_partner_company_vals ( )
partner_vals = self . get_partner_company_vals ( )
else :
else :
partner_vals = self . get_partner_vals ( )
partner_vals = self . get_partner_vals ( )
partner = partner_obj . create ( 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 ) :
def create_user ( self , partner ) :
user_obj = self . env [ ' res.users ' ]
user_obj = self . env [ ' res.users ' ]
email = self . email
email = self . email
if self . is_company :
if self . is_company :
email = self . company_email
email = self . company_email
user = user_obj . search ( [ ( ' login ' , ' = ' , email ) ] )
user = user_obj . search ( [ ( ' login ' , ' = ' , email ) ] )
if not user :
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_id = user_obj . sudo ( ) . _signup_create_user ( user_values )
user = user_obj . browse ( user_id )
user = user_obj . browse ( user_id )
user . sudo ( ) . with_context ( { ' create_user ' : True } ) . action_reset_password ( )
user . sudo ( ) . with_context ( { ' create_user ' : True } ) . action_reset_password ( )
return True
return True
@api.one
@api.one
def validate_subscription_request ( self ) :
def validate_subscription_request ( self ) :
partner_obj = self . env [ ' res.partner ' ]
partner_obj = self . env [ ' res.partner ' ]
if self . ordered_parts < = 0 :
if self . ordered_parts < = 0 :
raise UserError ( _ ( ' Number of share must be greater than 0. ' ) )
raise UserError ( _ ( ' Number of share must be greater than 0. ' ) )
if self . partner_id :
if self . partner_id :
@ -307,11 +370,12 @@ class subscription_request(models.Model):
partner = self . partner_id
partner = self . partner_id
else :
else :
if self . already_cooperator :
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 :
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 :
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 :
else :
partner = None
partner = None
@ -320,32 +384,47 @@ class subscription_request(models.Model):
else :
else :
partner = partner [ 0 ]
partner = partner [ 0 ]
if self . is_company and not partner . has_representative ( ) :
if self . is_company and not partner . has_representative ( ) :
contact = False
contact = False
if self . no_registre :
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 :
if contact :
contact . type = ' representative '
contact . type = ' representative '
if not contact :
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 )
contact = partner_obj . create ( contact_vals )
else :
else :
if len ( contact ) > 1 :
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 :
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 :
else :
contact . write ( { ' parent_id ' : partner . id , ' representative ' : True } )
contact . write ( { ' parent_id ' : partner . id ,
' representative ' : True } )
invoice = self . create_invoice ( partner )
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 )
self . create_user ( partner )
@ -353,80 +432,132 @@ class subscription_request(models.Model):
@api.one
@api.one
def block_subscription_request ( self ) :
def block_subscription_request ( self ) :
self . write ( { ' state ' : ' block ' } )
@api.one
self . write ( { ' state ' : ' block ' } )
@api.one
def unblock_subscription_request ( self ) :
def unblock_subscription_request ( self ) :
self . write ( { ' state ' : ' draft ' } )
@api.one
self . write ( { ' state ' : ' draft ' } )
@api.one
def cancel_subscription_request ( self ) :
def cancel_subscription_request ( self ) :
self . write ( { ' state ' : ' cancelled ' } )
self . write ( { ' state ' : ' cancelled ' } )
@api.one
@api.one
def put_on_waiting_list ( self ) :
def put_on_waiting_list ( self ) :
self . write ( { ' state ' : ' waiting ' } )
self . write ( { ' state ' : ' waiting ' } )
class share_line ( models . Model ) :
class share_line ( models . Model ) :
_name = ' share.line '
_name = ' share.line '
@api.multi
@api.multi
def _compute_total_line ( self ) :
def _compute_total_line ( self ) :
res = { }
res = { }
for line in self :
for line in self :
line . total_amount_line = line . share_unit_price * line . share_number
line . total_amount_line = line . share_unit_price * line . share_number
return res
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
@api.multi
def _compute_total_line ( self ) :
def _compute_total_line ( self ) :
res = { }
for register_line in self :
for register_line in self :
register_line . total_amount_line = register_line . share_unit_price * register_line . quantity
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 )
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 ,
change_default = True , readonly = True ,
default = lambda self : self . env [ ' res.company ' ] . _company_default_get ( ) )
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 "
_order = " register_number_operation asc "
@api.model
@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 :
if ' share_unit_price ' in fields :
fields . remove ( ' share_unit_price ' )
fields . remove ( ' share_unit_price ' )
if ' register_number_operation ' in fields :
if ' register_number_operation ' in fields :
fields . remove ( ' register_number_operation ' )
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 :
if ' total_amount_line ' in fields :
for line in res :
for line in res :
if ' __domain ' in line :
if ' __domain ' in line :