Dekodi: Get rid of null values

This commit is contained in:
Raphael Michel
2019-04-29 15:46:32 +02:00
parent f0128429e4
commit e8e5f5c7bf

View File

@@ -29,33 +29,14 @@ class DekodiNREIExporter(BaseExporter):
positions = []
for l in invoice.lines.all():
positions.append({
'ABcd': None,
'ADes': l.description.replace("<br />", "\n"),
'ANetA': round(float(l.net_value), 2),
'ANetAEUR': None,
'ANo': None, # TODO: needs to be there!
'ANo1': None,
'ANo2': None,
'ANoEx': None,
'ANoM': None,
'ANo': self.event.slug,
'AQ': -1 if invoice.is_cancellation else 1,
'ASku': None,
'AST': 0,
'ATm': None,
'ATT': None,
'AU': None,
'AVatP': round(float(l.tax_rate), 2),
'AWgt': None,
'DiC': None,
'DiCeID': None,
'DICeN': None,
'DiZ': None,
'DIDt': (l.subevent or invoice.order.event).date_from.isoformat().replace('Z', '+00:00'),
'OC': None,
'PosGrossA': round(float((-1 if invoice.is_cancellation else 1) * l.gross_value), 2),
'PosGrossAEUR': None,
'PosNetA': round(float((-1 if invoice.is_cancellation else 1) * l.net_value), 2),
'PosNetAEUR': None,
})
gross_total += l.gross_value
net_total += l.net_value
@@ -72,175 +53,101 @@ class DekodiNREIExporter(BaseExporter):
'PTID': '1',
'PTN': 'PayPal',
'PTNo1': p.info_data.get('id'),
'PTNo2': None,
'PTNo3': None,
'PTNo4': None,
'PTNo5': None,
'PTNo6': None,
'PTNo7': round(float(p.amount), 2),
'PTNo8': str(self.event.currency),
'PTNo9': None,
'PTNo10': None,
'PTNo11': paypal_email,
'PTNo12': None,
'PTNo13': None,
'PTNo14': None,
'PTNo15': p.full_id,
'PTNo11': paypal_email or '',
'PTNo15': p.full_id or '',
})
elif p.provider == 'banktransfer':
payments.append({
'PTID': '4',
'PTN': 'Vorkasse',
'PTNo1': None,
'PTNo2': None,
'PTNo3': None,
'PTNo4': p.info_data.get('reference') or p.payment_provider._code(invoice.order),
'PTNo5': None,
'PTNo6': None,
'PTNo7': round(float(p.amount), 2),
'PTNo8': str(self.event.currency),
'PTNo9': None,
'PTNo10': p.info_data.get('payer'),
'PTNo11': None,
'PTNo12': None,
'PTNo13': None,
'PTNo14': p.info_data.get('date'),
'PTNo15': p.full_id,
'PTNo10': p.info_data.get('payer') or '',
'PTNo14': p.info_data.get('date') or '',
'PTNo15': p.full_id or '',
})
elif p.provider == 'sepadebit':
with language(invoice.order.locale):
payments.append({
'PTID': '5',
'PTN': 'Lastschrift',
'PTNo1': None,
'PTNo2': None,
'PTNo3': None,
'PTNo4': ugettext('Event ticket {event}-{code}').format(
event=self.event.slug.upper(),
code=invoice.order.code
),
'PTNo5': p.info_data.get('iban'),
'PTNo6': p.info_data.get('bic'),
'PTNo5': p.info_data.get('iban') or '',
'PTNo6': p.info_data.get('bic') or '',
'PTNo7': round(float(p.amount), 2),
'PTNo8': str(self.event.currency),
'PTNo9': p.info_data.get('date'),
'PTNo10': p.info_data.get('account'),
'PTNo11': None,
'PTNo12': None,
'PTNo13': None,
'PTNo14': p.info_data.get('reference'),
'PTNo15': p.full_id,
'PTNo8': str(self.event.currency) or '',
'PTNo9': p.info_data.get('date') or '',
'PTNo10': p.info_data.get('account') or '',
'PTNo14': p.info_data.get('reference') or '',
'PTNo15': p.full_id or '',
})
elif p.provider.startswith('stripe'):
src = p.info_data.get("source", "{}")
payments.append({
'PTID': '81',
'PTN': 'Stripe',
'PTNo1': p.info_data.get("id"),
'PTNo2': None,
'PTNo3': None,
'PTNo4': None,
'PTNo5': src.get("card", {}).get("last4"),
'PTNo6': None,
'PTNo7': round(float(p.amount), 2),
'PTNo8': str(self.event.currency),
'PTNo9': None,
'PTNo10': src.get('owner', {}).get('verified_name') or src.get('owner', {}).get('name'),
'PTNo11': None,
'PTNo12': None,
'PTNo13': None,
'PTNo14': None,
'PTNo15': p.full_id,
'PTNo1': p.info_data.get("id") or '',
'PTNo5': src.get("card", {}).get("last4") or '',
'PTNo7': round(float(p.amount), 2) or '',
'PTNo8': str(self.event.currency) or '',
'PTNo10': src.get('owner', {}).get('verified_name') or src.get('owner', {}).get('name') or '',
'PTNo15': p.full_id or '',
})
else:
payments.append({
'PTID': '0',
'PTN': p.provider,
'PTNo1': None,
'PTNo2': None,
'PTNo3': None,
'PTNo4': None,
'PTNo5': None,
'PTNo6': None,
'PTNo7': round(float(p.amount), 2),
'PTNo8': str(self.event.currency),
'PTNo9': None,
'PTNo10': None,
'PTNo11': None,
'PTNo12': None,
'PTNo13': None,
'PTNo14': None,
'PTNo15': p.full_id,
'PTNo7': round(float(p.amount), 2) or '',
'PTNo8': str(self.event.currency) or '',
'PTNo15': p.full_id or '',
})
payments = [
{
k: v for k, v in p.items() if v is not None
} for p in payments
]
hdr = {
'APmtA': None,
'APmtAEUR': None,
'C': str(invoice.invoice_to_country),
'CA': None,
'CAEUR': None,
'C': str(invoice.invoice_to_country) or self.event.settings.invoice_address_from_country,
'CC': self.event.currency,
'CGrp': None,
'CID': None,
'City': invoice.invoice_to_city,
'CN': invoice.invoice_to_company,
'CNo': None,
'CoDA': None,
'CoDAEUR': None,
'DL': None,
'DIC': None,
'DICt': None,
'DIC': self.event.settings.invoice_address_from_country,
# DIC is a little bit unclean, should be the event location's country
'DIDt': invoice.order.datetime.isoformat().replace('Z', '+00:00'),
'DIZ': None,
'DN': None,
'DT': '30' if invoice.is_cancellation else '10',
'EbNm': None,
'EbPmtID': None,
'EM': invoice.order.email,
'FamN': invoice.invoice_to_name.rsplit(' ', 1)[-1],
'FCExR': None,
'FN': invoice.invoice_to_name.rsplit(' ', 1)[0] if ' ' in invoice.invoice_to_name else '',
'FS': None,
'GwA': None,
'GwAEUR': None,
'IDt': invoice.date.isoformat() + 'T08:00:00+01:00',
'INo': invoice.full_invoice_no,
'IsNet': invoice.reverse_charge,
'IsPf': False,
'IT': None,
'KlnId': None,
'ODt': invoice.order.datetime.isoformat().replace('Z', '+00:00'),
'OID': invoice.order.code,
'Pb': None,
'PL': None,
'PmDt': p_last.payment_date.isoformat().replace('Z', '+00:00') if p_last else None,
'PPEm': paypal_email, # todo: fill,
'PvrINo': invoice.refers.full_invoice_no if invoice.refers else None,
'PrvOID': None,
'Rmrks': None,
'ShA': None,
'ShAEUR': None,
'ShDt': None,
'ShGrp': None,
'SID': self.event.slug,
'SN': str(self.event),
'SSID': None,
'SSINo': None,
'SSN': None,
'SSOID': None,
'Str': invoice.invoice_to_street,
'Str': invoice.invoice_to_street or '',
'TGrossA': round(float(gross_total), 2),
'TGrossAEUR': None,
'TNetA': round(float(net_total), 2),
'TNetAEUR': None,
'TNo': None,
'TT': None,
'TVatA': round(float(gross_total - net_total), 2),
'VatDp': False,
'VatID': invoice.invoice_to_vat_id or None,
'Zip': invoice.invoice_to_zipcode
}
if invoice.refers:
hdr['PvrINo'] = invoice.refers.full_invoice_no
if p_last:
hdr['PmDt'] = p_last.payment_date.isoformat().replace('Z', '+00:00')
if paypal_email:
hdr['PPEm'] = paypal_email
if invoice.invoice_to_vat_id:
hdr['VatID'] = invoice.invoice_to_vat_id
return {
'IsValid': True,