Skip to content
GitLab
Explore
Sign in
Commits on Source (2)
Scripts are not executable
· 43734b91
ynerant
authored
Jul 25, 2020
43734b91
Import remittances
· 85568dd4
ynerant
authored
Jul 26, 2020
85568dd4
Hide whitespace changes
Inline
Side-by-side
management/commands/_import_utils.py
View file @
85568dd4
#!/usr/bin/env python3
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
import
json
import
time
...
...
management/commands/import_account.py
View file @
85568dd4
#!/usr/bin/env python3
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
import
psycopg2
as
pg
import
psycopg2.extras
as
pge
...
...
management/commands/import_activities.py
View file @
85568dd4
#!/usr/bin/env python3
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
import
psycopg2
as
pg
import
psycopg2.extras
as
pge
...
...
management/commands/import_nk15.py
View file @
85568dd4
#!/usr/env/bin python3
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
import
subprocess
from
django.core.management.base
import
BaseCommand
...
...
management/commands/import_transaction.py
View file @
85568dd4
#!/usr/bin/env python3
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
import
re
import
psycopg2
as
pg
import
psycopg2.extras
as
pge
...
...
@@ -21,8 +23,12 @@ from note.models import Note, NoteClub
from
activity.models
import
Guest
,
GuestTransaction
,
Entry
from
member.models
import
Membership
from
treasury.models
import
Remittance
,
SpecialTransactionProxy
from
._import_utils
import
ImportCommand
,
BulkCreateManager
,
timed
MAP_TRANSACTION
=
dict
()
MAP_REMITTANCE
=
dict
()
# from member/fixtures/initial
BDE_PK
=
1
KFET_PK
=
2
...
...
@@ -157,7 +163,7 @@ class Command(ImportCommand):
).
first
().
pk
child_dict
[
"
entry_id
"
]
=
entry_id
else
:
raise
(
f
"
Guest not Found
{
row
[
'
id
'
]
}
{
first_name
}
, last_name
"
)
raise
Exception
(
f
"
Guest not Found
{
row
[
'
id
'
]
}
first_name, last_name
"
)
return
obj_dict
,
child_dict
,
GuestTransaction
...
...
@@ -166,7 +172,7 @@ class Command(ImportCommand):
def
import_transaction
(
self
,
cur
,
chunk_size
,
idmin
):
bulk_mgr
=
BulkCreateManager
(
chunk_size
=
chunk_size
)
cur
.
execute
(
f
"
SELECT t.date AS transac_date, t.type, t.emetteur,
\
f
"
SELECT
t.id,
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
\
...
...
@@ -179,6 +185,9 @@ class Command(ImportCommand):
pk_transaction
=
1
for
idx
,
row
in
enumerate
(
cur
):
self
.
update_line
(
idx
,
n
,
row
[
"
description
"
])
MAP_TRANSACTION
[
row
[
"
id
"
]]
=
pk_transaction
try
:
date
=
make_aware
(
row
[
"
transac_date
"
])
except
(
pytz
.
NonExistentTimeError
,
pytz
.
AmbiguousTimeError
):
...
...
@@ -225,7 +234,8 @@ class Command(ImportCommand):
}
pk_membership
+=
1
pk_transaction
+=
1
obj_dict
,
child_dict
,
child_transaction
=
self
.
_membership_transaction
(
row
,
obj_dict
,
child_dict
,
pk_membership
)
obj_dict
,
child_dict
,
child_transaction
=
\
self
.
_membership_transaction
(
row
,
obj_dict
,
child_dict
,
pk_membership
)
# Kfet membership
# BDE Membership
obj_dict
[
"
pk
"
]
=
pk_transaction
...
...
@@ -270,6 +280,51 @@ class Command(ImportCommand):
pk_transaction
+=
1
bulk_mgr
.
done
()
@timed
@transaction.atomic
def
import_remittances
(
self
,
cur
,
chunk_size
):
bulk_mgr
=
BulkCreateManager
(
chunk_size
=
chunk_size
)
cur
.
execute
(
"
SELECT id, date, commentaire, close FROM remises WHERE id = 105 ORDER BY id;
"
)
n
=
cur
.
rowcount
pk_remittance
=
1
for
idx
,
row
in
enumerate
(
cur
):
self
.
update_line
(
idx
,
n
,
row
[
"
commentaire
"
])
MAP_REMITTANCE
[
row
[
"
id
"
]]
=
pk_remittance
remittance_dict
=
{
"
pk
"
:
pk_remittance
,
"
date
"
:
make_aware
(
row
[
"
date
"
]),
"
remittance_type_id
"
:
1
,
# Only Bank checks are supported in NK15
"
comment
"
:
row
[
"
commentaire
"
],
"
closed
"
:
row
[
"
close
"
],
}
bulk_mgr
.
add
(
Remittance
(
**
remittance_dict
))
pk_remittance
+=
1
bulk_mgr
.
done
()
@timed
def
import_checks
(
self
,
cur
):
cur
.
execute
(
"
SELECT id, nom, prenom, banque, idtransaction, idremise
"
"
FROM cheques WHERE idremise = 105 ORDER BY id;
"
)
n
=
cur
.
rowcount
for
idx
,
row
in
enumerate
(
cur
):
self
.
update_line
(
idx
,
n
,
row
[
"
nom
"
])
tr
=
SpecialTransactionProxy
.
objects
.
get
(
transaction__id
=
MAP_TRANSACTION
[
row
[
"
idtransaction
"
]])
tr
.
remittance_id
=
MAP_REMITTANCE
[
row
[
"
idremise
"
]]
tr
.
save
()
tr
=
tr
.
transaction
tr
.
last_name
=
row
[
"
nom
"
]
tr
.
first_name
=
row
[
"
prenom
"
]
tr
.
bank
=
row
[
"
banque
"
]
tr
.
save
()
@timed
def
set_roles
(
self
):
bulk_mgr
=
BulkCreateManager
(
chunk_size
=
10000
)
...
...
@@ -297,3 +352,5 @@ class Command(ImportCommand):
self
.
import_buttons
(
cur
,
kwargs
[
"
chunk
"
],
kwargs
[
"
buttons
"
])
self
.
import_transaction
(
cur
,
kwargs
[
"
chunk
"
],
kwargs
[
"
transactions
"
])
self
.
set_roles
()
self
.
import_remittances
(
cur
,
kwargs
[
"
chunk
"
])
self
.
import_checks
(
cur
)
management/commands/refresh_highlighted_buttons.py
View file @
85568dd4
#!/usr/bin/env python3
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from
datetime
import
timedelta
...
...
management/commands/syncsql.py
View file @
85568dd4
#!/usr/bin/env python3
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from
django.core.management.base
import
BaseCommand
from
django.apps
import
apps
...
...