Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
warpinfra
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Value stream analytics
Contributor 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
Sebastian
warpinfra
Commits
0657deed
Commit
0657deed
authored
8 years ago
by
Christian Dresen
Browse files
Options
Downloads
Patches
Plain Diff
[WarpPay] Fixed Transaction REST API Endpoint
parent
e027df92
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
www/web/warppay/urls.py
+1
-1
1 addition, 1 deletion
www/web/warppay/urls.py
www/web/warppay/views.py
+30
-15
30 additions, 15 deletions
www/web/warppay/views.py
with
31 additions
and
16 deletions
www/web/warppay/urls.py
+
1
−
1
View file @
0657deed
...
...
@@ -8,7 +8,7 @@ urlpatterns = [
url
(
r
'
^api/products/$
'
,
views
.
product_list
),
url
(
r
'
^api/categories/$
'
,
views
.
category_list
),
# url(r'^api/gen_token/$', views.gen_token),
url
(
r
'
^api/transaction/(?P<user_id>\w+)/$
'
,
views
.
transaction
),
url
(
r
'
^api/transaction
s
/(?P<user_id>\w+)/$
'
,
views
.
multiple_
transaction
),
url
(
r
'
^api/products/(?P<prod_id>\w+)/barcode/$
'
,
views
.
addBarcode
),
]
This diff is collapsed.
Click to expand it.
www/web/warppay/views.py
+
30
−
15
View file @
0657deed
...
...
@@ -115,13 +115,12 @@ def user_list(request, user_id = 0):
return
Response
(
serializer
.
data
,
status
=
state
)
return
Response
()
@api_view
([
'
PUT
'
])
@authentication_classes
((
TokenAuthentication
,))
@permission_classes
((
IsAuthenticated
,))
def
transaction
(
request
,
user_id
=
None
):
def
multiple_
transaction
(
request
,
user_id
=
None
):
if
request
.
method
==
'
PUT
'
:
if
'
trans_type
'
not
in
request
.
data
or
not
user_id
:
if
not
user_id
:
return
Response
(
status
=
status
.
HTTP_406_NOT_ACCEPTABLE
)
try
:
...
...
@@ -129,38 +128,54 @@ def transaction(request, user_id=None):
except
ObjectDoesNotExist
:
return
Response
(
status
=
status
.
HTTP_404_NOT_FOUND
)
transactions
=
[]
products
=
[]
for
transact
in
request
.
data
:
if
'
trans_type
'
not
in
transact
:
return
Response
(
status
=
status
.
HTTP_406_NOT_ACCEPTABLE
)
t
=
Transaction
()
t
.
type
=
int
(
request
.
data
[
'
trans_type
'
])
t
.
type
=
int
(
transact
[
'
trans_type
'
])
if
t
.
type
==
1
:
if
'
amount
'
not
in
request
.
data
or
(
'
amount
'
in
request
.
data
and
float
(
request
.
data
[
'
amount
'
]
<
0
)):
if
'
amount
'
not
in
transact
or
(
'
amount
'
in
transact
and
float
(
transact
[
'
amount
'
]
<
0
)):
return
Response
(
status
=
status
.
HTTP_406_NOT_ACCEPTABLE
)
if
'
cash_paid
'
in
request
.
data
:
t
.
cash_paid
=
bool
(
request
.
data
[
'
cash_paid
'
])
if
'
cash_paid
'
in
transact
:
t
.
cash_paid
=
bool
(
transact
[
'
cash_paid
'
])
else
:
t
.
cash_paid
=
True
t
.
amount
=
float
(
request
.
data
[
'
amount
'
])
u
.
credit
+=
t
.
amount
t
.
amount
=
float
(
transact
[
'
amount
'
])
u
.
credit
+=
t
.
amount
elif
t
.
type
==
2
:
try
:
product
=
Product
.
objects
.
get
(
id
=
request
.
data
[
'
product
'
][
'
id
'
])
product
=
Product
.
objects
.
get
(
id
=
transact
[
'
product
'
][
'
id
'
])
t
.
product
=
product
if
'
cash_paid
'
in
request
.
data
:
t
.
cash_paid
=
bool
(
request
.
data
[
'
cash_paid
'
])
if
'
cash_paid
'
in
transact
:
t
.
cash_paid
=
bool
(
transact
[
'
cash_paid
'
])
t
.
amount
=
product
.
price_vk
if
not
t
.
cash_paid
:
u
.
credit
-=
t
.
amount
product
.
stock_count
-=
1
product
.
save
(
)
product
s
.
append
(
product
)
except
:
return
Response
(
status
=
status
.
HTTP_406_NOT_ACCEPTABLE
)
else
:
return
Response
(
status
=
status
.
HTTP_406_NOT_ACCEPTABLE
)
transactions
.
append
(
t
)
for
t
in
transactions
:
t
.
save
()
u
.
save
()
return
Response
()
print
(
t
)
for
p
in
products
:
p
.
save
()
print
(
p
)
u
.
save
()
print
(
u
)
return
Response
()
def
sync_users
():
for
ldapuser
in
LdapUser
.
objects
.
all
():
...
...
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