Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
AE
Sith
Commits
ffe2aec9
Commit
ffe2aec9
authored
Jun 01, 2016
by
Skia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement barman prices and improve counter views
parent
6c48b7c7
Pipeline
#31
passed with stage
in 1 minute and 6 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
21 deletions
+44
-21
core/management/commands/populate.py
core/management/commands/populate.py
+1
-0
core/models.py
core/models.py
+3
-0
counter/templates/counter/counter_click.jinja
counter/templates/counter/counter_click.jinja
+1
-1
counter/templates/counter/counter_main.jinja
counter/templates/counter/counter_main.jinja
+11
-0
counter/views.py
counter/views.py
+28
-20
No files found.
core/management/commands/populate.py
View file @
ffe2aec9
...
...
@@ -140,6 +140,7 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
# Counters
Customer
(
user
=
skia
,
account_id
=
"6568j"
,
amount
=
0
).
save
()
Customer
(
user
=
r
,
account_id
=
"4000"
,
amount
=
0
).
save
()
p
=
ProductType
(
name
=
"Bières bouteilles"
)
p
.
save
()
barb
=
Product
(
name
=
"Barbar"
,
code
=
"BARB"
,
product_type
=
p
,
purchase_price
=
"1.50"
,
selling_price
=
"1.7"
,
...
...
core/models.py
View file @
ffe2aec9
...
...
@@ -269,6 +269,9 @@ class AnonymousUser(AuthAnonymousUser):
return
True
return
False
def
get_display_name
(
self
):
return
_
(
"Visitor"
)
class
LockError
(
Exception
):
"""There was a lock error on the object"""
pass
...
...
counter/templates/counter/counter_click.jinja
View file @
ffe2aec9
...
...
@@ -22,7 +22,7 @@
<p><strong>
Club:
</strong>
{{
counter.club
}}
</p>
<div>
<p>
Customer:
{{
customer
}}
</p>
<p>
Customer:
{{
customer
.user.get_display_name
()
}}
,
{{
customer.amount
}}
€
</p>
<p>
Basket:
</p>
<ul>
{%
for
id
,
qte
in
request.session
[
'basket'
]
.
items
()
%}
...
...
counter/templates/counter/counter_main.jinja
View file @
ffe2aec9
...
...
@@ -16,6 +16,17 @@
<div>
<h3>
Sellings
</h3>
{%
if
last_basket
%}
<h4>
Last selling:
</h4>
<p>
Client:
{{
last_customer
}}
, new amount:
{{
new_customer_amount
}}
€.
</p>
<ul>
{%
for
s
in
last_basket
%}
<li>
{{
s
}}
</li>
{%
endfor
%}
</ul>
<p><strong>
Total:
{{
last_total
}}
€
</strong></p>
{%
endif
%}
{%
if
barmen
%}
<p>
Enter client code:
</p>
<form
method=
"post"
action=
"
{{
url
(
'counter:details'
,
counter_id
=
counter.id
)
}}
"
>
...
...
counter/views.py
View file @
ffe2aec9
...
...
@@ -60,6 +60,11 @@ class CounterMain(DetailView, ProcessFormView, FormMixin):
kwargs
[
'login_form'
]
=
AuthenticationForm
()
kwargs
[
'form'
]
=
self
.
get_form
()
kwargs
[
'barmen'
]
=
Counter
.
get_barmen_list
(
self
.
object
.
id
)
if
'last_basket'
in
self
.
request
.
session
.
keys
():
kwargs
[
'last_basket'
]
=
self
.
request
.
session
.
pop
(
'last_basket'
)
kwargs
[
'last_customer'
]
=
self
.
request
.
session
.
pop
(
'last_customer'
)
kwargs
[
'last_total'
]
=
self
.
request
.
session
.
pop
(
'last_total'
)
kwargs
[
'new_customer_amount'
]
=
self
.
request
.
session
.
pop
(
'new_customer_amount'
)
return
kwargs
def
form_valid
(
self
,
form
):
...
...
@@ -69,26 +74,9 @@ class CounterMain(DetailView, ProcessFormView, FormMixin):
self
.
kwargs
[
'user_id'
]
=
form
.
cleaned_data
[
'user_id'
]
return
super
(
CounterMain
,
self
).
form_valid
(
form
)
def
get_success_url
(
self
):
return
reverse_lazy
(
'counter:click'
,
args
=
self
.
args
,
kwargs
=
self
.
kwargs
)
class
BasketForm
(
forms
.
Form
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
print
(
kwargs
)
super
(
BasketForm
,
self
).
__init__
(
*
args
,
**
kwargs
)
for
p
in
kwargs
[
'initial'
][
'counter'
].
products
.
all
():
# TODO: filter on the allowed products for this counter
self
.
fields
[
p
.
id
]
=
forms
.
IntegerField
(
label
=
p
.
name
,
required
=
False
)
# TODO ^: add some extra infos for the products (price, or ID to load infos dynamically)
def
clean
(
self
):
cleaned_data
=
super
(
BasketForm
,
self
).
clean
()
total
=
0
for
pid
,
q
in
cleaned_data
.
items
():
p
=
Product
.
objects
.
filter
(
id
=
pid
).
first
()
total
+=
(
q
or
0
)
*
p
.
selling_price
print
(
total
)
class
CounterClick
(
DetailView
):
"""
The click view
...
...
@@ -151,13 +139,33 @@ class CounterClick(DetailView):
def
finish
(
self
,
request
):
""" Finish the click session, and validate the basket """
if
self
.
customer
in
Counter
.
get_barmen_list
(
self
.
object
.
id
):
seller
=
self
.
customer
.
user
barman
=
True
else
:
seller
=
Counter
.
get_random_barman
(
self
.
object
.
id
)
barman
=
False
total
=
0
kwargs
=
{
'counter_id'
:
self
.
object
.
id
,
}
request
.
session
[
'last_basket'
]
=
[]
for
pid
,
qty
in
request
.
session
[
'basket'
].
items
():
p
=
Product
.
objects
.
filter
(
pk
=
pid
).
first
()
s
=
Selling
(
product
=
p
,
counter
=
self
.
object
,
unit_price
=
p
.
selling_price
,
quantity
=
qty
,
seller
=
Counter
.
get_random_barman
(
self
.
object
.
id
),
customer
=
self
.
customer
)
if
barman
:
uprice
=
p
.
special_selling_price
else
:
uprice
=
p
.
selling_price
total
+=
uprice
request
.
session
[
'last_basket'
].
append
(
"%d x %s"
%
(
qty
,
p
.
name
))
s
=
Selling
(
product
=
p
,
counter
=
self
.
object
,
unit_price
=
uprice
,
quantity
=
qty
,
seller
=
seller
,
customer
=
self
.
customer
)
s
.
save
()
kwargs
=
{
'counter_id'
:
self
.
object
.
id
}
request
.
session
[
'last_customer'
]
=
self
.
customer
.
user
.
get_display_name
()
request
.
session
[
'last_total'
]
=
str
(
total
)
request
.
session
[
'new_customer_amount'
]
=
str
(
self
.
customer
.
amount
)
del
request
.
session
[
'basket'
]
request
.
session
.
modified
=
True
return
HttpResponseRedirect
(
reverse_lazy
(
'counter:details'
,
args
=
self
.
args
,
kwargs
=
kwargs
))
def
cancel
(
self
,
request
):
...
...
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