Browse Source

[REFACT] replace national register number by email

Due to a legal issue we won't use the national register number anymore.
So the unique identification will now be made through the email of the
partner from now.
pull/10/head
houssine 5 years ago
parent
commit
da0653d76b
  1. 22
      easy_my_coop/controllers/main.py
  2. 62
      easy_my_coop/models/coop.py
  3. 13
      easy_my_coop/models/partner.py
  4. 6
      easy_my_coop/view/operation_request_view.xml
  5. 1
      easy_my_coop/view/subscription_request_view.xml
  6. 14
      easy_my_coop/view/subscription_template.xml
  7. 45
      easy_my_coop/wizard/create_subscription_from_partner.py
  8. 2
      easy_my_coop/wizard/create_subscription_from_partner.xml
  9. 10
      easy_my_coop/wizard/update_partner_info.py
  10. 1
      easy_my_coop/wizard/update_share_line.py
  11. 1
      easy_my_coop_ch/__openerp__.py
  12. 6
      easy_my_coop_ch/models/coop.py
  13. 13
      easy_my_coop_ch/views/subscription_request_view.xml
  14. 2
      easy_my_coop_ch/views/subscription_template.xml
  15. 6
      easy_my_coop_export_xlsx/wizard/export_global_wizard.py
  16. 5
      easy_my_coop_fr/models/coop.py
  17. 5
      easy_my_coop_fr/views/subscription_template.xml

22
easy_my_coop/controllers/main.py

@ -14,14 +14,14 @@ _BLACKLIST = ['id', 'create_uid', 'create_date', 'write_uid', 'write_date',
'user_id', 'active']
_COOP_FORM_FIELD = ['email', 'firstname', 'lastname', 'birthdate', 'iban',
'share_product_id', 'no_registre', 'address', 'city',
'share_product_id', 'address', 'city',
'zip_code', 'country_id', 'phone', 'lang', 'nb_parts',
'total_parts', 'error_msg']
_COMPANY_FORM_FIELD = ['is_company', 'company_register_number', 'company_name',
'company_email', 'company_type', 'email', 'firstname',
'lastname', 'birthdate', 'iban', 'share_product_id',
'no_registre', 'address', 'city', 'zip_code',
'address', 'city', 'zip_code',
'country_id', 'phone', 'lang', 'nb_parts',
'total_parts', 'error_msg']
@ -109,7 +109,6 @@ class WebsiteSubscription(http.Controller):
values['gender'] = representative.gender
values['email'] = representative.email
values['contact_person_function'] = representative.function
values['no_registre'] = representative.national_register_number
values['birthdate'] = self.get_date_string(representative.birthdate)
values['lang'] = representative.lang
values['phone'] = representative.phone
@ -118,7 +117,6 @@ class WebsiteSubscription(http.Controller):
values['lastname'] = partner.lastname
values['email'] = partner.email
values['gender'] = partner.gender
values['no_registre'] = partner.national_register_number
values['birthdate'] = self.get_date_string(partner.birthdate)
values['lang'] = partner.lang
values['phone'] = partner.phone
@ -258,17 +256,6 @@ class WebsiteSubscription(http.Controller):
"is not valid")
return request.website.render(redirect, values)
if not is_company and 'no_registre' in required_fields:
no_registre = re.sub('[^0-9a-zA-Z]+', '',
kwargs.get("no_registre"))
valid = sub_req_obj.check_belgian_identification_id(no_registre)
if not valid:
values = self.fill_values(values, is_company, logged)
values["error_msg"] = _("You national register number "
"is not valid")
return request.website.render(redirect, values)
values["no_registre"] = no_registre
# check the subscription's amount
max_amount = company.subscription_maximum_amount
if logged:
@ -375,11 +362,6 @@ class WebsiteSubscription(http.Controller):
kwargs.get("company_register_number"))
subscription_id = sub_req_obj.sudo().create_comp_sub_req(values)
else:
if 'no_registre' in required_fields:
no_registre = re.sub('[^0-9a-zA-Z]+', '',
kwargs.get("no_registre"))
values["no_registre"] = no_registre
subscription_id = sub_req_obj.sudo().create(values)
if subscription_id:

62
easy_my_coop/models/coop.py

