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
240b68f9
Commit
240b68f9
authored
Aug 14, 2017
by
Sli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow negative amount for customer
parent
d60e14a3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
5 deletions
+6
-5
counter/migrations/0013_customer_recorded_products.py
counter/migrations/0013_customer_recorded_products.py
+2
-1
counter/models.py
counter/models.py
+4
-4
No files found.
counter/migrations/0013_customer_recorded_products.py
View file @
240b68f9
...
...
@@ -11,6 +11,7 @@ from counter.models import Customer, Product, Selling, Counter
def
balance_ecocups
(
apps
,
schema_editor
):
for
customer
in
Customer
.
objects
.
all
():
customer
.
recorded_products
=
0
for
selling
in
customer
.
buyings
.
filter
(
product__id__in
=
[
settings
.
SITH_RECORD_PRODUCT
,
settings
.
SITH_UNRECORD_PRODUCT
]).
all
():
if
selling
.
product
.
id
==
settings
.
SITH_RECORD_PRODUCT
:
customer
.
recorded_products
-=
selling
.
quantity
...
...
@@ -21,7 +22,7 @@ def balance_ecocups(apps, schema_editor):
cons
=
Product
.
objects
.
get
(
id
=
settings
.
SITH_RECORD_PRODUCT
)
Selling
(
label
=
_
(
"Record regularization"
),
product
=
cons
,
unit_price
=
cons
.
selling_price
,
club
=
cons
.
club
,
counter
=
Counter
.
objects
.
filter
(
name
=
'Foyer'
).
first
(),
quantity
=
qt
,
seller
=
User
.
objects
.
get
(
id
=
0
),
customer
=
customer
).
save
()
quantity
=
qt
,
seller
=
User
.
objects
.
get
(
id
=
0
),
customer
=
customer
).
save
(
allow_negative
=
True
)
customer
.
recorded_products
-=
qt
customer
.
save
()
...
...
counter/models.py
View file @
240b68f9
...
...
@@ -80,8 +80,8 @@ class Customer(models.Model):
letter
=
random
.
choice
(
string
.
ascii_lowercase
)
return
number
+
letter
def
save
(
self
,
*
args
,
**
kwargs
):
if
self
.
amount
<
0
:
def
save
(
self
,
allow_negative
=
False
,
is_purchase
=
False
,
*
args
,
**
kwargs
):
if
self
.
amount
<
0
and
(
is_purchase
and
not
allow_negative
)
:
raise
ValidationError
(
_
(
"Not enough money"
))
super
(
Customer
,
self
).
save
(
*
args
,
**
kwargs
)
...
...
@@ -392,13 +392,13 @@ class Selling(models.Model):
html_message
=
message_html
)
def
save
(
self
,
*
args
,
**
kwargs
):
def
save
(
self
,
allow_negative
=
False
,
*
args
,
**
kwargs
):
if
not
self
.
date
:
self
.
date
=
timezone
.
now
()
self
.
full_clean
()
if
not
self
.
is_validated
:
self
.
customer
.
amount
-=
self
.
quantity
*
self
.
unit_price
self
.
customer
.
save
()
self
.
customer
.
save
(
allow_negative
=
allow_negative
,
is_purchase
=
True
)
self
.
is_validated
=
True
u
=
User
.
objects
.
filter
(
id
=
self
.
customer
.
user
.
id
).
first
()
if
u
.
was_subscribed
:
...
...
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