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): |
... | ... | |
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 |
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')) |
237 | 249 |
Invoice.objects.update_or_create(resource=self, |
238 | 250 |
family=family, external_id=invoice['id'], defaults=data) |
239 |
- |