@ -15,7 +15,6 @@ _REQUIRED = ['email',
'zip_code',
'city',
'iban',
'no_registre',
'gender'] # Could be improved including required from model
@ -43,12 +42,12 @@ class subscription_request(models.Model):
partner_obj = self.env['res.partner']
if not vals.get('partner_id'):
cooperator = False
if vals.get('no_registre'):
cooperator = partner_obj.get_cooperator_from_nin(
vals.get('no_registre'))
if vals.get('email'):
cooperator = partner_obj.get_cooperator_from_email(
vals.get('email'))
if cooperator:
# TODO remove the following line of code once it has
# been founded a way to avoid dubble entry
# been founded a way to avoid double entry
cooperator = cooperator[0]
if cooperator.member:
vals['type'] = 'increase'
@ -89,21 +88,21 @@ class subscription_request(models.Model):
return subscr_request
def check_belgian_identification_id(self, nat_register_num):
if not self.check_empty_string(nat_register_num):
return False
if len(nat_register_num) != 11:
return False
if not nat_register_num.isdigit():
return False
birthday_number = nat_register_num[0:9]
controle = nat_register_num[9:11]
check_controle = 97 - (int(birthday_number) % 97)
if int(check_controle) != int(controle):
check_controle = 97 - ((2000000000 + int(birthday_number)) % 97)
if int(check_controle) != int(controle):
return False
return True
# def check_belgian_identification_id(self, nat_register_num):
# if not self.check_empty_string(nat_register_num):
# return False
# if len(nat_register_num) != 11:
# return False
# if not nat_register_num.isdigit():
# return False
# birthday_number = nat_register_num[0:9]
# controle = nat_register_num[9:11]
# check_controle = 97 - (int(birthday_number) % 97)
# if int(check_controle) != int(controle):
# check_controle = 97 - ((2000000000 + int(birthday_number)) % 97)
# if int(check_controle) != int(controle):
# return False
# return True
def check_empty_string(self, value):
if value is None or value is False or value == '':
@ -119,17 +118,10 @@ class subscription_request(models.Model):
return validated
@api.multi
@api.depends('iban', 'no_registre', 'skip_control_ng', 'is_company')
@api.depends('iban', 'skip_control_ng', 'is_company')
def _validated_lines(self):
for sub_request in self:
validated = self.check_iban(sub_request.iban)
if validated and (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
@ -234,9 +226,6 @@ class subscription_request(models.Model):
phone = fields.Char(string='Phone',
readonly=True,
states={'draft': [('readonly', False)]})
no_registre = fields.Char(string='National Register Number',
readonly=True,
states={'draft': [('readonly', False)]})
user_id = fields.Many2one('res.users',
string='Responsible',
readonly=True)
@ -349,7 +338,6 @@ class subscription_request(models.Model):
self.firstname = partner.firstname
self.name = partner.name
self.lastname = partner.lastname
self.no_registre = partner.national_register_number
self.email = partner.email
self.birthdate = partner.birthdate_date
self.gender = partner.gender
@ -469,7 +457,6 @@ class subscription_request(models.Model):
'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,
@ -513,8 +500,8 @@ class subscription_request(models.Model):
' checked please select a cooperator.'))
elif self.is_company and self.company_register_number:
domain = [('company_register_number', '=', self.company_register_number)] #noqa
elif not self.is_company and self.no_registre:
domain = [('national_register_number', '=', self.no_registre)]
elif not self.is_company and self.email:
domain = [('email', '=', self.email)]
if domain:
partner = partner_obj.search(domain)
@ -526,8 +513,8 @@ class subscription_request(models.Model):
if self.is_company and not partner.has_representative():
contact = False
if self.no_registre:
domain = [('national_register_number', '=', self.no_registre)]
if self.email:
domain = [('email', '=', self.email)]
contact = partner_obj.search(domain)
if contact:
contact.type = 'representative'
@ -539,7 +526,6 @@ class subscription_request(models.Model):
'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',

13
easy_my_coop/models/partner.py

