Changeset - 7156529ceb23
[Not reviewed]
0 3 0
Brett Smith - 5 years ago 2019-10-15 19:44:53
brettcsmith@brettcsmith.org
nbpy2017: Report item rate names and final unit prices.

This keeps more of the RBI calculation in the templates, where it belongs.
Template logic has become more capable since this importer was first
written, which makes this change practical.
3 files changed with 52 insertions and 27 deletions:
0 comments (0 inline, 0 general)
import2ledger/importers/nbpy2017.py
Show inline comments
...
 
@@ -3,2 +3,3 @@ import decimal
 
import functools
 
import re
 

	
...
 
@@ -12,7 +13,4 @@ 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) - ')
 

	
...
 
@@ -56,4 +54,6 @@ class Invoice2017:
 
            '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,
...
 
@@ -80,5 +80,7 @@ class Invoice2017:
 
        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:
...
 
@@ -88,11 +90,22 @@ class Invoice2017:
 
            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
 

	
setup.py
Show inline comments
...
 
@@ -32,3 +32,3 @@ setup(
 
    description="Import different sources of financial data to Ledger",
 
    version='0.9.3',
 
    version='0.10.0',
 
    author='Brett Smith',
tests/data/imports.yml
Show inline comments
...
 
@@ -182,5 +182,7 @@
 
      tickets_sold: !!python/object/apply:decimal.Decimal ["1"]
 
      ticket_rate: !!python/object/apply:decimal.Decimal ["21.25"]
 
      ticket_price: !!python/object/apply:decimal.Decimal ["80.00"]
 
      ticket_rate: Early Bird (Ticket - Individual Supporter)
 
      shirts_sold: !!python/object/apply:decimal.Decimal ["1"]
 
      shirt_rate: !!python/object/apply:decimal.Decimal ["25.50"]
 
      shirt_price: !!python/object/apply:decimal.Decimal ["0"]
 
      shirt_rate: "Complimentary for ticket holder (Supporter-level and above) (T-Shirt - Men's/Straight Cut Size L)"
 
      currency: USD
...
 
@@ -194,5 +196,7 @@
 
      tickets_sold: !!python/object/apply:decimal.Decimal ["1"]
 
      ticket_rate: !!python/object/apply:decimal.Decimal ["21.25"]
 
      ticket_price: !!python/object/apply:decimal.Decimal ["80.00"]
 
      ticket_rate: Early Bird (Ticket - Individual Supporter)
 
      shirts_sold: !!python/object/apply:decimal.Decimal ["1"]
 
      shirt_rate: !!python/object/apply:decimal.Decimal ["25.50"]
 
      shirt_price: !!python/object/apply:decimal.Decimal ["0"]
 
      shirt_rate: "Complimentary for ticket holder (Supporter-level and above) (T-Shirt - Men's/Straight Cut Size L)"
 
      currency: USD
...
 
@@ -212,5 +216,7 @@
 
      tickets_sold: !!python/object/apply:decimal.Decimal ["1"]
 
      ticket_rate: !!python/object/apply:decimal.Decimal ["42.50"]
 
      ticket_price: !!python/object/apply:decimal.Decimal ["50.00"]
 
      ticket_rate: Ticket - Unaffiliated Individual
 
      shirts_sold: !!python/object/apply:decimal.Decimal ["0"]
 
      shirt_rate: !!python/object/apply:decimal.Decimal ["25.50"]
 
      shirt_price: !!python/object/apply:decimal.Decimal ["0"]
 
      shirt_rate: ""
 
      status: Invoice
...
 
@@ -224,5 +230,7 @@
 
      tickets_sold: !!python/object/apply:decimal.Decimal ["1"]
 
      ticket_rate: !!python/object/apply:decimal.Decimal ["42.50"]
 
      ticket_price: !!python/object/apply:decimal.Decimal ["50.00"]
 
      ticket_rate: Ticket - Unaffiliated Individual
 
      shirts_sold: !!python/object/apply:decimal.Decimal ["0"]
 
      shirt_rate: !!python/object/apply:decimal.Decimal ["25.50"]
 
      shirt_price: !!python/object/apply:decimal.Decimal ["0"]
 
      shirt_rate: ""
 
      status: Payment
...
 
@@ -242,5 +250,7 @@
 
      tickets_sold: !!python/object/apply:decimal.Decimal ["0"]
 
      ticket_rate: !!python/object/apply:decimal.Decimal ["42.50"]
 
      ticket_price: !!python/object/apply:decimal.Decimal ["0"]
 
      ticket_rate: Ticket - Talk Proposer
 
      shirts_sold: !!python/object/apply:decimal.Decimal ["2"]
 
      shirt_rate: !!python/object/apply:decimal.Decimal ["25.50"]
 
      shirt_price: !!python/object/apply:decimal.Decimal ["30.00"]
 
      shirt_rate: "T-Shirt - Men's/Straight Cut Size M"
 
      status: Invoice
...
 
@@ -254,5 +264,7 @@
 
      tickets_sold: !!python/object/apply:decimal.Decimal ["0"]
 
      ticket_rate: !!python/object/apply:decimal.Decimal ["42.50"]
 
      ticket_price: !!python/object/apply:decimal.Decimal ["0"]
 
      ticket_rate: Ticket - Talk Proposer
 
      shirts_sold: !!python/object/apply:decimal.Decimal ["2"]
 
      shirt_rate: !!python/object/apply:decimal.Decimal ["25.50"]
 
      shirt_price: !!python/object/apply:decimal.Decimal ["30.00"]
 
      shirt_rate: "T-Shirt - Men's/Straight Cut Size M"
 
      status: Payment
0 comments (0 inline, 0 general)