Commit 46ae4c08 authored by Patrick's avatar Patrick

Django 1.9.11, CMS 3.4.1

parent 3e4798c3
This diff is collapsed.
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')),
) )
......
This diff is collapsed.
# -*- 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)
# -*- 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 PurchaseFilterByCustomerForThisPermanence(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
# -*- 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)