fix time error and explicit select query

This commit is contained in:
Pierre-antoine Comby 2020-05-02 16:08:40 +02:00
parent f0aa426950
commit 6f0bfb175b
1 changed files with 16 additions and 7 deletions

View File

@ -3,16 +3,19 @@
import json import json
import datetime import datetime
import re import re
import pytz
import psycopg2 as pg
import psycopg2.extras as pge
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.core.management import call_command from django.core.management import call_command
import psycopg2 as pg
import psycopg2.extras as pge
from django.db import transaction from django.db import transaction
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.utils.timezone import make_aware from django.utils.timezone import make_aware
from django.db import IntegrityError from django.db import IntegrityError
from django.contrib.auth.models import User from django.contrib.auth.models import User
from activity.models import ActivityType, Activity, Guest, Entry, GuestTransaction from activity.models import ActivityType, Activity, Guest, Entry, GuestTransaction
from note.models import Note from note.models import Note
from note.models import Alias from note.models import Alias
@ -159,16 +162,22 @@ def import_boutons(cur):
@transaction.atomic @transaction.atomic
def import_transaction(cur): def import_transaction(cur):
idmin = 58770 idmin = 58770
cur.execute("SELECT *, transactions.date AS transac_date\ bde = Club.objects.get(name="BDE")
FROM transactions\ kfet = Club.objects.get(name="Kfet")
LEFT JOIN adhesions ON transactions.id = adhesions.id\ 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> {}\ WHERE transactions.id> {}\
ORDER BY transactions.id;".format(idmin)) ORDER BY transactions.id;".format(idmin))
n = cur.rowcount n = cur.rowcount
for idx, row in enumerate(cur): for idx, row in enumerate(cur):
update_line(idx, n, row["description"]) update_line(idx, n, row["description"])
# some date are set to None, use the previous one try:
date = row["transac_date"] date = make_aware(row["transac_date"])
except (pytz.NonExistentTimeError, pytz.AmbiguousTimeError):
date = make_aware(row["transac_date"] + datetime.timedelta(hours=1)
obj_dict = { obj_dict = {
# "pk": row["id"], # "pk": row["id"],
"destination_id": MAP_IDBDE[row["destinataire"]], "destination_id": MAP_IDBDE[row["destinataire"]],