Commit 0465b134 by Damien Moulard

Merge branch 'dev_cooperatic' of…

Merge branch 'dev_cooperatic' of gl.cooperatic.fr:cooperatic-foodcoops/third-party into dev_cooperatic
parents 88de0202 1424912e
...@@ -46,6 +46,7 @@ def archive_envelop(request): ...@@ -46,6 +46,7 @@ def archive_envelop(request):
"done": False, "done": False,
"error": repr(e) "error": repr(e)
} }
coop_logger.error("Payment error : %s \n %s", str(data), str(e))
if res['done']: if res['done']:
# Immediately save a token than this payment has been saved # Immediately save a token than this payment has been saved
...@@ -59,22 +60,19 @@ def archive_envelop(request): ...@@ -59,22 +60,19 @@ def archive_envelop(request):
try: try:
res['partner_name'] = envelop['envelop_content'][partner_id]['partner_name'] res['partner_name'] = envelop['envelop_content'][partner_id]['partner_name']
res['amount'] = envelop['envelop_content'][partner_id]['amount'] res['amount'] = envelop['envelop_content'][partner_id]['amount']
except: except Exception as e:
res['error'] = "Wrong envelop structure" res['error'] = "Wrong envelop structure"
coop_logger.error("Wrong envelop structure : %s", str(e))
res_payments.append(res) res_payments.append(res)
try: try:
# Log the error # Log the error
lf = open("/tmp/erreurs_django.log", "a")
lf.write(datetime.date.today().strftime("%Y-%m-%d") + " - Erreur lors de l'enregistrement du paiement de " + res['partner_name'] + "(odoo_id:" + partner_id + " )")
lf.write(res['error'] + "\n")
lf.close()
msg = 'Erreur lors de l\'enregistrement du paiement ' + envelop['type'] msg = 'Erreur lors de l\'enregistrement du paiement ' + envelop['type']
msg += ' ' + envelop['envelop_content'][partner_id]['amount'] + ' euros ' msg += ' ' + str(envelop['envelop_content'][partner_id]['amount']) + ' euros '
msg += ' (' + res['error'] + ')' msg += ' (' + res['error'] + ')'
CagetteMember(int(partner_id)).attach_message(msg) CagetteMember(int(partner_id)).attach_message(msg)
except: except Exception as e:
pass coop_logger.error("Cannot attach payment error message to member : %s", str(e))
try: try:
# Delete envelop from couchdb # Delete envelop from couchdb
......
...@@ -317,7 +317,7 @@ class CagetteMember(models.Model): ...@@ -317,7 +317,7 @@ class CagetteMember(models.Model):
if 'street2' in post_data: if 'street2' in post_data:
received_data['street2'] = post_data['street2'] received_data['street2'] = post_data['street2']
if 'phone' in post_data: if 'phone' in post_data:
received_data['phone'] = post_data['phone'] received_data['phone'] = format_phone_number(post_data['phone'])
r = c_db.updateDoc(received_data, 'odoo_id') r = c_db.updateDoc(received_data, 'odoo_id')
if r: if r:
if ('odoo_id' in r): if ('odoo_id' in r):
...@@ -394,7 +394,7 @@ class CagetteMember(models.Model): ...@@ -394,7 +394,7 @@ class CagetteMember(models.Model):
'street': post_data['address'], 'street': post_data['address'],
'zip': post_data['zip'], 'zip': post_data['zip'],
'city': post_data['city'], 'city': post_data['city'],
'phone': post_data['mobile'], # Because list view default show Phone and people mainly gives mobile 'phone': format_phone_number(post_data['mobile']), # Because list view default show Phone and people mainly gives mobile
'barcode_rule_id': settings.COOP_BARCODE_RULE_ID 'barcode_rule_id': settings.COOP_BARCODE_RULE_ID
} }
if ('_id' in post_data): if ('_id' in post_data):
...@@ -407,10 +407,10 @@ class CagetteMember(models.Model): ...@@ -407,10 +407,10 @@ class CagetteMember(models.Model):
f['street2'] = post_data['street2'] f['street2'] = post_data['street2']
if ('phone' in post_data) and len(post_data['phone']) > 0: if ('phone' in post_data) and len(post_data['phone']) > 0:
if len(f['phone']) == 0: if len(f['phone']) == 0:
f['phone'] = post_data['phone'] f['phone'] = format_phone_number(post_data['phone'])
else: else:
f['mobile'] = f['phone'] f['mobile'] = f['phone']
f['phone'] = post_data['phone'] f['phone'] = format_phone_number(post_data['phone'])
# Create coop # Create coop
if not ('odoo_id' in post_data): if not ('odoo_id' in post_data):
......
...@@ -48,5 +48,4 @@ urlpatterns = [ ...@@ -48,5 +48,4 @@ urlpatterns = [
url(r'^add_pts_to_everybody/([0-9]+)/([a-zA-Z0-9_ ]+)$', admin.add_pts_to_everybody), url(r'^add_pts_to_everybody/([0-9]+)/([a-zA-Z0-9_ ]+)$', admin.add_pts_to_everybody),
# conso / groupe recherche / socio # conso / groupe recherche / socio
url(r'^panel_get_purchases$', views.panel_get_purchases), url(r'^panel_get_purchases$', views.panel_get_purchases),
] ]
...@@ -102,6 +102,7 @@ def prepa_odoo(request): ...@@ -102,6 +102,7 @@ def prepa_odoo(request):
'office_place_string': settings.OFFICE_NAME, 'office_place_string': settings.OFFICE_NAME,
'max_begin_hour': settings.MAX_BEGIN_HOUR, 'max_begin_hour': settings.MAX_BEGIN_HOUR,
'payment_meanings': settings.SUBSCRIPTION_PAYMENT_MEANINGS, 'payment_meanings': settings.SUBSCRIPTION_PAYMENT_MEANINGS,
'input_phone_pattern': getattr(settings, 'INPUT_PHONE_PATTERN', default_input_phone_pattern),
'input_barcode': getattr(settings, 'SUBSCRIPTION_INPUT_BARCODE', False), 'input_barcode': getattr(settings, 'SUBSCRIPTION_INPUT_BARCODE', False),
'ask_for_sex': getattr(settings, 'SUBSCRIPTION_ASK_FOR_SEX', False), 'ask_for_sex': getattr(settings, 'SUBSCRIPTION_ASK_FOR_SEX', False),
'ask_for_street2': getattr(settings, 'SUBSCRIPTION_ADD_STREET2', False), 'ask_for_street2': getattr(settings, 'SUBSCRIPTION_ADD_STREET2', False),
...@@ -135,6 +136,7 @@ def validation_inscription(request, email): ...@@ -135,6 +136,7 @@ def validation_inscription(request, email):
'office_place_string': settings.OFFICE_NAME, 'office_place_string': settings.OFFICE_NAME,
'max_begin_hour': settings.MAX_BEGIN_HOUR, 'max_begin_hour': settings.MAX_BEGIN_HOUR,
'payment_meanings': settings.SUBSCRIPTION_PAYMENT_MEANINGS, 'payment_meanings': settings.SUBSCRIPTION_PAYMENT_MEANINGS,
'input_phone_pattern': getattr(settings, 'INPUT_PHONE_PATTERN', default_input_phone_pattern),
'ask_for_sex': getattr(settings, 'SUBSCRIPTION_ASK_FOR_SEX', False), 'ask_for_sex': getattr(settings, 'SUBSCRIPTION_ASK_FOR_SEX', False),
'ask_for_street2': getattr(settings, 'SUBSCRIPTION_ADD_STREET2', False), 'ask_for_street2': getattr(settings, 'SUBSCRIPTION_ADD_STREET2', False),
'ask_for_second_phone': getattr(settings, 'SUBSCRIPTION_ADD_SECOND_PHONE', False), 'ask_for_second_phone': getattr(settings, 'SUBSCRIPTION_ADD_SECOND_PHONE', False),
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""commons apps functions .""" """commons apps functions ."""
from django.conf import settings from django.conf import settings
default_input_phone_pattern = "^((\+33(-| )\d{1})|\d{2})(\.| )\d{2}(\.| )\d{2}(\.| )\d{2}(\.| )\d{2}$"
def format_phone_number(phone_string):
"""Format phone number for DB insertion (french format)"""
try:
import re
# keep only figures
figures = re.sub(r'[^0-9]', '', phone_string)
international_prefix = ''
if len(figures) > 10:
international_prefix = figures[:len(figures) -9]
figures = figures[-9:]
# for the moment, international prefix is omitted, since only french format is processed
if len(figures) == 9:
figures = '0' + figures
if len(figures) == 10:
number_pairs = [figures[:2]]
for i in range(1,5):
idx = i*2
number_pairs.append(figures[idx:idx + 2])
phone_pairs_separator = getattr(settings, 'PHONE_PAIRS_SEPARATOR', ' ')
output_phone_number = phone_pairs_separator.join(number_pairs)
else:
output_phone_number = phone_string
except:
output_phone_number = phone_string
return output_phone_number
...@@ -79,3 +79,4 @@ LOGGING = { ...@@ -79,3 +79,4 @@ LOGGING = {
} }
""" """
coop_logger = logging.getLogger("coop.framework") coop_logger = logging.getLogger("coop.framework")
...@@ -106,6 +106,14 @@ ...@@ -106,6 +106,14 @@
Maximum accepted checks numbers Maximum accepted checks numbers
- INPUT_PHONE_PATTERN = "^(0\d{9})$"
Regexp pattern which is used to validate values input in phone fields
Default is "^((\+33(-| )\d{1})|\d{2})(\.| )\d{2}(\.| )\d{2}(\.| )\d{2}(\.| )\d{2}$"
- PHONE_PAIRS_SEPARATOR = "."
Character which by used to separate every 2 phone figures (04.67.23.89.21 for example)
Default is " "
### Scales and labels files generation ### Scales and labels files generation
- DAV_PATH = '/data/dav/cagette' - DAV_PATH = '/data/dav/cagette'
......
...@@ -21,9 +21,9 @@ ...@@ -21,9 +21,9 @@
<input name="city" placeholder="Ville" class="b_green" autocomplete="address-level4"/> <input name="city" placeholder="Ville" class="b_green" autocomplete="address-level4"/>
<input name="country" placeholder="Pays" class="b_yellow" autocomplete="address-level4"/> <input name="country" placeholder="Pays" class="b_yellow" autocomplete="address-level4"/>
<span class="phone-wrapper{% if ask_for_second_phone %}-2{% endif %}"> <span class="phone-wrapper{% if ask_for_second_phone %}-2{% endif %}">
<input type="tel" name="mobile" placeholder="Tél. mobile" class="b_green" pattern="^(\+\d{1,3}(-| ))?\d{1,2}(\.| )\d{1,2}(\.| )\d{1,2}(\.| )\d{1,2}(\.| )\d{0,2}?$" autocomplete="address-level4"/> <input type="tel" name="mobile" placeholder="Tél. mobile" class="b_green" pattern="{{input_phone_pattern}}" autocomplete="address-level4"/>
{% if ask_for_second_phone %} {% if ask_for_second_phone %}
<input type="tel" name="phone" placeholder="Tél. fixe" class="b_green" pattern="^(\+\d{1,3}(-| ))?\d{1,2}(\.| )\d{1,2}(\.| )\d{1,2}(\.| )\d{1,2}(\.| )\d{0,2}?$" autocomplete="address-level4"/> <input type="tel" name="phone" placeholder="Tél. fixe" class="b_green" pattern="{{input_phone_pattern}}" autocomplete="address-level4"/>
{% endif %} {% endif %}
</span> </span>
</p> </p>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment