def export_form_fields(self) -> dict: f = OverviewFilterForm(event=self.event) del f.fields['ordering'] return f.fields
def _table_story(self, doc, form_data, net=False): from reportlab.lib.units import mm from reportlab.platypus import Paragraph, Spacer, Table, TableStyle headlinestyle = self.get_style() headlinestyle.fontSize = 15 headlinestyle.fontName = 'OpenSansBd' colwidths = [ a * doc.width for a in ( 1 - (0.05 + 0.075) * 6, 0.05, .075, 0.05, .075, 0.05, .075, 0.05, .075, 0.05, .075, 0.05, .075 ) ] tstyledata = [ ('SPAN', (1, 0), (2, 0)), ('SPAN', (3, 0), (4, 0)), ('SPAN', (5, 0), (6, 1)), ('SPAN', (7, 0), (-1, 0)), ('SPAN', (7, 1), (8, 1)), ('SPAN', (9, 1), (10, 1)), ('SPAN', (11, 1), (12, 1)), ('ALIGN', (0, 0), (-1, 1), 'CENTER'), ('ALIGN', (1, 2), (-1, -1), 'RIGHT'), ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'), ('FONTNAME', (0, 0), (-1, 1), 'OpenSansBd'), ('FONTNAME', (0, -1), (-1, -1), 'OpenSansBd'), ('FONTSIZE', (0, 0), (-1, -1), 8), ('LINEBEFORE', (1, 0), (1, -1), 1, colors.lightgrey), ('LINEBEFORE', (3, 0), (3, -1), 1, colors.lightgrey), ('LINEBEFORE', (5, 0), (5, -1), 1, colors.lightgrey), ('LINEBEFORE', (7, 0), (7, -1), 1, colors.lightgrey), ('LINEBEFORE', (9, 1), (9, -1), 1, colors.lightgrey), ('LINEBEFORE', (11, 1), (11, -1), 1, colors.lightgrey), ] tstyle = copy.copy(self.get_style()) tstyle.fontSize = 8 tstyle_bold = copy.copy(tstyle) tstyle_bold.fontSize = 8 tstyle_bold.fontName = 'OpenSansBd' tstyle_th = copy.copy(tstyle_bold) tstyle_th.alignment = TA_CENTER story = [ Paragraph(_('Orders by product') + ' ' + (_('(excl. taxes)') if net else _('(incl. taxes)')), headlinestyle), Spacer(1, 5 * mm) ] if form_data.get('date_axis'): story += [ Paragraph(_('{axis} between {start} and {end}').format( axis=dict(OverviewFilterForm(event=self.event).fields['date_axis'].choices)[form_data.get('date_axis')], start=date_format(form_data.get('date_from'), 'SHORT_DATE_FORMAT') if form_data.get('date_from') else '–', end=date_format(form_data.get('date_until'), 'SHORT_DATE_FORMAT') if form_data.get('date_until') else '–', ), self.get_style()), Spacer(1, 5 * mm) ] if form_data.get('subevent'): try: subevent = self.event.subevents.get(pk=self.form_data.get('subevent')) except SubEvent.DoesNotExist: subevent = self.form_data.get('subevent') story.append(Paragraph(pgettext('subevent', 'Date: {}').format(subevent), self.get_style())) story.append(Spacer(1, 5 * mm)) tdata = [ [ _('Product'), Paragraph(_('Canceled'), tstyle_th), '', Paragraph(_('Expired'), tstyle_th), '', Paragraph(_('Approval pending'), tstyle_th), '', Paragraph(_('Purchased'), tstyle_th), '', '', '', '', '' ], [ '', '', '', '', '', '', '', _('Pending'), '', _('Paid'), '', _('Total'), '' ], [ '', _('#'), self.event.currency, _('#'), self.event.currency, _('#'), self.event.currency, _('#'), self.event.currency, _('#'), self.event.currency, _('#'), self.event.currency, ], ] items_by_category, total = order_overview( self.event, subevent=form_data.get('subevent'), date_filter=form_data.get('date_axis'), date_from=form_data.get('date_from'), date_until=form_data.get('date_until'), fees=True ) places = settings.CURRENCY_PLACES.get(self.event.currency, 2) states = ( ('canceled', Order.STATUS_CANCELED), ('expired', Order.STATUS_EXPIRED), ('unapproved', 'unapproved'), ('pending', Order.STATUS_PENDING), ('paid', Order.STATUS_PAID), ('total', None), ) for tup in items_by_category: if tup[0]: tdata.append([ Paragraph(str(tup[0].name), tstyle_bold) ]) for l, s in states: tdata[-1].append(str(tup[0].num[l][0])) tdata[-1].append(floatformat(tup[0].num[l][2 if net else 1], places)) for item in tup[1]: tdata.append([ str(item) ]) for l, s in states: tdata[-1].append(str(item.num[l][0])) tdata[-1].append(floatformat(item.num[l][2 if net else 1], places)) if item.has_variations: for var in item.all_variations: tdata.append([ Paragraph(" " + str(var), tstyle) ]) for l, s in states: tdata[-1].append(str(var.num[l][0])) tdata[-1].append(floatformat(var.num[l][2 if net else 1], places)) tdata.append([ _("Total"), ]) for l, s in states: tdata[-1].append(str(total['num'][l][0])) tdata[-1].append(floatformat(total['num'][l][2 if net else 1], places)) table = Table(tdata, colWidths=colwidths, repeatRows=3) table.setStyle(TableStyle(tstyledata)) story.append(table) return story