diff --git a/import2ledger/importers/nbpy2017.py b/import2ledger/importers/nbpy2017.py index f861d2f7db20af8a53a6f9ffbcb96a2b37205067..75ec2124be8e638ff54772ce76fc130d700e8c94 100644 --- a/import2ledger/importers/nbpy2017.py +++ b/import2ledger/importers/nbpy2017.py @@ -1,6 +1,7 @@ import collections import decimal import functools +import re import bs4 from .. import strparse @@ -10,11 +11,8 @@ STATUS_PAID = 'Payment' STATUS_REFUNDED = 'Refund' class Invoice2017: - STANDARD_TICKET_RBI = decimal.Decimal('42.50') - DISCOUNT_TICKET_RBI = STANDARD_TICKET_RBI / 2 - STANDARD_SHIRT_RBI = decimal.Decimal('25.50') - DISCOUNT_SHIRT_RBI = STANDARD_SHIRT_RBI CURRENCY = 'USD' + ITEM_RE = re.compile(r'(?:^|\()(Ticket|T-Shirt) - ') @classmethod def _elem_stripped_string(cls, elem): @@ -54,8 +52,10 @@ class Invoice2017: 'invoice_date': self.invoice_date, 'invoice_id': self.invoice_id, 'payee': self.payee, + 'shirt_price': self.shirt_price, 'shirt_rate': self.shirt_rate, 'shirts_sold': self.shirts_sold, + 'ticket_price': self.ticket_price, 'ticket_rate': self.ticket_rate, 'tickets_sold': self.tickets_sold, } @@ -78,23 +78,36 @@ class Invoice2017: def _read_invoice_items(self, table, first_row_text, rows_text): self.amount = decimal.Decimal(0) self.tickets_sold = decimal.Decimal(0) - self.ticket_rate = self.STANDARD_TICKET_RBI + self.ticket_price = decimal.Decimal(0) + self.ticket_rate = '' self.shirts_sold = decimal.Decimal(0) - self.shirt_rate = self.STANDARD_SHIRT_RBI + self.shirt_price = decimal.Decimal(0) + self.shirt_rate = '' for description, qty, unit_price, total in rows_text: if qty is None: continue total = strparse.currency_decimal(total) self.amount += total - if description.startswith('Ticket - '): + match = self.ITEM_RE.search(description) + try: + item_type = match.group(1) + except AttributeError: + continue + qty = int(qty) + unit_price = strparse.currency_decimal(unit_price) + if item_type == 'Ticket': if total > 0: - self.tickets_sold += int(qty) - elif description.startswith('Early Bird ('): - self.ticket_rate = self.DISCOUNT_TICKET_RBI - elif description.startswith('T-Shirt - '): - self.shirts_sold += int(qty) - elif description.startswith('T-shirts complimentary '): - self.shirts_sold -= int(qty) + self.tickets_sold += qty + self.ticket_price += unit_price + self.ticket_rate = description + elif item_type == 'T-Shirt': + if description.startswith('T-shirts complimentary '): + self.shirts_sold -= qty + else: + if total > 0: + self.shirts_sold += qty + self.shirt_price += unit_price + self.shirt_rate = description def _read_invoice_activity(self, table, first_row_text, rows_text): self.actions = [{