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
c099cc48
Commit
c099cc48
authored
Jul 17, 2016
by
Skia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve refilling form to handle the checks and the banks
parent
14595936
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
7 deletions
+53
-7
counter/migrations/0004_auto_20160717_0933.py
counter/migrations/0004_auto_20160717_0933.py
+24
-0
counter/models.py
counter/models.py
+3
-2
counter/templates/counter/counter_click.jinja
counter/templates/counter/counter_click.jinja
+1
-1
counter/views.py
counter/views.py
+18
-4
sith/settings_sample.py
sith/settings_sample.py
+7
-0
No files found.
counter/migrations/0004_auto_20160717_0933.py
0 → 100644
View file @
c099cc48
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'counter'
,
'0003_customer_amount'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'refilling'
,
name
=
'bank'
,
field
=
models
.
CharField
(
verbose_name
=
'bank'
,
default
=
'other'
,
max_length
=
255
,
choices
=
[(
'other'
,
'Autre'
),
(
'la-poste'
,
'La Poste'
),
(
'credit-agricole'
,
'Credit Agricole'
),
(
'credit-mutuel'
,
'Credit Mutuel'
)]),
),
migrations
.
AlterField
(
model_name
=
'refilling'
,
name
=
'payment_method'
,
field
=
models
.
CharField
(
verbose_name
=
'payment method'
,
default
=
'cash'
,
max_length
=
255
,
choices
=
[(
'cheque'
,
'Chèque'
),
(
'cash'
,
'Espèce'
)]),
),
]
counter/models.py
View file @
c099cc48
...
...
@@ -123,8 +123,9 @@ class Refilling(models.Model):
customer
=
models
.
ForeignKey
(
Customer
,
related_name
=
"refill_customers"
,
blank
=
False
)
date
=
models
.
DateTimeField
(
_
(
'date'
),
auto_now
=
True
)
payment_method
=
models
.
CharField
(
_
(
'payment method'
),
max_length
=
255
,
choices
=
settings
.
SITH_COUNTER_PAYMENT_METHOD
)
# TODO: add the bank if the payment is made by cheque
choices
=
settings
.
SITH_COUNTER_PAYMENT_METHOD
,
default
=
'cash'
)
bank
=
models
.
CharField
(
_
(
'bank'
),
max_length
=
255
,
choices
=
settings
.
SITH_COUNTER_BANK
,
default
=
'other'
)
def
__str__
(
self
):
return
"Refilling: %.2f for %s"
%
(
self
.
amount
,
self
.
customer
.
user
.
get_display_name
())
...
...
counter/templates/counter/counter_click.jinja
View file @
c099cc48
...
...
@@ -29,8 +29,8 @@
<h5>
Refilling
</h5>
<form
method=
"post"
action=
"
{{
url
(
'counter:click'
,
counter_id
=
counter.id
,
user_id
=
customer.user.id
)
}}
"
>
{%
csrf_token
%}
{{
refill_form.as_p
()
}}
<input
type=
"hidden"
name=
"action"
value=
"refill"
>
<input
type=
"input"
name=
"amount"
value=
""
/>
<input
type=
"submit"
value=
"Go"
/>
</form>
</div>
...
...
counter/views.py
View file @
c099cc48
...
...
@@ -44,6 +44,13 @@ class GetUserForm(forms.Form):
cleaned_data
[
'user_id'
]
=
user
.
user
.
id
return
cleaned_data
class
RefillForm
(
forms
.
ModelForm
):
error_css_class
=
'error'
required_css_class
=
'required'
class
Meta
:
model
=
Refilling
fields
=
[
'amount'
,
'payment_method'
,
'bank'
]
class
CounterMain
(
DetailView
,
ProcessFormView
,
FormMixin
):
"""
The public (barman) view
...
...
@@ -101,6 +108,7 @@ class CounterClick(DetailView):
request
.
session
[
'basket'
]
=
{}
request
.
session
[
'basket_total'
]
=
0
request
.
session
[
'not_enough'
]
=
False
self
.
refill_form
=
None
ret
=
super
(
CounterClick
,
self
).
get
(
request
,
*
args
,
**
kwargs
)
if
len
(
Counter
.
get_barmen_list
(
self
.
object
.
id
))
<
1
:
# Check that at least one barman is logged in
return
self
.
cancel
(
request
)
# Otherwise, go to main view
...
...
@@ -110,6 +118,7 @@ class CounterClick(DetailView):
""" Handle the many possibilities of the post request """
self
.
object
=
self
.
get_object
()
self
.
customer
=
Customer
.
objects
.
filter
(
user__id
=
self
.
kwargs
[
'user_id'
]).
first
()
self
.
refill_form
=
None
if
len
(
Counter
.
get_barmen_list
(
self
.
object
.
id
))
<
1
:
# Check that at least one barman is logged in
return
self
.
cancel
(
request
)
if
'basket'
not
in
request
.
session
.
keys
():
...
...
@@ -243,16 +252,21 @@ class CounterClick(DetailView):
operator
=
self
.
customer
.
user
else
:
operator
=
Counter
.
get_random_barman
(
self
.
object
.
id
)
amount
=
float
(
request
.
POST
[
'amount'
])
s
=
Refilling
(
counter
=
self
.
object
,
operator
=
operator
,
customer
=
self
.
customer
,
amount
=
amount
,
payment_method
=
"cash"
)
s
.
save
()
form
=
RefillForm
(
request
.
POST
)
if
form
.
is_valid
():
form
.
instance
.
counter
=
self
.
object
form
.
instance
.
operator
=
operator
form
.
instance
.
customer
=
self
.
customer
form
.
instance
.
save
()
else
:
self
.
refill_form
=
form
def
get_context_data
(
self
,
**
kwargs
):
""" Add customer to the context """
kwargs
=
super
(
CounterClick
,
self
).
get_context_data
(
**
kwargs
)
kwargs
[
'customer'
]
=
self
.
customer
kwargs
[
'basket_total'
]
=
self
.
sum_basket
(
self
.
request
)
kwargs
[
'refill_form'
]
=
self
.
refill_form
or
RefillForm
()
return
kwargs
class
CounterLogin
(
RedirectView
):
...
...
sith/settings_sample.py
View file @
c099cc48
...
...
@@ -222,6 +222,13 @@ SITH_COUNTER_PAYMENT_METHOD = [
(
'cash'
,
'Espèce'
),
]
SITH_COUNTER_BANK
=
[
(
'other'
,
'Autre'
),
(
'la-poste'
,
'La Poste'
),
(
'credit-agricole'
,
'Credit Agricole'
),
(
'credit-mutuel'
,
'Credit Mutuel'
),
]
# Subscription durations are in semestres (should be settingized)
SITH_SUBSCRIPTIONS
=
{
'un-semestre'
:
{
...
...
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