@ -167,10 +167,15 @@ class ResPartner(models.Model):
def get_representative(self):
return self.child_ids.filtered('representative')
def get_cooperator_from_nin(self, national_id_number):
def get_cooperator_from_email(self, email):
return self.search([('cooperator', '=', True),
('national_register_number', '=', national_id_number)])
('email', '=', email)])
def get_cooperator_from_crn(self, company_register_number):
# def get_cooperator_from_nin(self, national_id_number):
# return self.search([('cooperator', '=', True),
# ('national_register_number', '=',
# national_id_number)])
def get_cooperator_from_crn(self, comp_reg_number):
return self.search([('cooperator', '=', True),
('company_register_number', '=', company_register_number)])
('company_register_number', '=', comp_reg_number)])

6
easy_my_coop/view/operation_request_view.xml

@ -53,10 +53,9 @@
<field name="subscription_request" attrs="{'invisible':['|',('operation_type','!=','transfer'),('receiver_not_member','=',False)]}" context="{'default_is_operation': True, 'default_ordered_parts':quantity,'default_share_product_id': share_product_id, 'default_source':'operation'}">
<tree>
<field name="name"/>
<field name="no_registre"/>
<field name="email"/>
<field name="birthdate"/>
<field name="phone"/>
<field name="email"/>
<field name="iban"/>
<field name="state" invisible="True"/>
</tree>
@ -67,11 +66,10 @@
<field name="name"/>
<field name="firstname"/>
<field name="lastname"/>
<field name="email"/>
<field name="birthdate"/>
<field name="gender"/>
<field name="email"/>
<field name="phone"/>
<field name="no_registre"/>
<field name="iban"/>
</group>
<group>

1
easy_my_coop/view/subscription_request_view.xml

@ -58,7 +58,6 @@
<field name="email"/>
<field name="phone"/>
<field name="contact_person_function" attrs="{'invisible':[('is_company','=',False)]}"/>
<field name="no_registre"/>
<field name="iban"/>
<field name="address"/>
<field name="zip_code"/>

14
easy_my_coop/view/subscription_template.xml

@ -115,13 +115,6 @@
</div>
</div>
<div t-attf-class="form-group #{error and 'no_registre' in error and 'has-error' or ''}">
<label class="col-md-3 col-sm-4 control-label" for="no_registre">National Register Number</label>
<div class="col-md-7 col-sm-8">
<input type="text" class="form-control mandatory-field" name="no_registre" t-attf-value="#{no_registre or ''}" placeholder="78230226321"/>
</div>
</div>
<div t-attf-class="form-group #{error and 'iban' in error and 'has-error' or ''}">
<label class="col-md-3 col-sm-4 control-label" for="iban">Bank Account Number</label>
<div class="col-md-7 col-sm-8">
@ -461,13 +454,6 @@
</div>
</div>
<div t-attf-class="form-group #{error and 'no_registre' in error and 'has-error' or ''}">
<label class="col-md-3 col-sm-4 control-label" for="no_registre">National Register Number</label>
<div class="col-md-7 col-sm-8">
<input type="text" class="form-control mandatory-field" name="no_registre" required="True" t-attf-value="#{no_registre or ''}" placeholder="78230226321"/>
</div>
</div>
<div t-attf-class="form-group #{error and 'birthday' in error and 'has-error' or ''}">
<label class="col-md-3 col-sm-4 control-label" for="birthdate">Birthdate</label>
<div class="col-md-7 col-sm-8">

45
easy_my_coop/wizard/create_subscription_from_partner.py

