Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nk20-scripts
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BDE
nk20-scripts
Commits
dce51ad2
Commit
dce51ad2
authored
4 years ago
by
ynerant
Browse files
Options
Downloads
Patches
Plain Diff
Add note consistency check script
parent
877d2e28
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
management/commands/check_consistency.py
+39
-0
39 additions, 0 deletions
management/commands/check_consistency.py
with
39 additions
and
0 deletions
management/commands/check_consistency.py
0 → 100644
+
39
−
0
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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment