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