Skip to content
GitLab
Explore
Sign in
Commits on Source (2)
Import the creation date of the accounts
· ceb7063f
ynerant
authored
Aug 01, 2020
ceb7063f
Update the balance of the Kfet club
· dd8b48c3
ynerant
authored
Aug 01, 2020
dd8b48c3
Hide whitespace changes
Inline
Side-by-side
management/commands/import_account.py
View file @
dd8b48c3
...
...
@@ -19,7 +19,7 @@ from member.models import Club, Profile
from
._import_utils
import
ImportCommand
,
BulkCreateManager
,
timed
M_DURATION
=
396
M_START
=
datetime
.
date
(
2019
,
8
,
3
1
)
M_START
=
datetime
.
date
(
2019
,
8
,
1
)
M_END
=
datetime
.
date
(
2020
,
9
,
30
)
MAP_IDBDE
=
{
...
...
@@ -60,6 +60,13 @@ class Command(ImportCommand):
Every Model has to be manually created, and no magic `.save()`
function is being called.
"""
# Get promotion and date of creation of the account
cur
.
execute
(
"
SELECT idbde, MIN(date) AS created_at, MIN(annee) AS promo FROM adhesions
"
"
GROUP BY idbde ORDER BY promo, created_at;
"
)
MAP_IDBDE_PROMOTION
=
{}
for
row
in
cur
:
MAP_IDBDE_PROMOTION
[
row
[
"
idbde
"
]]
=
row
cur
.
execute
(
"
SELECT * FROM comptes WHERE idbde > 0 ORDER BY idbde;
"
)
pk_club
=
3
pk_user
=
1
...
...
@@ -84,7 +91,6 @@ class Command(ImportCommand):
"
last_negative
"
:
None
,
"
is_active
"
:
True
,
"
display_image
"
:
"
pic/default.png
"
,
"
created_at
"
:
now
()
}
if
row
[
"
last_negatif
"
]
is
not
None
:
note_dict
[
"
last_negative
"
]
=
make_aware
(
row
[
"
last_negatif
"
])
...
...
@@ -95,6 +101,11 @@ class Command(ImportCommand):
else
:
passwd_nk15
=
''
if
row
[
"
idbde
"
]
not
in
MAP_IDBDE_PROMOTION
:
# NK12 bug. Applying default values
MAP_IDBDE_PROMOTION
[
row
[
"
idbde
"
]]
=
{
"
promo
"
:
2014
,
"
created_at
"
:
datetime
.
datetime
(
2014
,
9
,
1
,
0
,
0
,
0
)}
obj_dict
=
{
"
pk
"
:
pk_user
,
"
username
"
:
row
[
"
pseudo
"
],
...
...
@@ -112,7 +123,9 @@ class Command(ImportCommand):
"
paid
"
:
row
[
'
normalien
'
],
"
registration_valid
"
:
True
,
"
email_confirmed
"
:
True
,
"
promotion
"
:
MAP_IDBDE_PROMOTION
[
row
[
"
idbde
"
]][
"
promo
"
],
}
note_dict
[
"
created_at
"
]
=
make_aware
(
MAP_IDBDE_PROMOTION
[
row
[
"
idbde
"
]][
"
created_at
"
])
note_dict
[
"
polymorphic_ctype
"
]
=
note_user_type
note_user_dict
=
{
"
pk
"
:
pk_note
,
...
...
@@ -138,6 +151,7 @@ class Command(ImportCommand):
"
pk
"
:
pk_club
,
"
name
"
:
row
[
"
pseudo
"
],
"
email
"
:
row
[
"
mail
"
],
"
parent_club
"
:
1
,
# All clubs depends on BDE by default
"
membership_duration
"
:
M_DURATION
,
"
membership_start
"
:
M_START
,
"
membership_end
"
:
M_END
,
...
...
@@ -146,7 +160,7 @@ class Command(ImportCommand):
}
note_club_dict
=
{
"
pk
"
:
pk_note
,
"
club_id
"
:
pk_club
,
"
club_id
"
:
pk_club
}
alias_dict
=
{
"
pk
"
:
pk_note
,
...
...
@@ -154,16 +168,18 @@ class Command(ImportCommand):
"
normalized_name
"
:
Alias
.
normalize
(
pseudo
),
"
note_id
"
:
pk_note
}
note_dict
[
"
created_at
"
]
=
make_aware
(
row
[
"
previous_report_date
"
])
# Not perfect, but good approximation
note_dict
[
"
polymorphic_ctype
"
]
=
note_club_type
bulk_mgr
.
add
(
Club
(
**
obj_dict
),
Note
(
**
note_dict
),
NoteClub
(
**
note_club_dict
),
Alias
(
**
alias_dict
))
#
bulk_mgr.add(Club(**obj_dict),
#
Note(**note_dict),
#
NoteClub(**note_club_dict),
#
Alias(**alias_dict))
pk_club
+=
1
# row import completed
MAP_IDBDE
[
row
[
"
idbde
"
]]
=
pk_note
pk_note
+=
1
bulk_mgr
.
done
()
exit
(
0
)
@timed
def
import_alias
(
self
,
cur
,
chunk_size
):
...
...
management/commands/import_transaction.py
View file @
dd8b48c3
...
...
@@ -185,6 +185,7 @@ class Command(ImportCommand):
n
=
cur
.
rowcount
pk_membership
=
1
pk_transaction
=
1
kfet_balance
=
0
for
idx
,
row
in
enumerate
(
cur
):
if
save
or
idx
%
chunk_size
==
0
:
self
.
update_line
(
idx
,
n
,
row
[
"
description
"
])
...
...
@@ -261,6 +262,7 @@ class Command(ImportCommand):
}
obj_dict0
[
"
amount
"
]
=
bde_dict
[
"
fee
"
]
obj_dict
[
"
amount
"
]
=
kfet_dict
[
"
fee
"
]
kfet_balance
+=
kfet_dict
[
"
fee
"
]
# BDE membership Transaction is inserted before the Kfet membershipTransaction
pk_membership
+=
1
pk_transaction
+=
1
...
...
@@ -291,6 +293,14 @@ class Command(ImportCommand):
pk_transaction
+=
1
bulk_mgr
.
done
()
# Update the balance of the BDE and the Kfet club
note_bde
=
NoteClub
.
objects
.
get
(
pk
=
5
)
note_kfet
=
NoteClub
.
objects
.
get
(
pk
=
6
)
note_bde
.
balance
-=
kfet_balance
note_kfet
.
balance
+=
kfet_balance
note_bde
.
save
()
note_kfet
.
save
()
@timed
def
set_roles
(
self
):
bulk_mgr
=
BulkCreateManager
(
chunk_size
=
10000
)
...
...