Skip to content
GitLab
Explore
Sign in
Commits on Source (2)
🐛
Kfet transactions should go to the Kfet note
· 7d0c94c1
ynerant
authored
Aug 03, 2020
7d0c94c1
Fix note balances if needed
· f41a5a32
ynerant
authored
Aug 03, 2020
f41a5a32
Hide whitespace changes
Inline
Side-by-side
management/commands/check_consistency.py
View file @
f41a5a32
...
...
@@ -11,6 +11,7 @@ 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
'
)
parser
.
add_argument
(
'
--fix
'
,
'
-f
'
,
action
=
'
store_true
'
,
help
=
'
Fix note balances
'
)
def
handle
(
self
,
*
args
,
**
options
):
if
options
[
"
sum_all
"
]:
...
...
@@ -29,11 +30,14 @@ class Command(BaseCommand):
.
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
expec
ted_balance
=
incoming
-
outcoming
if
expec
ted_balance
!=
balance
:
calcula
ted_balance
=
incoming
-
outcoming
if
calcula
ted_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
))))
.
format
(
pretty_money
(
balance
),
pretty_money
(
calculated_balance
))))
if
options
[
"
fix
"
]:
note
.
balance
=
calculated_balance
note
.
save
()
error
=
True
exit
(
1
if
error
else
0
)
management/commands/import_transaction.py
View file @
f41a5a32
...
...
@@ -236,6 +236,7 @@ class Command(ImportCommand):
(
obj_dict0
,
child_dict0
,
child_transaction
)
=
self
.
_membership_transaction
(
row
,
obj_dict
,
child_dict
,
pk_membership
)
obj_dict0
[
"
destination_id
"
]
=
6
# Kfet note id
bde_dict
=
{
"
pk
"
:
pk_membership
,
"
user_id
"
:
user_id
,
...
...