fix time error and explicit select query
This commit is contained in:
parent
f0aa426950
commit
6f0bfb175b
|
@ -3,16 +3,19 @@
|
|||
import json
|
||||
import datetime
|
||||
import re
|
||||
import pytz
|
||||
|
||||
import psycopg2 as pg
|
||||
import psycopg2.extras as pge
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.core.management import call_command
|
||||
import psycopg2 as pg
|
||||
import psycopg2.extras as pge
|
||||
from django.db import transaction
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils.timezone import make_aware
|
||||
from django.db import IntegrityError
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from activity.models import ActivityType, Activity, Guest, Entry, GuestTransaction
|
||||
from note.models import Note
|
||||
from note.models import Alias
|
||||
|
@ -159,16 +162,22 @@ def import_boutons(cur):
|
|||
@transaction.atomic
|
||||
def import_transaction(cur):
|
||||
idmin = 58770
|
||||
cur.execute("SELECT *, transactions.date AS transac_date\
|
||||
FROM transactions\
|
||||
LEFT JOIN adhesions ON transactions.id = adhesions.id\
|
||||
bde = Club.objects.get(name="BDE")
|
||||
kfet = Club.objects.get(name="Kfet")
|
||||
cur.execute("SELECT t.date AS transac_date, t.type, t.emetteur, t.destinataire, t.quantite, t.montant, t.description, t.valide, t.cantinvalidate, t.categorie\
|
||||
a.idbde,a.annee, a.wei, a.date AS adh_date, a.section
|
||||
FROM transactions AS t\
|
||||
LEFT JOIN adhesions AS a ON t.id = a.idtransaction\
|
||||
WHERE transactions.id> {}\
|
||||
ORDER BY transactions.id;".format(idmin))
|
||||
n = cur.rowcount
|
||||
for idx, row in enumerate(cur):
|
||||
update_line(idx, n, row["description"])
|
||||
# some date are set to None, use the previous one
|
||||
date = row["transac_date"]
|
||||
try:
|
||||
date = make_aware(row["transac_date"])
|
||||
except (pytz.NonExistentTimeError, pytz.AmbiguousTimeError):
|
||||
date = make_aware(row["transac_date"] + datetime.timedelta(hours=1)
|
||||
|
||||
obj_dict = {
|
||||
# "pk": row["id"],
|
||||
"destination_id": MAP_IDBDE[row["destinataire"]],
|
||||
|
|
Loading…
Reference in New Issue