Commit 3db1b9ed authored by Patrick's avatar Patrick

Colorized delivery display in admin

parent 0cb5ad77
......@@ -389,7 +389,7 @@ class PurchaseAdmin(ExportMixin, admin.ModelAdmin):
delivery_field.initial = customer_invoice.first().delivery_id
elif delivery_id is not None:
delivery_field.initial = delivery_id
delivery_field.choices = [(o.id, o.get_delivery_display()) for o in DeliveryBoard.objects.filter(
delivery_field.choices = [(o.id, o.get_delivery_status_display()) for o in DeliveryBoard.objects.filter(
permanence_id=permanence_id
).order_by("id")]
else:
......
......@@ -6,6 +6,7 @@ from django.core.cache import cache
from django.db import models
from django.utils import timezone
from django.utils.encoding import python_2_unicode_compatible
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from menus.menu_pool import menu_pool
from parler.models import TranslatableModel, TranslatedFields, TranslationDoesNotExist
......@@ -70,7 +71,18 @@ class DeliveryBoard(TranslatableModel):
status=new_status
)
def __str__(self):
def get_delivery_display(self, admin=False):
try:
short_name = "%s" % self.delivery_point.short_name
except TranslationDoesNotExist:
short_name = EMPTY_STRING
if admin:
if self.delivery_date is not None:
label = mark_safe('%s <font color="green">%s</font>' % (
self.delivery_date.strftime(settings.DJANGO_SETTINGS_DATE), short_name))
else:
label = mark_safe('<font color="green">%s</font>' % short_name)
else:
try:
if self.delivery_comment != EMPTY_STRING:
comment = "%s " % self.delivery_comment
......@@ -78,18 +90,14 @@ class DeliveryBoard(TranslatableModel):
comment = EMPTY_STRING
except TranslationDoesNotExist:
comment = EMPTY_STRING
try:
short_name = "%s" % self.delivery_point.short_name
except TranslationDoesNotExist:
short_name = EMPTY_STRING
if self.delivery_date is not None:
label = "%s %s%s" % (
self.delivery_date.strftime(settings.DJANGO_SETTINGS_DATE), comment, short_name)
label = mark_safe('%s %s%s' % (
self.delivery_date.strftime(settings.DJANGO_SETTINGS_DATE), comment, short_name))
else:
label = "%s%s" % (comment, self.delivery_point.short_name)
label = mark_safe('%s%s' % (comment, short_name))
return label
def get_delivery_display(self):
def get_delivery_status_display(self):
return "%s - %s" % (self, self.get_status_display())
def get_delivery_customer_display(self):
......@@ -98,6 +106,9 @@ class DeliveryBoard(TranslatableModel):
else:
return "%s - %s" % (self, _('orders closed'))
def __str__(self):
return self.get_delivery_display()
class Meta:
verbose_name = _("delivery board")
verbose_name_plural = _("deliveries board")
......@@ -176,7 +176,7 @@ class Purchase(models.Model):
def get_delivery_display(self):
if self.customer_invoice is not None:
return self.customer_invoice.delivery
return self.customer_invoice.delivery.get_delivery_display(admin=True)
return None
get_delivery_display.short_description = (_("delivery point"))
......
......@@ -59,7 +59,7 @@ def export_abstract(permanence, deliveries_id=None, wb=None):
preparation_order += 1
row = [
"%d - %s" % (delivery_ref, delivery.get_delivery_display()),
"%d - %s" % (delivery_ref, delivery.get_delivery_status_display()),
" %d - %s" % (customer.preparation_order, customer.long_basket_name),
customer.phone1,
customer.phone2,
......@@ -334,7 +334,7 @@ def export_preparation_for_a_delivery(delivery_cpt, delivery_id, header, permane
if delivery_id is not None:
c = ws.cell(row=row_num, column=5)
c.style.font.bold = True
c.value = DeliveryBoard.objects.filter(id=delivery_id).order_by('?').first().get_delivery_display()
c.value = DeliveryBoard.objects.filter(id=delivery_id).order_by('?').first().get_delivery_status_display()
row_num += 1
producer_counter = 0
hide_column_placement = True
......@@ -1158,7 +1158,7 @@ def export_customer_for_a_delivery(
if delivery_id is not None:
c = ws.cell(row=row_num, column=4)
c.style.font.bold = True
c.value = DeliveryBoard.objects.filter(id=delivery_id).order_by('?').first().get_delivery_display()
c.value = DeliveryBoard.objects.filter(id=delivery_id).order_by('?').first().get_delivery_status_display()
row_num += 1
if ws_preparation_title is not None and xlsx_formula:
ref_preparation_sheet = ws_preparation_title if delivery_id is None else "%d-%s" % (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment