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 source diff could not be displayed because it is too large. You can view the blob instead.
# -*- 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)
This diff is collapsed.
This diff is collapsed.
# -*- coding: utf-8
from __future__ import unicode_literals
from django.utils.translation import ugettext_lazy as _
from parler.admin import TranslatableAdmin
from parler.forms import TranslatableModelForm
from repanier.const import ORDER_GROUP, INVOICE_GROUP, COORDINATION_GROUP
from repanier.models import Permanence, Producer
class ConfigurationDataForm(TranslatableModelForm):
def __init__(self, *args, **kwargs):
super(ConfigurationDataForm, self).__init__(*args, **kwargs)
def clean(self):
if any(self.errors):
# Don't bother validating the formset unless each form is valid on its own
return
send_order_mail_to_customer = self.cleaned_data["send_order_mail_to_customer"]
send_abstract_order_mail_to_customer = self.cleaned_data["send_abstract_order_mail_to_customer"]
if send_abstract_order_mail_to_customer and not send_order_mail_to_customer:
self.add_error(
'send_abstract_order_mail_to_customer',
_('The abstract can only be send if the order is also send to customer'))
send_order_mail_to_producer = self.cleaned_data["send_order_mail_to_producer"]
send_abstract_order_mail_to_producer = self.cleaned_data["send_abstract_order_mail_to_producer"]
if send_abstract_order_mail_to_producer and not send_order_mail_to_producer:
self.add_error(
'send_abstract_order_mail_to_customer',
_('The abstract can only be send if the order is also send to producer'))
class ConfigurationAdmin(TranslatableAdmin):
form = ConfigurationDataForm
def has_delete_permission(self, request, obj=None):
return False
def has_add_permission(self, request):
return False
def has_change_permission(self, request, obj=None):
if request.user.groups.filter(
name__in=[ORDER_GROUP, INVOICE_GROUP, COORDINATION_GROUP]).exists() or request.user.is_superuser:
return True
return False
def get_fieldsets(self, *args, **kwargs):
fieldsets = [
(None, {
'fields':
(('test_mode', 'group_name', 'name'),
'display_anonymous_order_form',
('display_producer_on_order_form', 'max_week_wo_participation'),
'customers_must_confirm_orders',
('bank_account', 'vat_id'),
('membership_fee', 'membership_fee_duration')),
}),
]
if Producer.objects.filter(producer_pre_opening=True).order_by('?').only('id').exists():
fieldsets += [
(_('Pre-opening mails'), {
'classes': ('collapse',),
'fields' :
(
'offer_producer_mail',
),
}),
]
fieldsets += [
(_('Opening mails'), {
'classes': ('collapse',),
'fields' :
(
'send_opening_mail_to_customer', 'offer_customer_mail',
),
}),
(_('Ordering mails'), {
'classes': ('collapse',),
'fields' :
(
'send_order_mail_to_customer', 'send_abstract_order_mail_to_customer', 'order_customer_mail',
'send_cancel_order_mail_to_customer', 'cancel_order_customer_mail',
'send_order_mail_to_producer', 'send_abstract_order_mail_to_producer', 'order_producer_mail',
'send_order_mail_to_board', 'order_staff_mail',
),
}),
(_('Invoicing mails'), {
'classes': ('collapse',),
'fields' :
(
'send_invoice_mail_to_customer', 'invoice_customer_mail',
'send_invoice_mail_to_producer', 'invoice_producer_mail',
),
}),
(_('Advanced options'), {
'classes': ('collapse',),
'fields' :
(
'home_site',
'transport',
'min_transport',
'group_label',
'page_break_on_customer_check',
'close_wo_sending',
'sms_gateway_mail',
('currency', 'invoice',),
),
}),
]
return fieldsets
def get_readonly_fields(self, request, configuration=None):
permanence = Permanence.objects.all().order_by('?')
is_coordinator = request.user.is_superuser or request.user.is_staff
if is_coordinator or permanence.first() is None:
return []
else:
return ['bank_account']
This diff is collapsed.
......@@ -6,6 +6,7 @@ class ForeignKeyCacheMixin(object):
"""
Cache foreignkey choices in the request object to prevent unnecessary queries.
"""
def formfield_for_foreignkey(self, db_field, request, **kwargs):
formfield = super(ForeignKeyCacheMixin, self).formfield_for_foreignkey(db_field, **kwargs)
cache = getattr(request, 'db_field_cache', {})
......@@ -15,7 +16,7 @@ class ForeignKeyCacheMixin(object):
formfield.choices.field.cache_choices = True
formfield.choices.field.choice_cache = [
formfield.choices.choice(obj) for obj in formfield.choices.queryset.all()
]
]
request.db_field_cache = cache
request.db_field_cache[db_field.name] = formfield.choices
return formfield
\ No newline at end of file
return formfield
from django import forms
from django.forms.formsets import formset_factory
from django.utils.translation import ugettext_lazy as _
from djangocms_text_ckeditor.widgets import TextEditorWidget
from repanier.const import REPANIER_MONEY_ZERO
from repanier.fields.RepanierMoneyField import FormMoneyField
class OpenAndSendOfferForm(forms.Form):
template_offer_customer_mail = forms.CharField(label=_("offer customer mail"), widget=TextEditorWidget,
required=False)
template_cancel_order_customer_mail = forms.CharField(
label=_("If customers must confirm orderds, cancelled order customer mail"),
widget=TextEditorWidget,
required=False
)
def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request', None)
super(OpenAndSendOfferForm, self).__init__(*args, **kwargs)
class CloseAndSendOrderForm(forms.Form):
template_order_customer_mail = forms.CharField(label=_("offer customer mail"), widget=TextEditorWidget,
required=False)
template_order_producer_mail = forms.CharField(label=_("offer producer mail"), widget=TextEditorWidget,
required=False)
template_order_staff_mail = forms.CharField(label=_("offer staff mail"), widget=TextEditorWidget, required=False)
def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request', None)
super(CloseAndSendOrderForm, self).__init__(*args, **kwargs)
class GeneratePermanenceForm(forms.Form):
repeat_counter = forms.DecimalField(label=_("Number of permanence(s)"), min_value=0, max_value=54, decimal_places=0)
repeat_step = forms.DecimalField(label=_("Number of week(s) between two permanences"), min_value=0, max_value=12,
decimal_places=0)
def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request', None)
super(GeneratePermanenceForm, self).__init__(*args, **kwargs)
class InvoiceOrderForm(forms.Form):
template_invoice_customer_mail = forms.CharField(
label=_("invoice customer mail"), widget=TextEditorWidget,
required=False)
template_invoice_producer_mail = forms.CharField(
label=_("invoice producer mail"), widget=TextEditorWidget,
required=False)
def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request', None)
super(InvoiceOrderForm, self).__init__(*args, **kwargs)
class PermanenceInvoicedForm(forms.Form):
payment_date = forms.DateField(label=_("payment date"), required=True)
def __init__(self, *args, **kwargs):
self.payment_date = kwargs.pop('payment_date', None)
super(PermanenceInvoicedForm, self).__init__(*args, **kwargs)
self.fields['payment_date'].initial = self.payment_date
class ProducerInvoicedForm(forms.Form):
selected = forms.BooleanField(required=False)
short_profile_name = forms.CharField(label=_("short_profile_name"), max_length=25, required=False)
calculated_invoiced_balance = FormMoneyField(
label=_("calculated balance to be invoiced"), max_digits=8, decimal_places=2, required=False, initial=REPANIER_MONEY_ZERO)
to_be_invoiced_balance = FormMoneyField(
label=_("balance to be invoiced"), max_digits=8, decimal_places=2, required=False, initial=REPANIER_MONEY_ZERO)
invoice_reference = forms.CharField(label=_("invoice reference"), max_length=100, required=False)
def __init__(self, *args, **kwargs):
super(ProducerInvoicedForm, self).__init__(*args, **kwargs)
self.fields["to_be_invoiced_balance"].widget.attrs['style'] = "width:100px"
self.fields["invoice_reference"].widget.attrs['style'] = "width:300px"
self.fields["calculated_invoiced_balance"].widget.attrs['readonly'] = True
self.fields["calculated_invoiced_balance"].widget.attrs['style'] = "width:100px"
ProducerInvoicedFormSet = formset_factory(ProducerInvoicedForm, extra=0)
# -*- coding: utf-8
from __future__ import unicode_literals
from django import forms
from django.contrib import admin
from django.contrib.admin import TabularInline
from django.db.models import Q
from django.utils.translation import ugettext_lazy as _
from django_mptt_admin.admin import DjangoMpttAdmin
from easy_select2 import apply_select2
from parler.admin import TranslatableAdmin
from parler.forms import TranslatableModelForm
from repanier.admin.fkey_choice_cache_mixin import ForeignKeyCacheMixin
from repanier.const import PERMANENCE_CLOSED, ORDER_GROUP, INVOICE_GROUP, \
COORDINATION_GROUP, DECIMAL_ONE
from repanier.models import PermanenceBoard, Customer, Permanence, LUT_DeliveryPoint
class LUTAdmin(TranslatableAdmin, DjangoMpttAdmin):
list_display = ( 'short_name', 'is_active')
list_display_links = ('short_name',)
mptt_level_indent = 20
mptt_indent_field = "short_name"
def has_delete_permission(self, request, obj=None):
if request.user.groups.filter(
name__in=[ORDER_GROUP, INVOICE_GROUP, COORDINATION_GROUP]).exists() or request.user.is_superuser:
return True
return False
def has_add_permission(self, request):
if request.user.groups.filter(
name__in=[ORDER_GROUP, INVOICE_GROUP, COORDINATION_GROUP]).exists() or request.user.is_superuser:
return True
return False
def has_change_permission(self, request, obj=None):
if request.user.groups.filter(
name__in=[ORDER_GROUP, INVOICE_GROUP, COORDINATION_GROUP]).exists() or request.user.is_superuser:
return True
return False
class LUTProductionModeAdmin(LUTAdmin):
exclude = ('picture',)
class LUTDeliveryPointDataForm(TranslatableModelForm):
customers = forms.ModelMultipleChoiceField(
Customer.objects.filter(
may_order=True, delivery_point__isnull=True,
represent_this_buyinggroup=False
),
widget=admin.widgets.FilteredSelectMultiple(_('Members'), False),
required=False
)
customer_responsible = forms.ModelChoiceField(
Customer.objects.filter(
may_order=False, is_active=True, delivery_point__isnull=True,
represent_this_buyinggroup=False
),
label=_("customer_responsible"),
help_text=_("Invoices are sent to this consumer who is responsible for collecting the payments."),
required=False)
def __init__(self, *args, **kwargs):
super(LUTDeliveryPointDataForm, self).__init__(*args, **kwargs)
if self.instance.id:
self.fields['customers'].initial = self.instance.customer_set.all()
self.fields['customers'].queryset = Customer.objects.filter(
Q(may_order=True, delivery_point__isnull=True) | Q(delivery_point=self.instance.id)
).distinct()
def clean(self):
if any(self.errors):
# Don't bother validating the formset unless each form is valid on its own
return
customer_responsible = self.cleaned_data.get("customer_responsible", None)
if customer_responsible is not None:
for delivery_point in LUT_DeliveryPoint.objects.filter(
customer_responsible=customer_responsible
).order_by('?'):
if delivery_point.id != self.instance.id:
self.add_error(
"customer_responsible",
_(
'This customer is already responsible of another delivery point (%(delivery_point)s). A customer may be responsible of maximum one delivery point.') % {
'delivery_point': delivery_point,})
def save(self, *args, **kwargs):
instance = super(LUTDeliveryPointDataForm, self).save(*args, **kwargs)
if instance.id is not None:
instance.closed_group = len(self.cleaned_data['customers']) > 0
instance.customer_set = self.cleaned_data['customers']
self.instance.save()
if instance.closed_group and instance.customer_responsible is not None:
# If this is a closed group with a customer_responsible, the customer.price_list_multiplier must be set to ONE
# Invoices are sent to the consumer responsible of the group who is
# also responsible for collecting the payments.
# The LUT_DeliveryPoint.price_list_multiplier will be used when invoicing the consumer responsible
# The link between the customer invoice and this customer responsible is made with
# CustomerInvoice.customer_who_pays
Customer.objects.filter(delivery_point=self.instance.id).update(price_list_multiplier=DECIMAL_ONE)
return instance
class Meta:
model = LUT_DeliveryPoint
fields = "__all__"
widgets = {
'customer_responsible': apply_select2(forms.Select),
}
class LUTDeliveryPointAdmin(LUTAdmin):
form = LUTDeliveryPointDataForm
def get_fields(self, request, obj=None):
if obj is None:
return ['parent', 'is_active', 'short_name', 'description', 'customer_responsible', 'price_list_multiplier', 'transport', 'min_transport']
return ['parent', 'is_active', 'short_name', 'description', 'customer_responsible', 'price_list_multiplier', 'transport', 'min_transport', 'customers']
class LUTDepartmentForCustomerAdmin(LUTAdmin):
pass
class PermanenceBoardInlineForm(forms.ModelForm):
class Meta:
widgets = {
'permanence': apply_select2(forms.Select),
'customer' : apply_select2(forms.Select),
}
class PermanenceBoardInline(ForeignKeyCacheMixin, TabularInline):
form = PermanenceBoardInlineForm
model = PermanenceBoard
fields = ['permanence', 'customer']
extra = 1
def get_queryset(self, request):
return super(PermanenceBoardInline, self).get_queryset(request).filter(
permanence__status__lte=PERMANENCE_CLOSED)
def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == "customer":
kwargs["queryset"] = Customer.objects.filter(may_order=True)
if db_field.name == "permanence":
kwargs["queryset"] = Permanence.objects.filter(status__lte=PERMANENCE_CLOSED).order_by("permanence_date")
return super(PermanenceBoardInline, self).formfield_for_foreignkey(db_field, request, **kwargs)
class LUTPermanenceRoleAdmin(LUTAdmin):
inlines = [PermanenceBoardInline]
def get_fields(self, request, obj=None):
return [
('parent',),
('is_active', 'customers_may_register', 'is_counted_as_participation'),
('short_name',),
('description',)
]
# -*- coding: utf-8
from __future__ import unicode_literals
from django import forms
from django.contrib import admin
from django.utils import translation
from django.utils.html import strip_tags
from django.utils.translation import ugettext_lazy as _
from repanier.admin.admin_filter import PurchaseFilterByProducerForThisPermanence, \
ProductFilterByDepartmentForThisProducer, OfferItemFilter
from repanier.const import PERMANENCE_CLOSED, PERMANENCE_OPENED
from repanier.models import Permanence, Product, LUT_DepartmentForCustomer, Producer
from repanier.tools import sint, update_offer_item
class OfferItemClosedDataForm(forms.ModelForm):
producer_qty_stock_invoiced = forms.CharField(
label=_("quantity invoiced by the producer"), required=False, initial=0)
def __init__(self, *args, **kwargs):
super(OfferItemClosedDataForm, self).__init__(*args, **kwargs)
offer_item = self.instance
self.fields["producer_qty_stock_invoiced"].initial = strip_tags(
offer_item.get_html_producer_qty_stock_invoiced())
self.fields["producer_qty_stock_invoiced"].widget.attrs['readonly'] = True
self.fields["producer_qty_stock_invoiced"].disabled = True
def get_readonly_fields(self, request, obj=None):
return ['qty_invoiced', ]
class OfferItemClosedAdmin(admin.ModelAdmin):
form = OfferItemClosedDataForm
search_fields = ('translations__long_name',)
list_display = ('department_for_customer', 'producer', 'get_long_name',
'stock',
'get_html_producer_qty_stock_invoiced',
'add_2_stock')
list_display_links = ('get_long_name',)
list_filter = (
PurchaseFilterByProducerForThisPermanence,
OfferItemFilter,
ProductFilterByDepartmentForThisProducer,
)
list_select_related = ('producer', 'department_for_customer')
list_per_page = 13
list_max_show_all = 13
ordering = ('translations__long_name',)
def get_queryset(self, request):
queryset = super(OfferItemClosedAdmin, self).get_queryset(request).filter(
translations__language_code=translation.get_language()
).distinct()
return queryset
def get_list_display(self, request):
producer_id = sint(request.GET.get('producer', 0))
if producer_id != 0:
producer_queryset = Producer.objects.filter(id=producer_id).order_by('?')
producer = producer_queryset.first()
else:
producer = None
permanence_id = sint(request.GET.get('permanence', 0))
permanence_open = False
permanence = Permanence.objects.filter(id=permanence_id, status=PERMANENCE_OPENED).order_by('?')
if permanence.exists():
permanence_open = True
if producer is not None:
self.list_editable = ('stock',)
if producer.manage_replenishment:
if permanence_open:
return ('department_for_customer', 'producer', 'get_long_name',
'stock',
'get_html_producer_qty_stock_invoiced')
else:
return ('department_for_customer', 'producer', 'get_long_name',
'stock',
'get_html_producer_qty_stock_invoiced',
'add_2_stock')
elif producer.manage_production:
return ('department_for_customer', 'producer', 'get_long_name',
'stock',
'get_html_producer_qty_stock_invoiced')
else:
return ('department_for_customer', 'producer', 'get_long_name',
'get_html_producer_qty_stock_invoiced')
else:
return ('department_for_customer', 'producer', 'get_long_name',
'get_html_producer_qty_stock_invoiced')
def get_form(self, request, obj=None, **kwargs):
if obj.manage_replenishment:
if obj.permanence.status == PERMANENCE_CLOSED:
fields_basic = [
('permanence', 'department_for_customer', 'product'),
('stock', 'producer_qty_stock_invoiced', 'add_2_stock',)
]
else:
fields_basic = [
('permanence', 'department_for_customer', 'product'),
('stock', 'producer_qty_stock_invoiced',)
]
elif obj.manage_production:
fields_basic = [
('permanence', 'department_for_customer', 'product'),
('stock', 'producer_qty_stock_invoiced',)
]
else:
fields_basic = [
('permanence', 'department_for_customer', 'product'),
('producer_qty_stock_invoiced',)
]
self.fieldsets = (
(None, {'fields': fields_basic}),
)
form = super(OfferItemClosedAdmin, self).get_form(request, obj, **kwargs)
permanence_field = form.base_fields["permanence"]
department_for_customer_field = form.base_fields["department_for_customer"]
product_field = form.base_fields["product"]
permanence_field.widget.can_add_related = False
department_for_customer_field.widget.can_add_related = False
product_field.widget.can_add_related = False
permanence_field.empty_label = None
department_for_customer_field.empty_label = None
product_field.empty_label = None
permanence_field.queryset = Permanence.objects \
.filter(id=obj.permanence_id)
department_for_customer_field.queryset = LUT_DepartmentForCustomer.objects \
.filter(id=obj.department_for_customer_id)
product_field.queryset = Product.objects \
.filter(id=obj.product_id)
return form
def has_add_permission(self, request):
return False
def has_delete_permission(self, request, obj=None):
return False
def get_actions(self, request):
actions = super(OfferItemClosedAdmin, self).get_actions(request)
if 'delete_selected' in actions:
del actions['delete_selected']
if not actions:
try:
self.list_display.remove('action_checkbox')
except ValueError:
pass
except AttributeError:
pass
return actions
def save_model(self, request, offer_item, form, change):
super(OfferItemClosedAdmin, self).save_model(
request, offer_item, form, change)
offer_item.product.stock = offer_item.stock
offer_item.product.save(update_fields=['stock'])
update_offer_item(product_id=offer_item.product_id)
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.