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
6c48b7c7
Commit
6c48b7c7
authored
May 31, 2016
by
Skia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Selling and Refilling classes
parent
356a2d26
Pipeline
#30
passed with stage
in 1 minute and 10 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
149 additions
and
9 deletions
+149
-9
core/management/commands/populate.py
core/management/commands/populate.py
+16
-7
counter/admin.py
counter/admin.py
+3
-0
counter/migrations/0002_refilling_selling.py
counter/migrations/0002_refilling_selling.py
+42
-0
counter/migrations/0003_customer_amount.py
counter/migrations/0003_customer_amount.py
+21
-0
counter/models.py
counter/models.py
+56
-0
counter/views.py
counter/views.py
+6
-2
sith/settings.py
sith/settings.py
+5
-0
No files found.
core/management/commands/populate.py
View file @
6c48b7c7
...
...
@@ -8,7 +8,7 @@ from core.models import Group, User, Page, PageRev
from
accounting.models
import
GeneralJournal
,
BankAccount
,
ClubAccount
,
Operation
,
AccountingType
from
club.models
import
Club
,
Membership
from
subscription.models
import
Subscription
,
Subscriber
from
counter.models
import
Customer
,
ProductType
,
Product
from
counter.models
import
Customer
,
ProductType
,
Product
,
Counter
class
Command
(
BaseCommand
):
help
=
"Populate a new instance of the Sith AE"
...
...
@@ -138,18 +138,27 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
address
=
"Terre Du Milieu"
,
parent
=
ae
)
troll
.
save
()
#
Acc
ount
ing test values:
Customer
(
user
=
skia
,
account_id
=
"6568j"
).
save
()
#
C
ount
ers
Customer
(
user
=
skia
,
account_id
=
"6568j"
,
amount
=
0
).
save
()
p
=
ProductType
(
name
=
"Bières bouteilles"
)
p
.
save
()
Product
(
name
=
"Barbar"
,
code
=
"BARB"
,
product_type
=
p
,
purchase_price
=
"1.50"
,
selling_price
=
"1.7"
,
special_selling_price
=
"1.6"
,
club
=
ae
).
save
()
Product
(
name
=
"Chimay"
,
code
=
"CBLE"
,
product_type
=
p
,
purchase_price
=
"1.50"
,
selling_price
=
"1.7"
,
special_selling_price
=
"1.6"
,
club
=
ae
).
save
()
barb
=
Product
(
name
=
"Barbar"
,
code
=
"BARB"
,
product_type
=
p
,
purchase_price
=
"1.50"
,
selling_price
=
"1.7"
,
special_selling_price
=
"1.6"
,
club
=
ae
)
barb
.
save
()
cble
=
Product
(
name
=
"Chimay Bleue"
,
code
=
"CBLE"
,
product_type
=
p
,
purchase_price
=
"1.50"
,
selling_price
=
"1.7"
,
special_selling_price
=
"1.6"
,
club
=
ae
)
cble
.
save
()
Product
(
name
=
"Corsendonk"
,
code
=
"CORS"
,
product_type
=
p
,
purchase_price
=
"1.50"
,
selling_price
=
"1.7"
,
special_selling_price
=
"1.6"
,
club
=
ae
).
save
()
Product
(
name
=
"Carolus"
,
code
=
"CARO"
,
product_type
=
p
,
purchase_price
=
"1.50"
,
selling_price
=
"1.7"
,
special_selling_price
=
"1.6"
,
club
=
ae
).
save
()
mde
=
Counter
(
name
=
"MDE"
,
club
=
ae
,
type
=
"BAR"
)
mde
.
save
()
mde
.
products
.
add
(
barb
)
mde
.
products
.
add
(
cble
)
mde
.
save
()
# Accounting test values:
BankAccount
(
name
=
"AE TG"
,
club
=
ae
).
save
()
BankAccount
(
name
=
"Carte AE"
,
club
=
ae
).
save
()
ba
=
BankAccount
(
name
=
"AE TI"
,
club
=
ae
)
...
...
counter/admin.py
View file @
6c48b7c7
...
...
@@ -7,3 +7,6 @@ admin.site.register(Customer)
admin
.
site
.
register
(
ProductType
)
admin
.
site
.
register
(
Product
)
admin
.
site
.
register
(
Counter
)
admin
.
site
.
register
(
Refilling
)
admin
.
site
.
register
(
Selling
)
counter/migrations/0002_refilling_selling.py
0 → 100644
View file @
6c48b7c7
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
import
accounting.models
from
django.conf
import
settings
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
migrations
.
swappable_dependency
(
settings
.
AUTH_USER_MODEL
),
(
'counter'
,
'0001_initial'
),
]
operations
=
[
migrations
.
CreateModel
(
name
=
'Refilling'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
verbose_name
=
'ID'
,
primary_key
=
True
,
serialize
=
False
,
auto_created
=
True
)),
(
'amount'
,
accounting
.
models
.
CurrencyField
(
verbose_name
=
'amount'
,
decimal_places
=
2
,
max_digits
=
12
)),
(
'date'
,
models
.
DateTimeField
(
verbose_name
=
'date'
,
auto_now
=
True
)),
(
'payment_method'
,
models
.
CharField
(
verbose_name
=
'payment method'
,
max_length
=
255
,
choices
=
[(
'cheque'
,
'Chèque'
),
(
'cash'
,
'Espèce'
)])),
(
'counter'
,
models
.
ForeignKey
(
to
=
'counter.Counter'
,
related_name
=
'refillings'
)),
(
'customer'
,
models
.
ForeignKey
(
to
=
'counter.Customer'
,
related_name
=
'refill_customers'
)),
(
'operator'
,
models
.
ForeignKey
(
to
=
settings
.
AUTH_USER_MODEL
,
related_name
=
'refill_operators'
)),
],
),
migrations
.
CreateModel
(
name
=
'Selling'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
verbose_name
=
'ID'
,
primary_key
=
True
,
serialize
=
False
,
auto_created
=
True
)),
(
'unit_price'
,
accounting
.
models
.
CurrencyField
(
verbose_name
=
'unit price'
,
decimal_places
=
2
,
max_digits
=
12
)),
(
'quantity'
,
models
.
IntegerField
(
verbose_name
=
'quantity'
)),
(
'date'
,
models
.
DateTimeField
(
verbose_name
=
'date'
,
auto_now
=
True
)),
(
'counter'
,
models
.
ForeignKey
(
to
=
'counter.Counter'
,
related_name
=
'sellings'
)),
(
'customer'
,
models
.
ForeignKey
(
to
=
'counter.Customer'
,
related_name
=
'customers'
)),
(
'product'
,
models
.
ForeignKey
(
to
=
'counter.Product'
,
related_name
=
'sellings'
)),
(
'seller'
,
models
.
ForeignKey
(
to
=
settings
.
AUTH_USER_MODEL
,
related_name
=
'sellers'
)),
],
),
]
counter/migrations/0003_customer_amount.py
0 → 100644
View file @
6c48b7c7
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
import
accounting.models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'counter'
,
'0002_refilling_selling'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'customer'
,
name
=
'amount'
,
field
=
accounting
.
models
.
CurrencyField
(
verbose_name
=
'amount'
,
default
=
0
,
decimal_places
=
2
,
max_digits
=
12
),
preserve_default
=
False
,
),
]
counter/models.py
View file @
6c48b7c7
...
...
@@ -18,6 +18,7 @@ class Customer(models.Model):
"""
user
=
models
.
OneToOneField
(
User
,
primary_key
=
True
)
account_id
=
models
.
CharField
(
_
(
'account id'
),
max_length
=
10
,
unique
=
True
)
amount
=
CurrencyField
(
_
(
'amount'
))
class
Meta
:
verbose_name
=
_
(
'customer'
)
...
...
@@ -108,9 +109,64 @@ class Counter(models.Model):
Counter
.
barmen_session
[
counter_id
][
'users'
]
=
set
()
return
bl
def
get_random_barman
(
counter_id
):
# TODO: improve this function
bl
=
Counter
.
get_barmen_list
(
counter_id
)
return
bl
[
0
]
class
Refilling
(
models
.
Model
):
"""
Handle the refilling
"""
counter
=
models
.
ForeignKey
(
Counter
,
related_name
=
"refillings"
,
blank
=
False
)
amount
=
CurrencyField
(
_
(
'amount'
))
operator
=
models
.
ForeignKey
(
User
,
related_name
=
"refill_operators"
,
blank
=
False
)
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
def
__str__
(
self
):
return
"Refilling: %f for %s"
%
(
self
.
amount
,
self
.
customer
.
user
.
get_display_name
())
# def get_absolute_url(self):
# return reverse('counter:details', kwargs={'counter_id': self.id})
def
save
(
self
,
*
args
,
**
kwargs
):
self
.
full_clean
()
self
.
customer
.
amount
+=
self
.
quantity
*
self
.
unit_price
self
.
customer
.
save
()
super
(
Selling
,
self
).
save
(
*
args
,
**
kwargs
)
class
Selling
(
models
.
Model
):
"""
Handle the sellings
"""
product
=
models
.
ForeignKey
(
Product
,
related_name
=
"sellings"
,
blank
=
False
)
counter
=
models
.
ForeignKey
(
Counter
,
related_name
=
"sellings"
,
blank
=
False
)
unit_price
=
CurrencyField
(
_
(
'unit price'
))
quantity
=
models
.
IntegerField
(
_
(
'quantity'
))
seller
=
models
.
ForeignKey
(
User
,
related_name
=
"sellers"
,
blank
=
False
)
customer
=
models
.
ForeignKey
(
Customer
,
related_name
=
"customers"
,
blank
=
False
)
date
=
models
.
DateTimeField
(
_
(
'date'
),
auto_now
=
True
)
def
__str__
(
self
):
return
"Selling: %d x %s (%f) for %s"
%
(
self
.
quantity
,
self
.
product
.
name
,
self
.
quantity
*
self
.
unit_price
,
self
.
customer
.
user
.
get_display_name
())
def
save
(
self
,
*
args
,
**
kwargs
):
self
.
full_clean
()
self
.
customer
.
amount
-=
self
.
quantity
*
self
.
unit_price
self
.
customer
.
save
()
super
(
Selling
,
self
).
save
(
*
args
,
**
kwargs
)
# def get_absolute_url(self):
# return reverse('counter:details', kwargs={'counter_id': self.id})
# TODO:
# une classe Vente
# foreign key vers comptoir, vendeur, client, produit, mais stocker le prix du produit, pour gerer les maj de prix
# une classe Rechargement
# foreign key vers comptoir, vendeur, client, plus montant
counter/views.py
View file @
6c48b7c7
...
...
@@ -12,7 +12,7 @@ from django import forms
from
core.views
import
CanViewMixin
,
CanEditMixin
,
CanEditPropMixin
from
subscription.models
import
Subscriber
from
counter.models
import
Counter
,
Customer
,
Product
from
counter.models
import
Counter
,
Customer
,
Product
,
Selling
,
Refilling
class
GetUserForm
(
forms
.
Form
):
"""
...
...
@@ -151,7 +151,11 @@ class CounterClick(DetailView):
def
finish
(
self
,
request
):
""" Finish the click session, and validate the basket """
# TODO: handle the 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
)
s
.
save
()
kwargs
=
{
'counter_id'
:
self
.
object
.
id
}
del
request
.
session
[
'basket'
]
return
HttpResponseRedirect
(
reverse_lazy
(
'counter:details'
,
args
=
self
.
args
,
kwargs
=
kwargs
))
...
...
sith/settings.py
View file @
6c48b7c7
...
...
@@ -218,6 +218,11 @@ SITH_SUBSCRIPTION_PAYMENT_METHOD = [
(
'other'
,
'Autre'
),
]
SITH_COUNTER_PAYMENT_METHOD
=
[
(
'cheque'
,
'Chèque'
),
(
'cash'
,
'Espèce'
),
]
# 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