Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
AE
Sith
Commits
bfb2dc5f
Commit
bfb2dc5f
authored
Aug 19, 2016
by
Skia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Kinda fix the refilling migration: there were some traps!
parent
da96e9da
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
5 deletions
+21
-5
migrate.py
migrate.py
+21
-5
No files found.
migrate.py
View file @
bfb2dc5f
...
...
@@ -2,6 +2,7 @@ import MySQLdb
import
os
import
django
import
random
import
datetime
from
io
import
StringIO
from
pytz
import
timezone
...
...
@@ -361,17 +362,27 @@ def migrate_refillings():
100
:
"OTHER"
,
None
:
"OTHER"
,
}
PAYMENT
=
{
2
:
"CARD"
,
1
:
"CASH"
,
0
:
"CHECK"
,
}
cur
=
db
.
cursor
(
MySQLdb
.
cursors
.
SSDictCursor
)
cur
.
execute
(
"""
SELECT *
FROM cpt_rechargements
"""
)
Refilling
.
objects
.
filter
(
payment_method
=
"SITH_ACCOUNT"
).
delete
()
print
(
"Sith account refillings deleted"
)
fail
=
100
root_cust
=
Customer
.
objects
.
filter
(
user__id
=
0
).
first
()
mde
=
Counter
.
objects
.
filter
(
id
=
1
).
first
()
threshold_date
=
datetime
.
datetime
(
year
=
2006
,
month
=
3
,
day
=
21
,
hour
=
22
,
minute
=
17
)
Refilling
.
objects
.
filter
(
payment_method
=
"CASH"
).
delete
()
Refilling
.
objects
.
filter
(
payment_method
=
"CHECK"
).
delete
()
Refilling
.
objects
.
filter
(
date__lte
=
threshold_date
.
replace
(
tzinfo
=
timezone
(
'Europe/Paris'
))).
delete
()
print
(
"Sith account refillings deleted"
)
fail
=
100
for
r
in
cur
:
if
r
[
'type_paiement_rech'
]
==
2
and
r
[
'date_rech'
]
>
threshold_date
:
continue
# There are no invoices before threshold_date when paid with credit card
try
:
cust
=
Customer
.
objects
.
filter
(
user__id
=
r
[
'id_utilisateur'
]).
first
()
user
=
User
.
objects
.
filter
(
id
=
r
[
'id_utilisateur'
]).
first
()
...
...
@@ -390,6 +401,7 @@ def migrate_refillings():
customer
=
cust
,
operator
=
op
or
root_cust
.
user
,
amount
=
r
[
'montant_rech'
]
/
100
,
payment_method
=
PAYMENT
[
r
[
'type_paiement_rech'
]],
bank
=
BANK
[
r
[
'banque_rech'
]],
date
=
r
[
'date_rech'
].
replace
(
tzinfo
=
timezone
(
'Europe/Paris'
)),
)
...
...
@@ -513,6 +525,10 @@ def migrate_sellings():
"""
)
Selling
.
objects
.
filter
(
payment_method
=
"SITH_ACCOUNT"
).
delete
()
print
(
"Sith account selling deleted"
)
for
c
in
Customer
.
objects
.
all
():
c
.
amount
=
sum
([
r
.
amount
for
r
in
c
.
refillings
.
all
()])
c
.
save
()
print
(
"Customer amount reset to sum of refillings"
)
ae
=
Club
.
objects
.
filter
(
unix_name
=
"ae"
).
first
()
mde
=
Counter
.
objects
.
filter
(
id
=
1
).
first
()
root
=
User
.
objects
.
filter
(
id
=
0
).
first
()
...
...
@@ -580,8 +596,8 @@ def main():
# migrate_products_to_counter()
# reset_customer_amount()
# migrate_invoices()
#
migrate_refillings()
#
migrate_sellings()
migrate_refillings
()
migrate_sellings
()
reset_index
(
'core'
,
'counter'
)
if
__name__
==
"__main__"
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment