Commits

Michael P. Jung  committed 888c0fe

Add item date as alternative to the period

  • Participants
  • Parent commits 90777c2

Comments (0)

Files changed (3)

File dinbrief/invoice/item.py

 
 class Item(object):
 
-    def __init__(self, position=0, text='', period='', price=Decimal(0),
-            unit='', quantity=Decimal(1), discount=Decimal(0),
-            vat_rate=Decimal(0)):
+    def __init__(self, position=0, text='', period='', date=None,
+            price=Decimal(0), unit='', quantity=Decimal(1),
+            discount=Decimal(0), vat_rate=Decimal(0)):
         self.position = position
         self.text = text
         self.period = period
+        self.date = date
         self.price = price
         self.unit = unit
         self.quantity = quantity

File dinbrief/invoice/item_table.py

 from ..constants import CONTENT_WIDTH
 from ..optional_django import ugettext as _
 from ..optional_django import number_format
+from ..optional_django import date_format
 from ..styles import styles
 
 
     ]
 
     show_period_column = any(item.period for item in invoice.items)
+    show_date_column = any(item.date for item in invoice.items) and \
+            not show_period_column
 
     col_widths = [
             8*mm, # position
             0,    # description
-            46*mm, # period
-            24*mm, # net price
-            14*mm, # unit
+            46*mm if show_period_column else # period
+            24*mm if show_date_column else # date
+            0, # neither period nor date
+            18*mm, # unit price
+            10*mm, # unit
             14*mm, # quantity
-            24*mm  # line total
+            24*mm  # sum price
     ]
     col_widths[1] = CONTENT_WIDTH - sum(col_widths)
 
         yield (
             HeadRight(u'#'),
             Head(_('Description')),
-            Head(_('Period') if show_period_column else ''),
-            HeadRight(_('Net Price')),
+            Head(_('Period') if show_period_column else
+                 _('Date') if show_date_column else ''),
+            HeadRight(_('Unit Price')),
             Head(u''),
             HeadRight(_('Quantity')),
             HeadRight(_('Line Total')),
         row = 0
         for item in invoice.items:
             row += 1
-            if not item.period:
+            if not (item.period or item.date):
                 style.append(('SPAN', (1, row), (2, row)))
             yield (
                 Number(unicode(item.position)),
                 Cell(escape(item.text)),
-                Cell(escape(item.period) if item.period else u''),
+                Cell(escape(item.period) if item.period else
+                     escape(date_format(item.date, 'SHORT_DATE_FORMAT')) if item.date else u''),
                 Number(u'%s €' % number_format(item.price, 2)),
                 Cell((u'/%s' % escape(item.get_unit_display()))
                     if item.unit else u''),

File dinbrief/optional_django.py

 
 try:
     from django.utils.translation import gettext, ugettext
-except:
+except ImportError:
     from gettext import gettext
     ugettext = gettext
 
 try:
     from django.utils.formats import number_format
-except:
+except ImportError:
     def number_format(value, decimal_places=''):
         format = '%%.%sf' % decimal_places
         return format % value
+
+try:
+    from django.utils.formats import date_format
+except ImportError:
+    def date_format(value, format=None):
+        return unicode(value)