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
f0aa4269
Commit
f0aa4269
authored
4 years ago
by
ynerant
Browse files
Options
Downloads
Patches
Plain Diff
Import remittances
parent
60a6b3c7
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
management/commands/import_nk15.py
+53
-1
53 additions, 1 deletion
management/commands/import_nk15.py
with
53 additions
and
1 deletion
management/commands/import_nk15.py
+
53
−
1
View file @
f0aa4269
...
...
@@ -19,6 +19,7 @@ from note.models import Alias
from
note.models
import
TemplateCategory
,
TransactionTemplate
,
\
Transaction
,
RecurrentTransaction
,
SpecialTransaction
from
member.models
import
Club
,
Membership
from
treasury.models
import
RemittanceType
,
Remittance
,
SpecialTransactionProxy
"""
Script d
'
import de la nk15:
...
...
@@ -43,6 +44,7 @@ MAP_IDBDE = {
MAP_IDACTIVITY
=
{}
MAP_NAMEACTIVITY
=
{}
MAP_NAMEGUEST
=
{}
MAP_IDSPECIALTRANSACTION
=
{}
def
update_line
(
n
,
total
,
content
):
...
...
@@ -210,7 +212,9 @@ def import_transaction(cur):
obj_dict
[
"
last_name
"
]
=
actor
.
club
.
name
else
:
raise
Exception
(
"
You should
'
nt be there
"
)
SpecialTransaction
.
objects
.
create
(
**
obj_dict
)
tr
=
SpecialTransaction
.
objects
.
create
(
**
obj_dict
)
if
"
cheques
"
in
row
[
"
description
"
]:
MAP_IDSPECIALTRANSACTION
[
row
[
"
id
"
]]
=
tr
elif
ttype
==
"
adhésion
"
:
# Since BDE and Kfet are distinct, don't import membership transaction and use our custom transactions.
pass
...
...
@@ -389,6 +393,50 @@ def import_memberships(cur):
raise
e
@transaction.atomic
def
import_remittances
(
cur
):
cur
.
execute
(
"
SELECT * FROM remises ORDER by id
"
)
map_idremittance
=
{}
n
=
cur
.
rowcount
check_type
=
RemittanceType
.
objects
.
get
(
note__name
=
"
Chèque
"
)
for
idx
,
row
in
enumerate
(
cur
):
update_line
(
idx
,
n
,
row
[
"
date
"
])
obj_dict
=
{
"
date
"
:
row
[
"
date
"
][
10
:],
"
remittance_type
"
:
check_type
,
"
comment
"
:
row
[
"
commentaire
"
],
"
closed
"
:
row
[
"
close
"
],
}
try
:
with
transaction
.
atomic
():
remittance
=
Remittance
.
objects
.
get_or_create
(
**
obj_dict
)
map_idremittance
[
row
[
"
id
"
]]
=
remittance
except
IntegrityError
as
e
:
raise
e
print
(
"
remittances are imported
"
)
print
(
"
imported checks
"
)
cur
.
execute
(
"
SELECT * FROM cheques ORDER by id
"
)
n
=
cur
.
rowcount
for
idx
,
row
in
enumerate
(
cur
):
update_line
(
idx
,
n
,
row
[
"
date
"
])
obj_dict
=
{
"
date
"
:
row
[
"
date
"
][
10
:],
"
remittance_type
"
:
check_type
,
"
comment
"
:
row
[
"
commentaire
"
],
"
closed
"
:
row
[
"
close
"
],
}
tr
=
MAP_IDSPECIALTRANSACTION
[
row
[
"
idtransaction
"
]]
proxy
=
SpecialTransactionProxy
.
objects
.
get_or_create
(
transaction
=
tr
)
proxy
.
remittance
=
map_idremittance
[
row
[
"
idremise
"
]]
try
:
with
transaction
.
atomic
():
proxy
.
save
()
except
IntegrityError
as
e
:
raise
e
class
Command
(
BaseCommand
):
"""
Command for importing the database of NK15.
...
...
@@ -405,6 +453,7 @@ class Command(BaseCommand):
parser
.
add_argument
(
'
-al
'
,
'
--aliases
'
,
action
=
'
store_true
'
,
help
=
"
import aliases
"
)
parser
.
add_argument
(
'
-ac
'
,
'
--activities
'
,
action
=
'
store_true
'
,
help
=
"
import activities
"
)
parser
.
add_argument
(
'
-M
'
,
'
--memberships
'
,
action
=
'
store_true
'
,
help
=
"
import memberships
"
)
parser
.
add_argument
(
'
-r
'
,
'
--remittances
'
,
action
=
'
store_true
'
,
help
=
"
import check remittances
"
)
parser
.
add_argument
(
'
-s
'
,
'
--save
'
,
action
=
'
store
'
,
help
=
"
save mapping of idbde
"
)
parser
.
add_argument
(
'
-m
'
,
'
--map
'
,
action
=
'
store
'
,
help
=
"
import mapping of idbde
"
)
parser
.
add_argument
(
'
-d
'
,
'
--nk15db
'
,
action
=
'
store
'
,
default
=
'
nk15
'
,
help
=
'
NK15 database name
'
)
...
...
@@ -452,3 +501,6 @@ class Command(BaseCommand):
if
kwargs
[
"
memberships
"
]:
import_memberships
(
cur
)
self
.
print_success
(
"
memberships imported
\n
"
)
if
kwargs
[
"
remittances
"
]:
import_remittances
(
cur
)
self
.
print_success
(
"
remittances imported
\n
"
)
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