Skip to content
GitLab
Explore
Sign in
Commits on Source (2)
Import note balance of BDE and special notes
· 877d2e28
ynerant
authored
Aug 01, 2020
877d2e28
Add note consistency check script
· dce51ad2
ynerant
authored
Aug 01, 2020
dce51ad2
Hide whitespace changes
Inline
Side-by-side
management/commands/check_consistency.py
0 → 100644
View file @
dce51ad2
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from
django.core.management
import
BaseCommand
from
django.db.models
import
Sum
,
F
from
note.models
import
Note
,
Transaction
from
note.templatetags.pretty_money
import
pretty_money
class
Command
(
BaseCommand
):
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
'
--sum-all
'
,
'
-s
'
,
action
=
'
store_true
'
,
help
=
'
Check if the global sum is equal to zero
'
)
def
handle
(
self
,
*
args
,
**
options
):
if
options
[
"
sum_all
"
]:
s
=
Note
.
objects
.
aggregate
(
Sum
(
"
balance
"
))[
"
balance__sum
"
]
if
s
:
self
.
stderr
.
write
(
self
.
style
.
NOTICE
(
"
LA SOMME DES NOTES NE VAUT PAS ZÉRO :
"
+
pretty_money
(
s
)))
exit
(
-
1
)
else
:
self
.
stdout
.
write
(
self
.
style
.
SUCCESS
(
"
La somme des notes vaut bien zéro.
"
))
exit
(
0
)
error
=
False
for
note
in
Note
.
objects
.
all
():
balance
=
note
.
balance
incoming
=
Transaction
.
objects
.
filter
(
valid
=
True
,
destination
=
note
)
\
.
annotate
(
total
=
F
(
"
quantity
"
)
*
F
(
"
amount
"
)).
aggregate
(
Sum
(
"
total
"
))[
"
total__sum
"
]
or
0
outcoming
=
Transaction
.
objects
.
filter
(
valid
=
True
,
source
=
note
)
\
.
annotate
(
total
=
F
(
"
quantity
"
)
*
F
(
"
amount
"
)).
aggregate
(
Sum
(
"
total
"
))[
"
total__sum
"
]
or
0
expected_balance
=
incoming
-
outcoming
if
expected_balance
!=
balance
:
self
.
stderr
.
write
(
self
.
style
.
NOTICE
(
"
LA SOMME DES TRANSACTIONS DE LA NOTE {} NE CORRESPOND PAS
"
"
AVEC LE MONTANT RÉEL
"
.
format
(
str
(
note
))))
self
.
stderr
.
write
(
self
.
style
.
NOTICE
(
"
Attendu : {}, calculé : {}
"
.
format
(
pretty_money
(
balance
),
pretty_money
(
expected_balance
))))
error
=
True
exit
(
1
if
error
else
0
)
management/commands/import_account.py
View file @
dce51ad2
...
...
@@ -67,6 +67,12 @@ class Command(ImportCommand):
for
row
in
cur
:
MAP_IDBDE_PROMOTION
[
row
[
"
idbde
"
]]
=
row
cur
.
execute
(
"
SELECT * FROM comptes WHERE idbde <= 0 ORDER BY idbde;
"
)
for
row
in
cur
:
note
=
Note
.
objects
.
get
(
pk
=
MAP_IDBDE
[
row
[
"
idbde
"
]])
note
.
balance
=
row
[
"
solde
"
]
note
.
save
()
cur
.
execute
(
"
SELECT * FROM comptes WHERE idbde > 0 ORDER BY idbde;
"
)
pk_club
=
3
pk_user
=
1
...
...
@@ -114,6 +120,7 @@ class Command(ImportCommand):
"
last_name
"
:
row
[
"
nom
"
],
"
email
"
:
row
[
"
mail
"
],
"
is_active
"
:
True
,
# temporary
"
date_joined
"
:
make_aware
(
MAP_IDBDE_PROMOTION
[
row
[
"
idbde
"
]][
"
created_at
"
]),
}
profile_dict
=
{
"
pk
"
:
pk_profile
,
...
...