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
aeb5ac9f
Commit
aeb5ac9f
authored
4 years ago
by
Pierre-antoine Comby
Browse files
Options
Downloads
Patches
Plain Diff
add support for transactions
parent
6ed65514
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
management/commands/import_nk15.py
+30
-8
30 additions, 8 deletions
management/commands/import_nk15.py
with
30 additions
and
8 deletions
management/commands/import_nk15.py
+
30
−
8
View file @
aeb5ac9f
...
...
@@ -47,9 +47,7 @@ def update_line(n,N, content):
n
=
str
(
n
)
N
=
str
(
N
)
n
.
rjust
(
len
(
N
))
content
.
ljust
(
41
)
content
=
content
[:
40
]
print
(
f
"
(
{
n
}
/
{
N
}
)
{
content
}
"
,
end
=
"
\r
"
)
print
(
f
"
(
{
n
}
/
{
N
}
)
{
content
:
10.10
}
"
,
end
=
"
\r
"
)
@transaction.atomic
def
import_comptes
(
cur
):
...
...
@@ -154,7 +152,7 @@ def import_boutons(cur):
@transaction.atomic
def
import_transaction
(
cur
):
cur
.
execute
(
"
SELECT * FROM transactions LEFT JOIN adhesions ON transactions.id = adhesions.idtransaction ORDER BY
-
id;
"
)
cur
.
execute
(
"
SELECT * FROM transactions LEFT JOIN adhesions ON transactions.id = adhesions.idtransaction ORDER BY
transaction.
id;
"
)
N
=
cur
.
rowcount
for
idx
,
row
in
enumerate
(
cur
):
update_line
(
idx
,
N
,
row
[
"
label
"
])
...
...
@@ -168,7 +166,10 @@ def import_transaction(cur):
"
reason
"
:
row
[
"
description
"
],
"
valid
"
:
row
[
"
valide
"
],
}
if
row
[
"
type
"
]
==
"
bouton
"
:
ttype
=
row
[
"
type
"
]
if
ttype
==
"
don
"
or
ttype
==
"
transfert
"
or
ttype
==
"
invitation
"
:
transac
=
Transaction
.
objects
.
create
(
**
obj_dict
)
elif
ttype
==
"
bouton
"
:
cat_name
=
row
[
"
categorie
"
]
if
cat_name
==
None
:
cat_name
=
'
None
'
...
...
@@ -177,8 +178,29 @@ def import_transaction(cur):
cat
.
save
()
obj_dict
[
"
category
"
]
=
cat
transac
=
RecurrentTransaction
.
objects
.
create
(
**
obj_dict
)
transac
.
save
()
elif
row
[
"
type
"
]
==
"
adhésion
"
:
elif
ttype
==
"
crédit
"
or
ttype
==
"
retrait
"
:
field_id
=
"
source_id
"
if
ttype
==
"
crédit
"
else
"
destination_id
"
if
"
espèce
"
in
row
[
"
description
"
]:
obj_dict
[
field_id
]
=
1
elif
"
carte
"
in
row
[
"
description
"
]:
obj_dict
[
field_id
]
=
2
elif
"
cheques
"
in
row
[
"
description
"
]:
obj_dict
[
field_id
]
=
3
elif
"
virement
"
in
row
[
"
description
"
]:
obj_dict
[
field_id
]
=
4
actor
=
Note
.
objects
.
get
(
MAP_IDBDE
[
max
(
row
[
"
destinataire
"
],
row
[
"
emetteur
"
])])
# custom fields of SpecialTransaction
if
dest
.
__class__
.
__name__
==
"
NoteUser
"
:
obj_dict
[
"
first_name
"
]
=
dest
.
user
.
first_name
obj_dict
[
"
last_name
"
]
=
dest
.
user
.
last_name
elif
dest
.
__class__
.
__name__
==
"
NoteClub
"
:
obj_dict
[
"
first_name
"
]
=
dest
.
club
.
name
obj_dict
[
"
last_name
"
]
=
dest
.
club
.
name
else
:
raise
(
"
You should
'
nt be there
"
)
transac
=
SpecialTransaction
.
objects
.
create
(
**
obj_dict
)
elif
ttype
==
"
adhésion
"
:
print
(
"
adhesion not supported yet
"
)
else
:
print
(
"
other type not supported yet
"
)
...
...
@@ -246,7 +268,7 @@ class Command(BaseCommand):
MAP_IDBDE
=
json
.
load
(
fp
)
if
kwargs
[
"
save
"
]:
filename
=
kwargs
[
"
save
"
]
with
open
(
filename
,
'
w
'
)
as
fp
:
with
open
(
filename
,
'
r
'
)
as
fp
:
json
.
dump
(
MAP_IDBDE
,
fp
,
sort_keys
=
True
,
indent
=
2
)
# /!\ need a prober MAP_IDBDE
...
...
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