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
7d40e111
Verified
Commit
7d40e111
authored
Nov 27, 2019
by
Sli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
club: ClubSellingView way faster and with multiple selections everywhere
parent
af48553e
Pipeline
#2154
passed with stage
in 59 minutes and 3 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
17 deletions
+25
-17
club/forms.py
club/forms.py
+5
-5
club/views.py
club/views.py
+20
-12
No files found.
club/forms.py
View file @
7d40e111
...
...
@@ -170,21 +170,21 @@ class SellingsForm(forms.Form):
required
=
False
,
widget
=
SelectDateTime
,
)
counter
=
forms
.
ModelChoiceField
(
counter
s
=
forms
.
Model
Multiple
ChoiceField
(
Counter
.
objects
.
order_by
(
"name"
).
all
(),
label
=
_
(
"Counter"
),
required
=
False
)
def
__init__
(
self
,
club
,
*
args
,
**
kwargs
):
super
(
SellingsForm
,
self
).
__init__
(
*
args
,
**
kwargs
)
self
.
fields
[
"product"
]
=
forms
.
ModelChoiceField
(
self
.
fields
[
"product
s
"
]
=
forms
.
Model
Multiple
ChoiceField
(
club
.
products
.
order_by
(
"name"
).
filter
(
archived
=
False
).
all
(),
label
=
_
(
"Product"
),
label
=
_
(
"Product
s
"
),
required
=
False
,
)
self
.
fields
[
"archived_product"
]
=
forms
.
ModelChoiceField
(
self
.
fields
[
"archived_product
s
"
]
=
forms
.
Model
Multiple
ChoiceField
(
club
.
products
.
order_by
(
"name"
).
filter
(
archived
=
True
).
all
(),
label
=
_
(
"Archived product"
),
label
=
_
(
"Archived product
s
"
),
required
=
False
,
)
...
...
club/views.py
View file @
7d40e111
...
...
@@ -355,21 +355,29 @@ class ClubSellingView(ClubTabsMixin, CanEditMixin, DetailFormView):
qs
=
qs
.
filter
(
date__gte
=
form
.
cleaned_data
[
"begin_date"
])
if
form
.
cleaned_data
[
"end_date"
]:
qs
=
qs
.
filter
(
date__lte
=
form
.
cleaned_data
[
"end_date"
])
if
form
.
cleaned_data
[
"counter"
]:
qs
=
qs
.
filter
(
counter
=
form
.
cleaned_data
[
"counter"
])
if
form
.
cleaned_data
[
"counters"
]:
qs
=
qs
.
filter
(
counter__in
=
form
.
cleaned_data
[
"counters"
])
selected_products
=
[]
if
form
.
cleaned_data
[
"product"
]:
selected_products
.
append
(
form
.
cleaned_data
[
"product"
].
id
)
if
form
.
cleaned_data
[
"archived_product"
]:
selected_products
.
append
(
form
.
cleaned_data
[
"selected_products"
].
id
)
if
form
.
cleaned_data
[
"products"
]:
selected_products
.
extend
(
form
.
cleaned_data
[
"products"
])
if
form
.
cleaned_data
[
"archived_products"
]:
selected_products
.
extend
(
form
.
cleaned_data
[
"selected_products"
])
print
(
selected_products
)
if
len
(
selected_products
)
>
0
:
qs
=
qs
.
filter
(
product__id__in
=
selected_products
)
qs
=
qs
.
filter
(
product__in
=
selected_products
)
kwargs
[
"result"
]
=
qs
.
all
().
order_by
(
"-id"
)
kwargs
[
"total"
]
=
sum
([
s
.
quantity
*
s
.
unit_price
for
s
in
qs
.
all
()])
kwargs
[
"total_quantity"
]
=
sum
([
s
.
quantity
for
s
in
qs
.
all
()])
kwargs
[
"benefit"
]
=
kwargs
[
"total"
]
-
sum
(
[
s
.
product
.
purchase_price
for
s
in
qs
.
exclude
(
product
=
None
)]
)
for
selling
in
kwargs
[
"result"
]:
kwargs
[
"total"
]
+=
selling
.
quantity
*
selling
.
unit_price
kwargs
[
"total_quantity"
]
+=
selling
.
quantity
if
hasattr
(
selling
,
"product"
):
kwargs
[
"benefit"
]
+=
selling
.
product
.
purchase_price
kwargs
[
"benefit"
]
=
kwargs
[
"total"
]
-
kwargs
[
"benefit"
]
return
kwargs
...
...
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