@ -30,15 +30,15 @@ class PartnerCreateSubscription(models.TransientModel):
def _get_representative(self):
partner = self._get_partner()
if partner.is_company:
return self.env['res.partner'].search([('parent_id', '=', partner.id),
return partner.search([('parent_id', '=', partner.id),
('representative', '=', True)])
return False
@api.model
def _get_representative_number(self):
def _get_representative_mail(self):
representative = self._get_representative()
if representative:
return representative.national_register_number
return representative.email
return False
@api.model
@ -67,8 +67,6 @@ class PartnerCreateSubscription(models.TransientModel):
partner = self._get_partner()
if partner.is_company:
return partner.company_register_number
else:
return partner.national_register_number
@api.model
def _get_bank_account(self):
@ -101,8 +99,7 @@ class PartnerCreateSubscription(models.TransientModel):
cooperator = fields.Many2one('res.partner',
string="Cooperator",
default=_get_partner)
register_number = fields.Char(string="Register Number",
required=True,
register_number = fields.Char(string="Register Company Number",
default=_get_register_number)
email = fields.Char(string="Email",
required=True,
@ -126,16 +123,15 @@ class PartnerCreateSubscription(models.TransientModel):
readonly=True)
representative_name = fields.Char(string='Representative name',
default=_get_representative_name)
representative_number = fields.Char(string='Representative national '
'register number',
default=_get_representative_number)
representative_email = fields.Char(string='Representative email',
default=_get_representative_mail)
def check_belgian_ident_id(self, register_number):
sub_req = self.env['subscription.request']
if sub_req.check_belgian_identification_id(register_number):
return True
else:
raise UserError(_("The national register number is not valid."))
# def check_belgian_ident_id(self, register_number):
# sub_req = self.env['subscription.request']
# if sub_req.check_belgian_identification_id(register_number):
# return True
# else:
# raise UserError(_("The national register number is not valid."))
@api.multi
def create_subscription(self):
@ -163,7 +159,6 @@ class PartnerCreateSubscription(models.TransientModel):
vals['is_company'] = True
else:
vals['name'] = cooperator.name
vals['no_registre'] = self.register_number
coop_vals = {}
if not self._get_email():
@ -172,15 +167,14 @@ class PartnerCreateSubscription(models.TransientModel):
if not self._get_register_number():
if self.is_company:
coop_vals['company_register_number'] = self.register_number
else:
if self.check_belgian_ident_id(self.register_number):
coop_vals['national_register_number'] = self.register_number
if self.is_company and not self._get_representative():
representative = False
if self.representative_number:
representative_number = self.representative_number
representative = partner_obj.search([('national_register_number', '=', representative_number)])
if self.representative_email:
representative = partner_obj.search([('email',
'=',
self.representative_email
)])
if representative:
if len(representative) > 1:
@ -193,10 +187,10 @@ class PartnerCreateSubscription(models.TransientModel):
"two different companies."))
representative.parent_id = cooperator.id
else:
if self.check_belgian_ident_id(representative_number):
if self.representative_email:
represent_vals = {'name': self.representative_name,
'cooperator': True,
'national_register_number': representative_number,
'email': self.representative_email,
'parent_id': cooperator.id,
'representative': True}
partner_obj.create(represent_vals)
@ -209,7 +203,6 @@ class PartnerCreateSubscription(models.TransientModel):
if self.is_company:
representative = self._get_representative()
vals['name'] = representative.name
vals['no_registre'] = representative.national_register_number
if coop_vals:
cooperator.write(coop_vals)

2
easy_my_coop/wizard/create_subscription_from_partner.xml

@ -13,7 +13,7 @@
<field name="is_company" invisible="True"/>
<field name="cooperator" invisible="True"/>
<field name="representative_name" attrs="{'invisible':[('is_company','=',False)],'required':[('is_company','=',True)]}"/>
<field name="representative_number" attrs="{'invisible':[('is_company','=',False)],'required':[('is_company','=',True)]}"/>
<field name="representative_email" attrs="{'invisible':[('is_company','=',False)],'required':[('is_company','=',True)]}"/>
<field name="email"/>
<field name="register_number"/>
<field name="bank_account"/>

10
easy_my_coop/wizard/update_partner_info.py

@ -28,13 +28,6 @@ class PartnerUpdateInfo(models.TransientModel):
string="Cooperator",
default=_get_partner)
def check_belgian_ident_id(self, register_number):
if self.env['subscription.request'].check_belgian_identification_id(
register_number):
return True
else:
raise UserError(_("The national register number is not valid."))
@api.multi
def update(self):
@ -43,9 +36,6 @@ class PartnerUpdateInfo(models.TransientModel):
if cooperator.is_company:
coop_vals['company_register_number'] = self.register_number
else:
if self.check_belgian_ident_id(self.register_number):
coop_vals['national_register_number'] = self.register_number
if coop_vals:
cooperator.write(coop_vals)

1
easy_my_coop/wizard/update_share_line.py

@ -29,7 +29,6 @@ class ShareLineUpdateInfo(models.TransientModel):
@api.multi
def update(self):
line = self.share_line
cooperator = line.partner_id

