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 / Register
Toggle navigation
Open sidebar
chris
repanier
Commits
46ae4c08
Commit
46ae4c08
authored
Dec 03, 2016
by
Patrick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Django 1.9.11, CMS 3.4.1
parent
3e4798c3
Changes
119
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
75 changed files
with
19664 additions
and
13823 deletions
+19664
-13823
doc/REPANIER - Gestion - 2.pdf
doc/REPANIER - Gestion - 2.pdf
+0
-0
mysite/common_settings.py
mysite/common_settings.py
+352
-130
mysite/urls.py
mysite/urls.py
+5
-11
repanier/admin.py
repanier/admin.py
+0
-2582
repanier/admin/__init__.py
repanier/admin/__init__.py
+48
-0
repanier/admin/admin_filter.py
repanier/admin/admin_filter.py
+88
-72
repanier/admin/bankaccount.py
repanier/admin/bankaccount.py
+308
-0
repanier/admin/box.py
repanier/admin/box.py
+287
-0
repanier/admin/configuration.py
repanier/admin/configuration.py
+121
-0
repanier/admin/customer.py
repanier/admin/customer.py
+417
-0
repanier/admin/fkey_choice_cache_mixin.py
repanier/admin/fkey_choice_cache_mixin.py
+3
-2
repanier/admin/forms.py
repanier/admin/forms.py
+87
-0
repanier/admin/lut.py
repanier/admin/lut.py
+166
-0
repanier/admin/offeritem.py
repanier/admin/offeritem.py
+162
-0
repanier/admin/permanence_done.py
repanier/admin/permanence_done.py
+501
-0
repanier/admin/permanence_in_preparation.py
repanier/admin/permanence_in_preparation.py
+908
-0
repanier/admin/producer.py
repanier/admin/producer.py
+320
-0
repanier/admin/product.py
repanier/admin/product.py
+541
-0
repanier/admin/purchase.py
repanier/admin/purchase.py
+508
-0
repanier/admin/rule_of_3_per_customer.py
repanier/admin/rule_of_3_per_customer.py
+280
-0
repanier/admin/rule_of_3_per_product.py
repanier/admin/rule_of_3_per_product.py
+440
-0
repanier/admin/staff.py
repanier/admin/staff.py
+174
-0
repanier/apps.py
repanier/apps.py
+122
-41
repanier/auth_backend.py
repanier/auth_backend.py
+37
-36
repanier/cms_menus.py
repanier/cms_menus.py
+188
-201
repanier/cms_toolbar.py
repanier/cms_toolbar.py
+26
-16
repanier/const.py
repanier/const.py
+106
-22
repanier/email/email_alert.py
repanier/email/email_alert.py
+0
-60
repanier/email/email_invoice.py
repanier/email/email_invoice.py
+102
-101
repanier/email/email_offer.py
repanier/email/email_offer.py
+113
-75
repanier/email/email_order.py
repanier/email/email_order.py
+258
-140
repanier/locale/fr/LC_MESSAGES/django.mo
repanier/locale/fr/LC_MESSAGES/django.mo
+0
-0
repanier/locale/fr/LC_MESSAGES/django.po
repanier/locale/fr/LC_MESSAGES/django.po
+4325
-2448
repanier/locale/nl/LC_MESSAGES/django.mo
repanier/locale/nl/LC_MESSAGES/django.mo
+0
-0
repanier/locale/nl/LC_MESSAGES/django.po
repanier/locale/nl/LC_MESSAGES/django.po
+3290
-1602
repanier/management/commands/backup_db.py
repanier/management/commands/backup_db.py
+25
-14
repanier/management/commands/recalculate_order_amount.py
repanier/management/commands/recalculate_order_amount.py
+175
-10
repanier/models.py
repanier/models.py
+0
-2496
repanier/picture/fields.py
repanier/picture/fields.py
+8
-13
repanier/picture/forms.py
repanier/picture/forms.py
+1
-1
repanier/picture/views.py
repanier/picture/views.py
+5
-5
repanier/picture/widgets.py
repanier/picture/widgets.py
+14
-9
repanier/static/bootstrap/css/bootstrap.css
repanier/static/bootstrap/css/bootstrap.css
+877
-400
repanier/static/bootstrap/css/custom.css
repanier/static/bootstrap/css/custom.css
+28
-26
repanier/static/bootstrap/css/variableswatch.less
repanier/static/bootstrap/css/variableswatch.less
+59
-36
repanier/static/bootstrap/fonts/glyphicons-halflings-regular.woff2
...static/bootstrap/fonts/glyphicons-halflings-regular.woff2
+0
-0
repanier/static/bootstrap/js/bootstrap.js
repanier/static/bootstrap/js/bootstrap.js
+831
-419
repanier/static/bootstrap/js/bootstrap.min.js
repanier/static/bootstrap/js/bootstrap.min.js
+5
-4
repanier/static/js/export_import_stock.js
repanier/static/js/export_import_stock.js
+9
-0
repanier/static/js/is_order_confirm_send.js
repanier/static/js/is_order_confirm_send.js
+8
-0
repanier/task/task_box.py
repanier/task/task_box.py
+49
-0
repanier/task/task_invoice.py
repanier/task/task_invoice.py
+572
-495
repanier/task/task_order.py
repanier/task/task_order.py
+559
-332
repanier/task/task_producer.py
repanier/task/task_producer.py
+135
-55
repanier/task/task_product.py
repanier/task/task_product.py
+7
-7
repanier/task/task_purchase.py
repanier/task/task_purchase.py
+12
-14
repanier/templates/403.html
repanier/templates/403.html
+5
-0
repanier/templates/404.html
repanier/templates/404.html
+5
-1
repanier/templates/500.html
repanier/templates/500.html
+12
-1
repanier/templates/base.html
repanier/templates/base.html
+55
-40
repanier/templates/base_wo_cms_toolbar.html
repanier/templates/base_wo_cms_toolbar.html
+0
-126
repanier/templates/cms_bootstrap_page.html
repanier/templates/cms_bootstrap_page.html
+6
-0
repanier/templates/cms_bootstrap_subpage.html
repanier/templates/cms_bootstrap_subpage.html
+3
-3
repanier/templates/cms_home.html
repanier/templates/cms_home.html
+3
-3
repanier/templates/cms_page.html
repanier/templates/cms_page.html
+3
-1
repanier/templates/cms_subpage.html
repanier/templates/cms_subpage.html
+26
-5
repanier/templatetags/repanier_tags.py
repanier/templatetags/repanier_tags.py
+91
-39
repanier/tools.py
repanier/tools.py
+1429
-362
repanier/urls.py
repanier/urls.py
+110
-41
repanier/views.py
repanier/views.py
+0
-1326
repanier/views/__init__.py
repanier/views/__init__.py
+0
-0
repanier/views/basket_message_form_ajax.py
repanier/views/basket_message_form_ajax.py
+35
-0
repanier/views/btn_confirm_order_ajax.py
repanier/views/btn_confirm_order_ajax.py
+82
-0
repanier/views/customer_invoice_class.py
repanier/views/customer_invoice_class.py
+116
-0
repanier/views/customer_name_ajax.py
repanier/views/customer_name_ajax.py
+21
-0
No files found.
doc/REPANIER - Gestion - 2.pdf
0 → 100644
View file @
46ae4c08
File added
mysite/common_settings.py
View file @
46ae4c08
This diff is collapsed.
Click to expand it.
mysite/urls.py
View file @
46ae4c08
from
django.conf.urls
import
patterns
,
include
,
url
from
django.conf.urls
import
include
,
url
from
django.conf.urls.i18n
import
i18n_patterns
from
django.conf.urls.i18n
import
i18n_patterns
from
django.conf
import
settings
from
django.contrib
import
admin
from
django.contrib
import
admin
from
django.contrib
import
auth
from
django.contrib.staticfiles.urls
import
staticfiles_urlpatterns
from
django.contrib.staticfiles.urls
import
staticfiles_urlpatterns
from
django.contrib.sitemaps.views
import
sitemap
from
cms.sitemaps
import
CMSSitemap
from
cms.sitemaps
import
CMSSitemap
# admin.autodiscover
# admin.autodiscover
# urlpatterns = patterns('',
urlpatterns
=
i18n_patterns
(
# url(r'^jsi18n/(?P<packages>\S+?)/$', 'django.views.i18n.javascript_catalog'),
# )
urlpatterns
=
i18n_patterns
(
''
,
url
(
r
'^repanier/'
,
include
(
'repanier.urls'
)),
url
(
r
'^repanier/'
,
include
(
'repanier.urls'
)),
url
(
r
'^coordi/'
,
include
(
admin
.
site
.
urls
)),
url
(
r
'^coordi/'
,
include
(
admin
.
site
.
urls
)),
url
(
r
'^sitemap\.xml$'
,
'django.contrib.sitemaps.views.sitemap'
,
{
'sitemaps'
:
{
'cmspages'
:
CMSSitemap
}}),
# url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': {'cmspages': CMSSitemap}}),
# url(r'^', include('filer.server.urls')),
url
(
r
'^sitemap\.xml$'
,
sitemap
,
{
'sitemaps'
:
{
'cmspages'
:
CMSSitemap
}},
name
=
'django.contrib.sitemaps.views.sitemap'
),
# url(r'^', include('password_reset.urls')),
url
(
r
'^'
,
include
(
'cms.urls'
)),
url
(
r
'^'
,
include
(
'cms.urls'
)),
)
)
...
...
repanier/admin.py
deleted
100644 → 0
View file @
3e4798c3
This diff is collapsed.
Click to expand it.
repanier/admin/__init__.py
0 → 100644
View file @
46ae4c08
# -*- coding: utf-8
from
django.contrib
import
admin
from
repanier.models
import
BankAccount
from
bankaccount
import
BankAccountAdmin
admin
.
site
.
register
(
BankAccount
,
BankAccountAdmin
)
from
repanier.models
import
Configuration
from
configuration
import
ConfigurationAdmin
admin
.
site
.
register
(
Configuration
,
ConfigurationAdmin
)
from
repanier.models
import
Customer
from
customer
import
CustomerWithUserDataAdmin
admin
.
site
.
register
(
Customer
,
CustomerWithUserDataAdmin
)
from
repanier.models
import
Purchase
from
purchase
import
PurchaseAdmin
admin
.
site
.
register
(
Purchase
,
PurchaseAdmin
)
from
repanier.models
import
LUT_ProductionMode
,
LUT_DeliveryPoint
,
LUT_DepartmentForCustomer
,
LUT_PermanenceRole
from
lut
import
LUTProductionModeAdmin
,
LUTPermanenceRoleAdmin
,
LUTDepartmentForCustomerAdmin
,
LUTDeliveryPointAdmin
admin
.
site
.
register
(
LUT_ProductionMode
,
LUTProductionModeAdmin
)
admin
.
site
.
register
(
LUT_PermanenceRole
,
LUTPermanenceRoleAdmin
)
admin
.
site
.
register
(
LUT_DepartmentForCustomer
,
LUTDepartmentForCustomerAdmin
)
admin
.
site
.
register
(
LUT_DeliveryPoint
,
LUTDeliveryPointAdmin
)
from
repanier.models
import
OfferItemClosed
from
offeritem
import
OfferItemClosedAdmin
admin
.
site
.
register
(
OfferItemClosed
,
OfferItemClosedAdmin
)
from
repanier.models
import
OfferItemSend
from
rule_of_3_per_product
import
OfferItemSendAdmin
admin
.
site
.
register
(
OfferItemSend
,
OfferItemSendAdmin
)
from
repanier.models
import
CustomerSend
from
rule_of_3_per_customer
import
CustomerSendAdmin
admin
.
site
.
register
(
CustomerSend
,
CustomerSendAdmin
)
from
repanier.models
import
PermanenceInPreparation
from
permanence_in_preparation
import
PermanenceInPreparationAdmin
admin
.
site
.
register
(
PermanenceInPreparation
,
PermanenceInPreparationAdmin
)
from
repanier.models
import
PermanenceDone
from
permanence_done
import
PermanenceDoneAdmin
admin
.
site
.
register
(
PermanenceDone
,
PermanenceDoneAdmin
)
from
repanier.models
import
Producer
from
producer
import
ProducerAdmin
admin
.
site
.
register
(
Producer
,
ProducerAdmin
)
from
repanier.models
import
Product
from
product
import
ProductAdmin
admin
.
site
.
register
(
Product
,
ProductAdmin
)
from
repanier.models.box
import
Box
from
box
import
BoxAdmin
admin
.
site
.
register
(
Box
,
BoxAdmin
)
from
repanier.models
import
Staff
from
staff
import
StaffWithUserDataAdmin
admin
.
site
.
register
(
Staff
,
StaffWithUserDataAdmin
)
repanier/admin_filter.py
→
repanier/admin
/admin
_filter.py
View file @
46ae4c08
# -*- coding: utf-8
# -*- coding: utf-8
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
from
django.conf
import
settings
from
django.db.models
import
Q
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils
import
timezone
from
const
import
*
from
models
import
Customer
from
models
import
LUT_DepartmentForCustomer
from
models
import
Permanence
from
models
import
Producer
from
models
import
Product
from
repanier.const
import
*
# Filters in the right sidebar of the change list page of the admin
# Filters in the right sidebar of the change list page of the admin
from
django.contrib.admin
import
SimpleListFilter
from
django.contrib.admin
import
SimpleListFilter
from
tools
import
sint
from
repanier.models
import
Producer
,
Product
,
LUT_DepartmentForCustomer
,
Customer
,
CustomerInvoice
,
ProducerInvoice
,
\
Permanence
from
repanier.tools
import
sint
class
ProductFilterByProducer
(
SimpleListFilter
):
class
ProductFilterByProducer
(
SimpleListFilter
):
...
@@ -21,6 +19,7 @@ class ProductFilterByProducer(SimpleListFilter):
...
@@ -21,6 +19,7 @@ class ProductFilterByProducer(SimpleListFilter):
title
=
_
(
"producers"
)
title
=
_
(
"producers"
)
# Parameter for the filter that will be used in the URL query.
# Parameter for the filter that will be used in the URL query.
parameter_name
=
'producer'
parameter_name
=
'producer'
template
=
'admin/producer_filter.html'
def
lookups
(
self
,
request
,
model_admin
):
def
lookups
(
self
,
request
,
model_admin
):
"""
"""
...
@@ -33,7 +32,7 @@ class ProductFilterByProducer(SimpleListFilter):
...
@@ -33,7 +32,7 @@ class ProductFilterByProducer(SimpleListFilter):
# This list is a collection of producer.id, .name
# This list is a collection of producer.id, .name
return
[(
c
.
id
,
c
.
short_profile_name
)
for
c
in
return
[(
c
.
id
,
c
.
short_profile_name
)
for
c
in
Producer
.
objects
.
filter
(
is_active
=
True
)
Producer
.
objects
.
filter
(
is_active
=
True
)
]
]
def
queryset
(
self
,
request
,
queryset
):
def
queryset
(
self
,
request
,
queryset
):
"""
"""
...
@@ -51,6 +50,7 @@ class ProductFilterByProducer(SimpleListFilter):
...
@@ -51,6 +50,7 @@ class ProductFilterByProducer(SimpleListFilter):
class
ProductFilterByDepartmentForThisProducer
(
SimpleListFilter
):
class
ProductFilterByDepartmentForThisProducer
(
SimpleListFilter
):
title
=
_
(
"departments for customer"
)
title
=
_
(
"departments for customer"
)
parameter_name
=
'department_for_customer'
parameter_name
=
'department_for_customer'
template
=
'admin/department_filter.html'
def
lookups
(
self
,
request
,
model_admin
):
def
lookups
(
self
,
request
,
model_admin
):
producer_id
=
request
.
GET
.
get
(
'producer'
)
producer_id
=
request
.
GET
.
get
(
'producer'
)
...
@@ -66,42 +66,39 @@ class ProductFilterByDepartmentForThisProducer(SimpleListFilter):
...
@@ -66,42 +66,39 @@ class ProductFilterByDepartmentForThisProducer(SimpleListFilter):
inner_qs
=
Product
.
objects
.
filter
(
is_active
=
True
).
order_by
().
distinct
(
inner_qs
=
Product
.
objects
.
filter
(
is_active
=
True
).
order_by
().
distinct
(
'department_for_customer__id'
)
'department_for_customer__id'
)
return
[(
c
.
id
,
c
.
short_name
)
for
c
in
return
[(
d
.
id
,
d
.
short_name
)
for
d
in
LUT_DepartmentForCustomer
.
objects
.
filter
(
is_active
=
True
,
product__in
=
inner_qs
)
LUT_DepartmentForCustomer
.
objects
.
filter
(
is_active
=
True
,
product__in
=
inner_qs
)
]
]
def
queryset
(
self
,
request
,
queryset
):
def
queryset
(
self
,
request
,
queryset
):
# This query set is a collection of products
if
self
.
value
():
if
self
.
value
():
return
queryset
.
filter
(
department_for_customer_id
=
self
.
value
())
return
queryset
.
filter
(
department_for_customer_id
=
self
.
value
())
else
:
else
:
return
queryset
return
queryset
class
PurchaseFilterByCustomer
ForThisPermanence
(
SimpleListFilter
):
class
PurchaseFilterByCustomer
(
SimpleListFilter
):
title
=
_
(
"customer"
)
title
=
_
(
"customer"
)
parameter_name
=
'customer'
parameter_name
=
'customer'
template
=
'admin/customer_filter.html'
def
lookups
(
self
,
request
,
model_admin
):
def
lookups
(
self
,
request
,
model_admin
):
permanence_id
=
request
.
GET
.
get
(
'permanence'
)
permanence_id
=
request
.
GET
.
get
(
'permanence'
,
None
)
if
permanence_id
:
list_filter
=
[]
permanence_id
=
sint
(
permanence_id
,
0
)
for
c
in
Customer
.
objects
.
filter
(
may_order
=
True
):
if
permanence_id
>=
0
:
ci
=
CustomerInvoice
.
objects
.
filter
(
permanence
=
permanence_id
,
customer_id
=
c
.
id
).
order_by
(
'?'
).
only
(
return
[(
c
.
id
,
c
.
short_basket_name
)
for
c
in
'total_price_with_tax'
,
'is_order_confirm_send'
).
first
()
Customer
.
objects
.
filter
(
purchase__permanence_id
=
permanence_id
).
distinct
()
if
ci
is
not
None
:
]
if
ci
.
is_order_confirm_send
:
list_filter
.
append
(
(
c
.
id
,
"%s (%s) %s"
%
(
c
.
short_basket_name
,
ci
.
get_total_price_with_tax
(),
LOCK_UNICODE
)))
else
:
list_filter
.
append
((
c
.
id
,
"%s (%s)"
%
(
c
.
short_basket_name
,
ci
.
total_price_with_tax
,)))
else
:
else
:
# This is a year
list_filter
.
append
((
c
.
id
,
c
.
short_basket_name
))
return
[(
c
.
id
,
c
.
short_basket_name
)
for
c
in
return
list_filter
Customer
.
objects
.
filter
(
purchase__permanence_date__year
=-
permanence_id
).
distinct
()
]
else
:
return
[(
c
.
id
,
c
.
short_basket_name
)
for
c
in
Customer
.
objects
.
filter
(
may_order
=
True
)
]
def
queryset
(
self
,
request
,
queryset
):
def
queryset
(
self
,
request
,
queryset
):
# This query set is a collection of purchase
if
self
.
value
():
if
self
.
value
():
return
queryset
.
filter
(
customer_id
=
self
.
value
())
return
queryset
.
filter
(
customer_id
=
self
.
value
())
else
:
else
:
...
@@ -111,27 +108,24 @@ class PurchaseFilterByCustomerForThisPermanence(SimpleListFilter):
...
@@ -111,27 +108,24 @@ class PurchaseFilterByCustomerForThisPermanence(SimpleListFilter):
class
PurchaseFilterByProducerForThisPermanence
(
SimpleListFilter
):
class
PurchaseFilterByProducerForThisPermanence
(
SimpleListFilter
):
title
=
_
(
"producer"
)
title
=
_
(
"producer"
)
parameter_name
=
'producer'
parameter_name
=
'producer'
template
=
'admin/producer_filter.html'
def
lookups
(
self
,
request
,
model_admin
):
def
lookups
(
self
,
request
,
model_admin
):
permanence_id
=
request
.
GET
.
get
(
'permanence'
)
permanence_id
=
request
.
GET
.
get
(
'permanence'
,
None
)
if
permanence_id
:
if
permanence_id
is
not
None
:
permanence_id
=
sint
(
permanence_id
,
0
)
list_filter
=
[]
if
permanence_id
>=
0
:
for
p
in
Producer
.
objects
.
filter
(
permanence
=
permanence_id
):
return
[(
c
.
id
,
c
.
short_profile_name
)
for
c
in
pi
=
ProducerInvoice
.
objects
.
filter
(
permanence
=
permanence_id
,
producer_id
=
p
.
id
).
order_by
(
'?'
).
only
(
Producer
.
objects
.
filter
(
permanence
=
permanence_id
).
distinct
()
'total_price_with_tax'
).
first
()
]
if
pi
is
not
None
:
else
:
list_filter
.
append
((
p
.
id
,
"%s (%s)"
%
(
p
.
short_profile_name
,
pi
.
total_price_with_tax
,)))
# This is a year
else
:
return
[(
c
.
id
,
c
.
short_profile_name
)
for
c
in
list_filter
.
append
((
p
.
id
,
p
.
short_profile_name
))
Producer
.
objects
.
filter
(
permanence__permanence_date__year
=-
permanence_id
).
distinct
()
return
list_filter
]
else
:
else
:
return
[(
c
.
id
,
c
.
short_profile_name
)
for
c
in
return
[]
Producer
.
objects
.
filter
(
is_active
=
True
)
]
def
queryset
(
self
,
request
,
queryset
):
def
queryset
(
self
,
request
,
queryset
):
# This query set is a collection of purchase
if
self
.
value
():
if
self
.
value
():
return
queryset
.
filter
(
producer_id
=
self
.
value
())
return
queryset
.
filter
(
producer_id
=
self
.
value
())
else
:
else
:
...
@@ -143,28 +137,39 @@ class PurchaseFilterByPermanence(SimpleListFilter):
...
@@ -143,28 +137,39 @@ class PurchaseFilterByPermanence(SimpleListFilter):
parameter_name
=
'permanence'
parameter_name
=
'permanence'
def
lookups
(
self
,
request
,
model_admin
):
def
lookups
(
self
,
request
,
model_admin
):
# This list is a collection of permanence.id, .name
permanence_id
=
request
.
GET
.
get
(
'permanence'
,
None
)
if
PERMANENCE_DONE
in
model_admin
.
permanence_status_list
\
if
permanence_id
is
None
:
or
PERMANENCE_ARCHIVED
in
model_admin
.
permanence_status_list
:
return
[(
p
.
id
,
p
.
get_permanence_display
(
with_status
=
False
))
for
p
in
this_year
=
timezone
.
now
().
year
Permanence
.
objects
.
filter
(
status__in
=
[
PERMANENCE_OPENED
,
PERMANENCE_CLOSED
,
PERMANENCE_SEND
])
return
[
]
(
-
(
this_year
-
i
),
str
(
this_year
-
i
))
for
i
in
xrange
(
10
)
]
else
:
else
:
return
[(
c
.
id
,
c
.
__str__
())
for
c
in
return
[]
Permanence
.
objects
.
filter
(
status__in
=
model_admin
.
permanence_status_list
)
]
def
queryset
(
self
,
request
,
queryset
):
def
queryset
(
self
,
request
,
queryset
):
# This query set is a collection of purchase
if
self
.
value
():
if
self
.
value
():
permanence_id
=
sint
(
self
.
value
(),
0
)
permanence_id
=
sint
(
self
.
value
(),
0
)
if
permanence_id
>=
0
:
if
permanence_id
>
0
:
return
queryset
.
filter
(
permanence_id
=
permanence_id
)
return
queryset
class
OfferItemSendFilterByPermanence
(
SimpleListFilter
):
title
=
_
(
"permanence"
)
parameter_name
=
'permanence'
def
lookups
(
self
,
request
,
model_admin
):
return
[(
p
.
id
,
p
.
get_permanence_display
(
with_status
=
False
))
for
p
in
Permanence
.
objects
.
filter
(
status
=
PERMANENCE_SEND
)
]
def
queryset
(
self
,
request
,
queryset
):
if
self
.
value
():
permanence_id
=
sint
(
self
.
value
(),
0
)
if
permanence_id
>
0
:
return
queryset
.
filter
(
permanence_id
=
permanence_id
)
return
queryset
.
filter
(
permanence_id
=
permanence_id
)
else
:
return
queryset
.
filter
(
permanence_date__year
=-
permanence_id
)
else
:
else
:
return
queryset
return
queryset
.
filter
(
permanence__status
=
PERMANENCE_SEND
)
return
queryset
class
OfferItemFilter
(
SimpleListFilter
):
class
OfferItemFilter
(
SimpleListFilter
):
...
@@ -172,27 +177,38 @@ class OfferItemFilter(SimpleListFilter):
...
@@ -172,27 +177,38 @@ class OfferItemFilter(SimpleListFilter):
parameter_name
=
'is_filled_exact'
parameter_name
=
'is_filled_exact'
def
lookups
(
self
,
request
,
model_admin
):
def
lookups
(
self
,
request
,
model_admin
):
# This list is a collection of offer_item.id, .name
return
[(
1
,
_
(
'only invoiced'
)),
]
return
[(
1
,
_
(
'only invoiced'
)),]
def
queryset
(
self
,
request
,
queryset
):
def
queryset
(
self
,
request
,
queryset
):
# This query set is a collection of offer_item
if
self
.
value
():
if
self
.
value
():
return
queryset
.
exclude
(
quantity_invoiced
=
DECIMAL_ZERO
)
return
queryset
.
exclude
(
quantity_invoiced
=
DECIMAL_ZERO
)
else
:
else
:
return
queryset
return
queryset
class
BankAccountFilterByPermanence
(
SimpleListFilter
):
title
=
_
(
"permanence"
)
class
BankAccountFilterByStatus
(
SimpleListFilter
):
title
=
_
(
"status"
)
parameter_name
=
'is_filled_exact'
parameter_name
=
'is_filled_exact'
def
lookups
(
self
,
request
,
model_admin
):
def
lookups
(
self
,
request
,
model_admin
):
# This list is a collection of bankaccount.id, .name
return
[(
1
,
_
(
'not invoiced'
)),
(
2
,
_
(
'balance'
)),
(
3
,
_
(
'subscriptions'
)),
(
4
,
_
(
'losts and profits'
)),
(
5
,
_
(
'taxes'
))]
return
[(
1
,
_
(
'not invoiced'
)),]
def
queryset
(
self
,
request
,
queryset
):
def
queryset
(
self
,
request
,
queryset
):
# This query set is a collection of bankaccount
value
=
self
.
value
()
if
self
.
value
():
if
value
:
return
queryset
.
filter
(
permanence_id__isnull
=
True
)
if
value
==
"1"
:
return
queryset
.
filter
(
Q
(
permanence_id__isnull
=
True
,
customer_id__isnull
=
False
)
|
Q
(
permanence_id__isnull
=
True
,
producer_id__isnull
=
False
)
)
elif
value
==
"2"
:
return
queryset
.
filter
(
permanence_id__isnull
=
False
,
customer_id__isnull
=
True
,
producer_id__isnull
=
True
)
elif
value
==
"3"
:
return
queryset
.
filter
(
operation_status
=
BANK_SUBSCRIPTION
)
elif
value
==
"4"
:
return
queryset
.
filter
(
operation_status
=
BANK_PROFIT
)
else
:
return
queryset
.
filter
(
operation_status
=
BANK_TAX
)
else
:
else
:
return
queryset
return
queryset
\ No newline at end of file
repanier/admin/bankaccount.py
0 → 100644
View file @
46ae4c08
# -*- coding: utf-8
from
__future__
import
unicode_literals
from
django
import
forms
from
django.contrib
import
admin
from
django.utils.translation
import
ugettext_lazy
as
_
from
easy_select2
import
apply_select2
from
import_export
import
resources
,
fields
from
import_export.admin
import
ImportExportMixin
from
import_export.formats.base_formats
import
XLS
from
repanier.admin.admin_filter
import
BankAccountFilterByStatus
from
repanier.const
import
*
from
repanier.fields.RepanierMoneyField
import
FormMoneyField
from
repanier.models
import
BankAccount
,
Customer
,
Producer
,
ProducerInvoice
,
CustomerInvoice
from
repanier.xlsx.widget
import
IdWidget
,
TwoMoneysWidget
,
ProducerNameWidget
,
CustomerNameWidget
,
DateWidgetExcel
from
repanier.xlsx.extended_formats
import
XLSX_OPENPYXL_1_8_6
class
BankAccountResource
(
resources
.
ModelResource
):
id
=
fields
.
Field
(
attribute
=
'id'
,
widget
=
IdWidget
(),
readonly
=
True
)
permanence
=
fields
.
Field
(
attribute
=
'permanence'
,
readonly
=
True
)
operation_date
=
fields
.
Field
(
attribute
=
'operation_date'
,
widget
=
DateWidgetExcel
())
operation_status
=
fields
.
Field
(
attribute
=
'operation_status'
,
readonly
=
True
)
producer_name
=
fields
.
Field
(
attribute
=
'producer'
,
widget
=
ProducerNameWidget
(
Producer
,
field
=
'short_profile_name'
))
customer_name
=
fields
.
Field
(
attribute
=
'customer'
,
widget
=
CustomerNameWidget
(
Customer
,
field
=
'short_basket_name'
))
bank_amount_in
=
fields
.
Field
(
attribute
=
'bank_amount_in'
,
widget
=
TwoMoneysWidget
())
bank_amount_out
=
fields
.
Field
(
attribute
=
'bank_amount_out'
,
widget
=
TwoMoneysWidget
())
customer_invoice
=
fields
.
Field
(
attribute
=
'customer_invoice__date_balance'
,
widget
=
DateWidgetExcel
(),
readonly
=
True
)
producer_invoice
=
fields
.
Field
(
attribute
=
'producer_invoice__date_balance'
,
widget
=
DateWidgetExcel
(),
readonly
=
True
)
def
before_save_instance
(
self
,
instance
,
using_transactions
,
dry_run
):
"""
Override to add additional logic.
"""
if
instance
.
id
is
None
:
if
instance
.
producer
is
None
and
instance
.
customer
is
None
:
if
instance
.
bank_amount_out
is
not
None
and
instance
.
bank_amount_out
!=
DECIMAL_ZERO
:
only_one_target
=
ProducerInvoice
.
objects
.
filter
(
status
=
PERMANENCE_SEND
,
total_price_with_tax
=
instance
.
bank_amount_out
).
order_by
(
'?'
).
count
()
if
only_one_target
==
1
:
instance
.
producer
=
ProducerInvoice
.
objects
.
filter
(
status
=
PERMANENCE_SEND
,
total_price_with_tax
=
instance
.
bank_amount_out
).
order_by
(
'?'
).
first
().
producer
elif
instance
.
bank_amount_in
is
not
None
and
instance
.
bank_amount_in
!=
DECIMAL_ZERO
:
only_one_target
=
CustomerInvoice
.
objects
.
filter
(
status
=
PERMANENCE_SEND
,
total_price_with_tax
=
instance
.
bank_amount_in
).
order_by
(
'?'
).
count
()
if
only_one_target
==
1
:
instance
.
customer
=
CustomerInvoice
.
objects
.
filter
(
status
=
PERMANENCE_SEND
,
total_price_with_tax
=
instance
.
bank_amount_in
).
order_by
(
'?'
).
first
().
customer
if
instance
.
producer
is
None
and
instance
.
customer
is
None
:
raise
ValueError
(
_
(
"No producer nor customer found."
))
if
instance
.
bank_amount_out
is
None
:
instance
.
bank_amount_out
=
DECIMAL_ZERO
if
instance
.
bank_amount_in
is
None
:
instance
.
bank_amount_in
=
DECIMAL_ZERO
if
instance
.
producer
is
not
None
and
instance
.
customer
is
not
None
:
raise
ValueError
(
_
(
"Only a customer or a producer may be entered."
))
if
instance
.
producer
is
not
None
:
if
BankAccount
.
objects
.
filter
(
producer
=
instance
.
producer
,
bank_amount_in
=
instance
.
bank_amount_in
,
bank_amount_out
=
instance
.
bank_amount_out
,
operation_date
=
instance
.
operation_date
).
exists
():
raise
ValueError
(
_
(
"This movement already exists."
))
if
BankAccount
.
objects
.
filter
(
producer
=
instance
.
producer
,
bank_amount_in
=
instance
.
bank_amount_in
,
bank_amount_out
=
instance
.
bank_amount_out
,
operation_comment
=
instance
.
operation_comment
).
exists
():
raise
ValueError
(
_
(
"This movement already exists."
))
if
instance
.
customer
is
not
None
:
if
BankAccount
.
objects
.
filter
(
customer
=
instance
.
customer
,
bank_amount_in
=
instance
.
bank_amount_in
,
bank_amount_out
=
instance
.
bank_amount_out
,
operation_date
=
instance
.
operation_date
).
exists
():
raise
ValueError
(
_
(
"This movement already exists."
))
if
BankAccount
.
objects
.
filter
(
customer
=
instance
.
customer
,
bank_amount_in
=
instance
.
bank_amount_in
,
bank_amount_out
=
instance
.
bank_amount_out
,
operation_comment
=
instance
.
operation_comment
).
exists
():
raise
ValueError
(
_
(
"This movement already exists."
))
def
skip_row
(
self
,
instance
,
original
):
if
instance
.
id
is
not
None
:
# The import may not be used to update bank movements.
return
True
super
(
BankAccountResource
,
self
).
skip_row
(
instance
,
original
)
class
Meta
:
model
=
BankAccount
fields
=
(
'id'
,
'permanence'
,
'operation_date'
,
'operation_status'
,
'producer_name'
,
'customer_name'
,
'bank_amount_in'
,
'bank_amount_out'
,
'operation_comment'
,
'customer_invoice'
,
'producer_invoice'
)
export_order
=
fields
import_id_fields
=
(
'id'
,
)
skip_unchanged
=
True
report_skipped
=
False
use_transactions
=
False
class
CustomerModelChoiceField
(
forms
.
ModelChoiceField
):
def
label_from_instance
(
self
,
obj
):
# Important "if obj.bank_account" and not "if obj.bank_account is not None"
# to handle the case of empty string
bank_account1
=
"-%s"
%
obj
.
bank_account1
if
obj
.
bank_account1
else
EMPTY_STRING
bank_account2
=
"-%s"
%
obj
.
bank_account2
if
obj
.
bank_account2
else
EMPTY_STRING
return
"%s%s%s"
%
(
obj
.
short_basket_name
,
bank_account1
,
bank_account2
)
class
ProducerModelChoiceField
(
forms
.
ModelChoiceField
):
def
label_from_instance
(
self
,
obj
):
# Important "if obj.bank_account" and not "if obj.bank_account is not None"
bank_account
=
"-%s"
%
obj
.
bank_account
if
obj
.
bank_account
else
EMPTY_STRING
return
"%s%s"
%
(
obj
.
short_profile_name
,
bank_account
)
class
BankAccountDataForm
(
forms
.
ModelForm
):
customer
=
CustomerModelChoiceField
(
queryset
=
Customer
.
objects
.
filter
(
is_active
=
True
),
label
=
_
(
"customer"
),
required
=
False
,
widget
=
apply_select2
(
forms
.
Select
)
)
producer
=
ProducerModelChoiceField
(
queryset
=
Producer
.
objects
.
filter
(
represent_this_buyinggroup
=
False
,
is_active
=
True
),
label
=
_
(
"producer"
),
required
=
False
,
widget
=
apply_select2
(
forms
.
Select
)
)
bank_amount_in
=
FormMoneyField
(
label
=
_
(
"bank_amount_in"
),
help_text
=
_
(
'payment_on_the_account'
),
max_digits
=
8
,
decimal_places
=
2
,
required
=
False
,
initial
=
REPANIER_MONEY_ZERO
)
bank_amount_out
=
FormMoneyField
(
label
=
_
(
"bank_amount_out"
),
help_text
=
_
(
'payment_from_the_account'
),
max_digits
=
8
,
decimal_places
=
2
,
required
=
False
,
initial
=
REPANIER_MONEY_ZERO
)