0002-family-fix-naive-datetime-warning-37760.patch
passerelle/apps/family/loaders/concerto_orleans.py | ||
---|---|---|
25 | 25 |
from django.core.files.storage import DefaultStorage |
26 | 26 | |
27 | 27 |
from ..models import Family, Adult, Child, Invoice |
28 |
from ..models import dict_cherry_pick, get_datetime |
|
28 |
from ..models import dict_cherry_pick, get_datetime, get_date
|
|
29 | 29 | |
30 | 30 | |
31 | 31 |
def normalize_adult(adult): |
... | ... | |
56 | 56 |
'invoices': [], |
57 | 57 |
'login': family['id_fam'], |
58 | 58 |
'password': family['cod_secret_fam'], |
59 |
'family_quotient': family['qf_vo'], |
|
59 |
'family_quotient': family['qf_vo'] or 0.0,
|
|
60 | 60 |
'street_number': family['num_voie_adr'] + family['lib_nom_btq'], |
61 | 61 |
'street_name': family['lib_nom_rue'], |
62 | 62 |
'address_complement': family['lib_comp_adr'], |
... | ... | |
73 | 73 |
'first_name': child['lib_prenom_per'], |
74 | 74 |
'last_name': child['lib_nom_per'], |
75 | 75 |
'sex': sex, |
76 |
'birthdate': get_datetime(child['dat_naissance'])
|
|
76 |
'birthdate': get_date(child['dat_naissance']) |
|
77 | 77 |
} |
78 | 78 | |
79 | 79 |
def normalize_invoice(i): |
... | ... | |
82 | 82 |
'total_amount': Decimal(i['mnt_facture_fac']), |
83 | 83 |
'amount': Decimal(i['mnt_solde_fac']), |
84 | 84 |
'issue_date': i['dat_generation_fac'], |
85 |
'pay_limit_date': get_datetime(i['dat_limitepaie_fac']),
|
|
85 |
'pay_limit_date': get_date(i['dat_limitepaie_fac']), |
|
86 | 86 |
'autobilling': i['on_prelevauto_ins'] == 'O', |
87 | 87 |
'online_payment': True, |
88 | 88 |
'payment_date': get_datetime(i['dat_reglement']), |
89 |
'litigation_date': get_datetime(i['dat_perception_fac']),
|
|
89 |
'litigation_date': get_date(i['dat_perception_fac']), |
|
90 | 90 |
'paid': Decimal(i['mnt_solde_fac']) == 0 |
91 | 91 |
} |
92 | 92 |
return invoice |
... | ... | |
145 | 145 |
try: |
146 | 146 |
families = self.build_families() |
147 | 147 |
except Exception, e: |
148 |
raise |
|
148 | 149 |
self.connector.logger.error('Error occured while building families: %s', e) |
149 | 150 |
return |
150 | 151 | |
... | ... | |
177 | 178 |
family=family, external_id=invoice_data['external_id'], defaults=invoice_data) |
178 | 179 | |
179 | 180 |
except Exception, e: |
181 |
raise |
|
180 | 182 |
self.connector.logger.error('Error occured while importing data: %s', e) |
181 | 183 | |
182 | 184 |
Family.objects.filter(resource=self.connector, update_timestamp__lte=import_start_timestamp).delete() |
passerelle/apps/family/management/commands/import_orleans_data.py | ||
---|---|---|
54 | 54 |
except IOError: |
55 | 55 |
raise CommandError('Command already running.') |
56 | 56 | |
57 |
try: |
|
58 |
archive_name = os.path.basename(options['archive_file']) |
|
59 |
connector.archive.save(archive_name, File(file(options['archive_file']))) |
|
60 |
except Exception, e: |
|
61 |
raise CommandError('Error occured: %s' % e) |
|
62 |
finally: |
|
63 |
fd.close() |
|
64 |
os.unlink(lock_filename) |
|
57 |
archive_name = os.path.basename(options['archive_file']) |
|
58 |
connector.archive.save(archive_name, File(file(options['archive_file']))) |
|
59 |
fd.close() |
|
60 |
os.unlink(lock_filename) |
passerelle/apps/family/models.py | ||
---|---|---|
16 | 16 |
# You should have received a copy of the GNU Affero General Public License |
17 | 17 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
18 | 18 | |
19 |
from datetime import date, time |
|
19 | 20 |
import json |
20 | 21 |
import os |
21 | 22 |
import shutil |
... | ... | |
29 | 30 |
from django.utils.translation import ugettext_lazy as _ |
30 | 31 |
from django.http import Http404, HttpResponse |
31 | 32 |
from django.db import models, transaction |
32 |
from django.utils.timezone import make_aware, datetime, get_current_timezone, now |
|
33 |
from django.utils.timezone import make_aware, datetime, get_current_timezone, now, is_naive
|
|
33 | 34 | |
34 | 35 |
from passerelle.base.models import BaseResource |
35 | 36 |
from passerelle.utils.api import endpoint |
... | ... | |
42 | 43 |
DATE_FORMAT = '%Y-%m-%d' |
43 | 44 |
DATETIME_FORMAT = DATE_FORMAT + 'T%H:%M:%S' |
44 | 45 | |
46 | ||
47 |
def get_date(dt): |
|
48 |
if isinstance(dt, date): |
|
49 |
return dt |
|
50 |
if not dt: |
|
51 |
return None |
|
52 |
return datetime.strptime(dt, DATE_FORMAT).date() |
|
53 | ||
54 | ||
45 | 55 |
def get_datetime(date): |
46 | 56 |
if not date: |
47 | 57 |
return None |
48 |
try: |
|
49 |
return make_aware(datetime.strptime(date,DATETIME_FORMAT), |
|
50 |
get_current_timezone()) |
|
51 |
except ValueError: |
|
52 |
pass |
|
53 |
try: |
|
54 |
return datetime.strptime(date, DATE_FORMAT).date() |
|
55 |
except ValueError: |
|
56 |
pass |
|
57 |
return None |
|
58 |
if not isinstance(date, datetime): |
|
59 |
try: |
|
60 |
date = datetime.strptime(date, DATETIME_FORMAT) |
|
61 |
except ValueError: |
|
62 |
date = datetime.strptime(date, DATE_FORMAT) |
|
63 |
if is_naive(date): |
|
64 |
date = make_aware(date) |
|
65 |
return date |
|
66 | ||
58 | 67 | |
59 | 68 |
def format_address(data): |
60 | 69 |
address = '%(street_number)s, %(street_name)s' % data |
... | ... | |
232 | 241 |
for date_attribute in data.keys(): |
233 | 242 |
if not date_attribute.endswith('_date'): |
234 | 243 |
continue |
235 |
data[date_attribute] = get_datetime(data[date_attribute]) |
|
244 |
if date_attribute == 'payment_date': |
|
245 |
data[date_attribute] = get_datetime(data[date_attribute]) |
|
246 |
else: |
|
247 |
data[date_attribute] = get_date(data[date_attribute]) |
|
236 | 248 |
data['paid'] = bool(data.get('payment_date')) |
249 |
if data['paid']: |
|
250 |
if isinstance(data['payment_date'], date): |
|
251 |
data['payment_date'] = make_aware( |
|
252 |
datetime.combine(data['payment_date'], time(0, 0))) |
|
237 | 253 |
Invoice.objects.update_or_create(resource=self, |
238 | 254 |
family=family, external_id=invoice['id'], defaults=data) |
239 | 255 |
if 'invoices/%s.pdf' % invoice['id'] in archive_files: |
240 |
- |