1
easy_my_coop_ch/__openerp__.py

@ -32,7 +32,6 @@
""",
'data': [
'views/subscription_template.xml',
'views/subscription_request_view.xml'
],
'installable': True,
}

6
easy_my_coop_ch/models/coop.py

@ -16,17 +16,11 @@ class subscription_request(models.Model):
def get_required_field(self):
req_fields = super(subscription_request, self).get_required_field()
if 'no_registre' in req_fields:
req_fields.remove('no_registre')
if 'iban' in req_fields:
req_fields.remove('iban')
return req_fields
def check_belgian_identification_id(self, nat_register_num):
# deactivate number validation for swiss localization
return True
def check_iban(self, iban):
if iban:
return super(subscription_request, self).check_iban(iban)

13
easy_my_coop_ch/views/subscription_request_view.xml

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="subscription_request_form" model="ir.ui.view">
<field name="name">subscription.request.form</field>
<field name="model">subscription.request</field>
<field name="inherit_id" ref="easy_my_coop.subscription_request_form"/>
<field name="arch" type="xml">
<field name="no_registre" position="replace"/>
</field>
</record>
</data>
</odoo>

2
easy_my_coop_ch/views/subscription_template.xml

@ -2,7 +2,6 @@
<odoo>
<data>
<template id="subscription_i18n_ch" inherit_id="easy_my_coop.becomecooperator" name="Removing fields">
<xpath expr="//label[@for='no_registre']/.." position="replace"/>
<xpath expr="//label[@for='iban']/.." position="replace">
<div t-attf-class="form-group #{error and 'iban' in error and 'has-error' or ''}">
<label class="col-md-3 col-sm-4 control-label" for="iban">Bank Account Number</label>
@ -14,7 +13,6 @@
</template>
<template id="company_subscription_i18n_ch" inherit_id="easy_my_coop.becomecompanycooperator" name="Company Removing fields">
<xpath expr="//label[@for='no_registre']/.." position="replace"/>
<xpath expr="//label[@for='iban']/.." position="replace">
<div t-attf-class="form-group #{error and 'iban' in error and 'has-error' or ''}">
<label class="col-md-3 col-sm-4 control-label" for="iban">Bank Account Number</label>

6
easy_my_coop_export_xlsx/wizard/export_global_wizard.py

@ -10,7 +10,6 @@ import xlsxwriter
HEADER = [
'Num. Coop',
'Numero de registre national',
'Nom',
'Email',
'Banque',
@ -36,7 +35,6 @@ HEADER2 = [
'Nombre de part',
'Montant',
'Statut',
'Numero de registre national',
'Email',
'Mobile',
'Adresse',
@ -77,8 +75,6 @@ class export_global_report(models.TransientModel):
i = 0
worksheet1.write(j, i, coop.cooperator_register_number)
i += 1
worksheet1.write(j, i, coop.national_register_number)
i += 1
worksheet1.write(j, i, coop.name)
i += 1
worksheet1.write(j, i, coop.email)
@ -250,8 +246,6 @@ class export_global_report(models.TransientModel):
i += 1
worksheet2.write(j, i, sub_request.state)
i += 1
worksheet2.write(j, i, sub_request.no_registre)
i += 1
worksheet2.write(j, i, sub_request.email)
i += 1
worksheet2.write(j, i, sub_request.phone)

5
easy_my_coop_fr/models/coop.py

@ -17,8 +17,3 @@ class SubscriptionRequest(models.Model):
req_fields.remove('iban')
return req_fields
# override function to disable the check
def check_belgian_identification_id(self, nat_register_num):
# deactivate number validation for french localization
return True

5
easy_my_coop_fr/views/subscription_template.xml

@ -2,10 +2,7 @@
<odoo>
<data>
<template id="subscription_i18n" inherit_id="easy_my_coop.becomecooperator" name="Removing fields">
<!-- <xpath expr="//label[@for='no_registre']/.." position="replace">
</xpath> -->
<xpath expr="//label[@for='iban']/.." position="replace">
</xpath>
<xpath expr="//label[@for='iban']/.." position="replace"/>
</template>
</data>
</odoo>
Loading…
Cancel
Save