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 import settings
from django.contrib import admin
from django.contrib import auth
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.contrib.sitemaps.views import sitemap
from cms.sitemaps import CMSSitemap
# admin.autodiscover
# urlpatterns = patterns('',
# url(r'^jsi18n/(?P<packages>\S+?)/$', 'django.views.i18n.javascript_catalog'),
# )
urlpatterns = i18n_patterns('',
urlpatterns = i18n_patterns(
url(r'^repanier/', include('repanier.urls')),
url(r'^coordi/', include(admin.site.urls)),
url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': {'cmspages': CMSSitemap}}),
# url(r'^', include('filer.server.urls')),
# url(r'^', include('password_reset.urls')),
# url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': {'cmspages': CMSSitemap}}),
url(r'^sitemap\.xml$', sitemap, {'sitemaps': {'cmspages': CMSSitemap}}, name='django.contrib.sitemaps.views.sitemap'),
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
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 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
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):
......@@ -21,6 +19,7 @@ class ProductFilterByProducer(SimpleListFilter):
title = _("producers")
# Parameter for the filter that will be used in the URL query.
parameter_name = 'producer'
template = 'admin/producer_filter.html'
def lookups(self, request, model_admin):
"""
......@@ -33,7 +32,7 @@ class ProductFilterByProducer(SimpleListFilter):
# This list is a collection of producer.id, .name
return [(c.id, c.short_profile_name) for c in
Producer.objects.filter(is_active=True)
]
]
def queryset(self, request, queryset):
"""
......@@ -51,6 +50,7 @@ class ProductFilterByProducer(SimpleListFilter):
class ProductFilterByDepartmentForThisProducer(SimpleListFilter):
title = _("departments for customer")
parameter_name = 'department_for_customer'
template = 'admin/department_filter.html'
def lookups(self, request, model_admin):
producer_id = request.GET.get('producer')
......@@ -66,42 +66,39 @@ class ProductFilterByDepartmentForThisProducer(SimpleListFilter):
inner_qs = Product.objects.filter(is_active=True).order_by().distinct(
'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)
]
]
def queryset(self, request, queryset):
# This query set is a collection of products
if self.value():
return queryset.filter(department_for_customer_id=self.value())
else:
return queryset
class PurchaseFilterByCustomerForThisPermanence(SimpleListFilter):
class PurchaseFilterByCustomer(SimpleListFilter):
title = _("customer")
parameter_name = 'customer'
template = 'admin/customer_filter.html'
def lookups(self, request, model_admin):
permanence_id = request.GET.get('permanence')
if permanence_id:
permanence_id = sint(permanence_id, 0)
if permanence_id >= 0:
return [(c.id, c.short_basket_name) for c in
Customer.objects.filter(purchase__permanence_id=permanence_id).distinct()
]
permanence_id = request.GET.get('permanence', None)
list_filter = []
for c in Customer.objects.filter(may_order=True):
ci = CustomerInvoice.objects.filter(permanence=permanence_id, customer_id=c.id).order_by('?').only(
'total_price_with_tax', 'is_order_confirm_send').first()
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:
# This is a year
return [(c.id, c.short_basket_name) for c in
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)
]
list_filter.append((c.id, c.short_basket_name))
return list_filter
def queryset(self, request, queryset):
# This query set is a collection of purchase
if self.value():
return queryset.filter(customer_id=self.value())
else:
......@@ -111,27 +108,24 @@ class PurchaseFilterByCustomerForThisPermanence(SimpleListFilter):
class PurchaseFilterByProducerForThisPermanence(SimpleListFilter):
title = _("producer")
parameter_name = 'producer'
template = 'admin/producer_filter.html'
def lookups(self, request, model_admin):
permanence_id = request.GET.get('permanence')
if permanence_id:
permanence_id = sint(permanence_id, 0)
if permanence_id >= 0:
return [(c.id, c.short_profile_name) for c in
Producer.objects.filter(permanence=permanence_id).distinct()
]
else:
# This is a year
return [(c.id, c.short_profile_name) for c in
Producer.objects.filter(permanence__permanence_date__year=-permanence_id).distinct()
]
permanence_id = request.GET.get('permanence', None)
if permanence_id is not None:
list_filter = []
for p in Producer.objects.filter(permanence=permanence_id):
pi = ProducerInvoice.objects.filter(permanence=permanence_id, producer_id=p.id).order_by('?').only(
'total_price_with_tax').first()
if pi is not None:
list_filter.append((p.id, "%s (%s)" % (p.short_profile_name, pi.total_price_with_tax,)))
else:
list_filter.append((p.id, p.short_profile_name))
return list_filter
else:
return [(c.id, c.short_profile_name) for c in
Producer.objects.filter(is_active=True)
]
return []
def queryset(self, request, queryset):
# This query set is a collection of purchase
if self.value():
return queryset.filter(producer_id=self.value())
else:
......@@ -143,28 +137,39 @@ class PurchaseFilterByPermanence(SimpleListFilter):
parameter_name = 'permanence'
def lookups(self, request, model_admin):
# This list is a collection of permanence.id, .name
if PERMANENCE_DONE in model_admin.permanence_status_list \
or PERMANENCE_ARCHIVED in model_admin.permanence_status_list:
this_year = timezone.now().year
return [
(-(this_year -i), str(this_year - i)) for i in xrange(10)
]
permanence_id = request.GET.get('permanence', None)
if permanence_id is None:
return [(p.id, p.get_permanence_display(with_status=False)) for p in
Permanence.objects.filter(status__in=[PERMANENCE_OPENED, PERMANENCE_CLOSED, PERMANENCE_SEND])
]
else:
return [(c.id, c.__str__()) for c in
Permanence.objects.filter(status__in=model_admin.permanence_status_list)
]
return []
def queryset(self, request, queryset):
# This query set is a collection of purchase
if self.value():
permanence_id = sint(self.value(),0)
if permanence_id >= 0:
permanence_id = sint(self.value(), 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)
else:
return queryset.filter(permanence_date__year=-permanence_id)
else:
return queryset
return queryset.filter(permanence__status=PERMANENCE_SEND)
return queryset
class OfferItemFilter(SimpleListFilter):
......@@ -172,27 +177,38 @@ class OfferItemFilter(SimpleListFilter):
parameter_name = 'is_filled_exact'
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):
# This query set is a collection of offer_item
if self.value():
return queryset.exclude(quantity_invoiced=DECIMAL_ZERO)
else:
return queryset
class BankAccountFilterByPermanence(SimpleListFilter):
title = _("permanence")
class BankAccountFilterByStatus(SimpleListFilter):
title = _("status")
parameter_name = 'is_filled_exact'
def lookups(self, request, model_admin):
# This list is a collection of bankaccount.id, .name
return [(1, _('not invoiced')),]
return [(1, _('not invoiced')), (2, _('balance')), (3, _('subscriptions')), (4, _('losts and profits')), (5, _('taxes'))]
def queryset(self, request, queryset):
# This query set is a collection of bankaccount
if self.value():
return queryset.filter(permanence_id__isnull=True)
value = self.value()
if value:
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:
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)
def __init__(self, *args, **kwargs):
super(BankAccountDataForm, self).__init__(*args, **kwargs)
bank_account = self.instance
if bank_account.id is not None:
self.fields["bank_amount_in"].initial = bank_account.bank_amount_in
self.fields["bank_amount_out"].initial = bank_account.bank_amount_out
self.fields["customer"].widget.attrs['readonly'] = True
self.fields["customer"].disabled = True
self.fields["producer"].widget.attrs['readonly'] = True
self.fields["producer"].disabled = True
if bank_account.customer is None:
self.fields["customer"].choices = [('', _("---------"))]
else:
self.fields["customer"].empty_label = None
self.fields["customer"].queryset = Customer.objects.filter(id=bank_account.customer_id)
if bank_account.producer is None:
self.fields["producer"].choices = [('', _("---------"))]
else:
self.fields["producer"].empty_label = None
self.fields["producer"].queryset = Producer.objects.filter(id=bank_account.producer_id)
if (bank_account.customer_invoice is not None or bank_account.producer_invoice is not None) or (
bank_account.customer is None and bank_account.producer is None):
self.fields["operation_date"].widget.attrs['readonly'] = True
self.fields["operation_date"].disabled = True
self.fields["bank_amount_in"].widget.attrs['readonly'] = True
self.fields["bank_amount_in"].disabled = True
self.fields["bank_amount_out"].widget.attrs['readonly'] = True
self.fields["bank_amount_out"].disabled = True
if bank_account.customer is None and bank_account.producer is None:
self.fields["operation_comment"].widget.attrs['readonly'] = True
self.fields["operation_comment"].disabled = True
else:
self.fields["producer"].queryset = Producer.objects.filter(
represent_this_buyinggroup=False, is_active=True
)
self.fields["customer"].queryset = Customer.objects.filter(
is_active=True
)
def clean(self):
if any(self.errors):
# Don't bother validating the formset unless each form is valid on its own
return
customer = self.cleaned_data.get("customer")
producer = self.cleaned_data.get("producer")
initial_id = self.instance.id
initial_customer = self.instance.customer
initial_producer = self.instance.producer
if customer is None and producer is None:
if initial_id is not None:
if initial_customer is None and initial_producer is None:
raise forms.ValidationError(
_('You may not update a balance.')
)
else:
self.add_error('customer', _('Either a customer or a producer must be given.'))
self.add_error('producer', _('Either a customer or a producer must be given.'))
else:
bank_account = BankAccount.objects.filter(operation_status=BANK_LATEST_TOTAL).order_by('?').first()
if bank_account:
# You may only insert the first latest bank total at initialisation of the website
self.add_error('customer', _('Either a customer or a producer must be given.'))
self.add_error('producer', _('Either a customer or a producer must be given.'))
else:
if self.instance