Commit 3db1b9ed authored by Patrick's avatar Patrick

Colorized delivery display in admin

parent 0cb5ad77
...@@ -389,7 +389,7 @@ class PurchaseAdmin(ExportMixin, admin.ModelAdmin): ...@@ -389,7 +389,7 @@ class PurchaseAdmin(ExportMixin, admin.ModelAdmin):
delivery_field.initial = customer_invoice.first().delivery_id delivery_field.initial = customer_invoice.first().delivery_id
elif delivery_id is not None: elif delivery_id is not None:
delivery_field.initial = delivery_id 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 permanence_id=permanence_id
).order_by("id")] ).order_by("id")]
else: else:
......
...@@ -6,6 +6,7 @@ from django.core.cache import cache ...@@ -6,6 +6,7 @@ from django.core.cache import cache
from django.db import models from django.db import models
from django.utils import timezone from django.utils import timezone
from django.utils.encoding import python_2_unicode_compatible 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 django.utils.translation import ugettext_lazy as _
from menus.menu_pool import menu_pool from menus.menu_pool import menu_pool
from parler.models import TranslatableModel, TranslatedFields, TranslationDoesNotExist from parler.models import TranslatableModel, TranslatedFields, TranslationDoesNotExist
...@@ -70,26 +71,33 @@ class DeliveryBoard(TranslatableModel): ...@@ -70,26 +71,33 @@ class DeliveryBoard(TranslatableModel):
status=new_status status=new_status
) )
def __str__(self): def get_delivery_display(self, admin=False):
try:
if self.delivery_comment != EMPTY_STRING:
comment = "%s " % self.delivery_comment
else:
comment = EMPTY_STRING
except TranslationDoesNotExist:
comment = EMPTY_STRING
try: try:
short_name = "%s" % self.delivery_point.short_name short_name = "%s" % self.delivery_point.short_name
except TranslationDoesNotExist: except TranslationDoesNotExist:
short_name = EMPTY_STRING short_name = EMPTY_STRING
if self.delivery_date is not None: if admin:
label = "%s %s%s" % ( if self.delivery_date is not None:
self.delivery_date.strftime(settings.DJANGO_SETTINGS_DATE), comment, short_name) 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: else:
label = "%s%s" % (comment, self.delivery_point.short_name) try:
if self.delivery_comment != EMPTY_STRING:
comment = "%s " % self.delivery_comment
else:
comment = EMPTY_STRING
except TranslationDoesNotExist:
comment = EMPTY_STRING
if self.delivery_date is not None:
label = mark_safe('%s %s%s' % (
self.delivery_date.strftime(settings.DJANGO_SETTINGS_DATE), comment, short_name))
else:
label = mark_safe('%s%s' % (comment, short_name))
return label return label
def get_delivery_display(self): def get_delivery_status_display(self):
return "%s - %s" % (self, self.get_status_display()) return "%s - %s" % (self, self.get_status_display())
def get_delivery_customer_display(self): def get_delivery_customer_display(self):
...@@ -98,6 +106,9 @@ class DeliveryBoard(TranslatableModel): ...@@ -98,6 +106,9 @@ class DeliveryBoard(TranslatableModel):
else: else:
return "%s - %s" % (self, _('orders closed')) return "%s - %s" % (self, _('orders closed'))
def __str__(self):
return self.get_delivery_display()
class Meta: class Meta:
verbose_name = _("delivery board") verbose_name = _("delivery board")
verbose_name_plural = _("deliveries board") verbose_name_plural = _("deliveries board")
...@@ -176,7 +176,7 @@ class Purchase(models.Model): ...@@ -176,7 +176,7 @@ class Purchase(models.Model):
def get_delivery_display(self): def get_delivery_display(self):
if self.customer_invoice is not None: if self.customer_invoice is not None:
return self.customer_invoice.delivery return self.customer_invoice.delivery.get_delivery_display(admin=True)
return None return None
get_delivery_display.short_description = (_("delivery point")) get_delivery_display.short_description = (_("delivery point"))
......
...@@ -59,7 +59,7 @@ def export_abstract(permanence, deliveries_id=None, wb=None): ...@@ -59,7 +59,7 @@ def export_abstract(permanence, deliveries_id=None, wb=None):
preparation_order += 1 preparation_order += 1
row = [ 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), " %d - %s" % (customer.preparation_order, customer.long_basket_name),
customer.phone1, customer.phone1,
customer.phone2, customer.phone2,
...@@ -334,7 +334,7 @@ def export_preparation_for_a_delivery(delivery_cpt, delivery_id, header, permane ...@@ -334,7 +334,7 @@ def export_preparation_for_a_delivery(delivery_cpt, delivery_id, header, permane
if delivery_id is not None: if delivery_id is not None:
c = ws.cell(row=row_num, column=5) c = ws.cell(row=row_num, column=5)
c.style.font.bold = True 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 row_num += 1
producer_counter = 0 producer_counter = 0
hide_column_placement = True hide_column_placement = True
...@@ -1158,7 +1158,7 @@ def export_customer_for_a_delivery( ...@@ -1158,7 +1158,7 @@ def export_customer_for_a_delivery(
if delivery_id is not None: if delivery_id is not None:
c = ws.cell(row=row_num, column=4) c = ws.cell(row=row_num, column=4)
c.style.font.bold = True 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 row_num += 1
if ws_preparation_title is not None and xlsx_formula: if ws_preparation_title is not None and xlsx_formula:
ref_preparation_sheet = ws_preparation_title if delivery_id is None else "%d-%s" % ( 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