Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Sith
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
59
Issues
59
List
Boards
Labels
Service Desk
Milestones
Merge Requests
9
Merge Requests
9
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
AE
Sith
Commits
525d7e67
Commit
525d7e67
authored
Jul 22, 2016
by
Skia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add atomic transaction in counters
parent
1f3e186e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
23 deletions
+28
-23
counter/templates/counter/user_account.jinja
counter/templates/counter/user_account.jinja
+1
-0
counter/views.py
counter/views.py
+27
-23
No files found.
counter/templates/counter/user_account.jinja
View file @
525d7e67
...
...
@@ -6,6 +6,7 @@
{%
block
infos
%}
<h3>
{%
trans
%}
User account
{%
endtrans
%}
</h3>
<p>
{%
trans
%}
Amount:
{%
endtrans
%}{{
customer.amount
}}
€
</p>
<p>
{{
customer.refillings.all
()
}}
</p>
<p>
{{
customer.buyings.all
()
}}
</p>
{%
endblock
%}
...
...
counter/views.py
View file @
525d7e67
...
...
@@ -10,6 +10,7 @@ from django.utils import timezone
from
django
import
forms
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.conf
import
settings
from
django.db
import
DataError
,
transaction
import
re
...
...
@@ -218,31 +219,34 @@ class CounterClick(DetailView):
def
finish
(
self
,
request
):
""" Finish the click session, and validate the basket """
if
self
.
is_barman_price
():
seller
=
self
.
customer
.
user
else
:
seller
=
Counter
.
get_random_barman
(
self
.
object
.
id
)
request
.
session
[
'last_basket'
]
=
[]
for
pid
,
infos
in
request
.
session
[
'basket'
].
items
():
# This duplicates code for DB optimization (prevent to load many times the same object)
p
=
Product
.
objects
.
filter
(
pk
=
pid
).
first
()
with
transaction
.
atomic
():
if
self
.
is_barman_price
():
uprice
=
p
.
special_selling_price
seller
=
self
.
customer
.
user
else
:
uprice
=
p
.
selling_price
request
.
session
[
'last_basket'
].
append
(
"%d x %s"
%
(
infos
[
'qty'
],
p
.
name
))
s
=
Selling
(
product
=
p
,
counter
=
self
.
object
,
unit_price
=
uprice
,
quantity
=
infos
[
'qty'
],
seller
=
seller
,
customer
=
self
.
customer
)
s
.
save
()
request
.
session
[
'last_customer'
]
=
self
.
customer
.
user
.
get_display_name
()
request
.
session
[
'last_total'
]
=
"%0.2f"
%
self
.
sum_basket
(
request
)
request
.
session
[
'new_customer_amount'
]
=
str
(
self
.
customer
.
amount
)
del
request
.
session
[
'basket'
]
request
.
session
.
modified
=
True
kwargs
=
{
'counter_id'
:
self
.
object
.
id
,
}
return
HttpResponseRedirect
(
reverse_lazy
(
'counter:details'
,
args
=
self
.
args
,
kwargs
=
kwargs
))
seller
=
Counter
.
get_random_barman
(
self
.
object
.
id
)
request
.
session
[
'last_basket'
]
=
[]
for
pid
,
infos
in
request
.
session
[
'basket'
].
items
():
# This duplicates code for DB optimization (prevent to load many times the same object)
p
=
Product
.
objects
.
filter
(
pk
=
pid
).
first
()
if
self
.
is_barman_price
():
uprice
=
p
.
special_selling_price
else
:
uprice
=
p
.
selling_price
if
uprice
*
infos
[
'qty'
]
>
self
.
customer
.
amount
:
raise
DataError
(
_
(
"You have not enough money to buy all the basket"
))
request
.
session
[
'last_basket'
].
append
(
"%d x %s"
%
(
infos
[
'qty'
],
p
.
name
))
s
=
Selling
(
product
=
p
,
counter
=
self
.
object
,
unit_price
=
uprice
,
quantity
=
infos
[
'qty'
],
seller
=
seller
,
customer
=
self
.
customer
)
s
.
save
()
request
.
session
[
'last_customer'
]
=
self
.
customer
.
user
.
get_display_name
()
request
.
session
[
'last_total'
]
=
"%0.2f"
%
self
.
sum_basket
(
request
)
request
.
session
[
'new_customer_amount'
]
=
str
(
self
.
customer
.
amount
)
del
request
.
session
[
'basket'
]
request
.
session
.
modified
=
True
kwargs
=
{
'counter_id'
:
self
.
object
.
id
,
}
return
HttpResponseRedirect
(
reverse_lazy
(
'counter:details'
,
args
=
self
.
args
,
kwargs
=
kwargs
))
def
cancel
(
self
,
request
):
""" Cancel the click session """
...
...
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