Skip to content

Commit

Permalink
Refactor #2: Money out
Browse files Browse the repository at this point in the history
I refactored money out, namely:

1. Made naming more consistent (e.g. "debt" to "amount" for numerical
   quantitiest that are not a Debt object).
2. Added a utility for automatically setting the right types when
   reading a model from CSV.
3. Simplified message formatting.
4. Added a constant for decimal precision.

My editor automatically formatted everything with Black, I'm not sure
if we are ok with that, let me know and I can figure out how to disable
that.
  • Loading branch information
Jair Trejo committed Jun 13, 2024
1 parent a620af0 commit aed9022
Show file tree
Hide file tree
Showing 4 changed files with 251 additions and 162 deletions.
30 changes: 17 additions & 13 deletions oldabe/constants.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import os

ABE_ROOT = './abe'
PAYOUTS_DIR = os.path.join(ABE_ROOT, 'payouts')
PAYMENTS_DIR = os.path.join(ABE_ROOT, 'payments')
ABE_ROOT = "./abe"
PAYOUTS_DIR = os.path.join(ABE_ROOT, "payouts")
PAYMENTS_DIR = os.path.join(ABE_ROOT, "payments")
NONATTRIBUTABLE_PAYMENTS_DIR = os.path.join(
ABE_ROOT, 'payments', 'nonattributable'
ABE_ROOT, "payments", "nonattributable"
)

TRANSACTIONS_FILE = os.path.join(ABE_ROOT, 'transactions.txt')
DEBTS_FILE = os.path.join(ABE_ROOT, 'debts.txt')
ADVANCES_FILE = os.path.join(ABE_ROOT, 'advances.txt')
UNPAYABLE_CONTRIBUTORS_FILE = os.path.join(ABE_ROOT, 'unpayable_contributors.txt')
ITEMIZED_PAYMENTS_FILE = os.path.join(ABE_ROOT, 'itemized_payments.txt')
PRICE_FILE = os.path.join(ABE_ROOT, 'price.txt')
VALUATION_FILE = os.path.join(ABE_ROOT, 'valuation.txt')
ATTRIBUTIONS_FILE = 'attributions.txt'
INSTRUMENTS_FILE = 'instruments.txt'
TRANSACTIONS_FILE = os.path.join(ABE_ROOT, "transactions.txt")
DEBTS_FILE = os.path.join(ABE_ROOT, "debts.txt")
ADVANCES_FILE = os.path.join(ABE_ROOT, "advances.txt")
UNPAYABLE_CONTRIBUTORS_FILE = os.path.join(
ABE_ROOT, "unpayable_contributors.txt"
)
ITEMIZED_PAYMENTS_FILE = os.path.join(ABE_ROOT, "itemized_payments.txt")
PRICE_FILE = os.path.join(ABE_ROOT, "price.txt")
VALUATION_FILE = os.path.join(ABE_ROOT, "valuation.txt")
ATTRIBUTIONS_FILE = "attributions.txt"
INSTRUMENTS_FILE = "instruments.txt"

DECIMAL_PRECISION = 10
20 changes: 20 additions & 0 deletions oldabe/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
from datetime import datetime
from dataclasses import dataclass, field
from decimal import Decimal
import re


def row_to_model(row, model):
for field_, value in row.items():
field_type = getattr(model, field_).annotation
if field_type == Decimal:
row[field_] = Decimal(re.sub("[^0-9.]", "", value))
elif field_type == datetime:
row[field_] = datetime.fromisoformat(value)

return model(**row)


@dataclass
Expand Down Expand Up @@ -74,3 +86,11 @@ class Attribution:
email: str = None
share: Decimal = 0
dilutable: bool = True


@dataclass
class Payout:
name: str = None
email: str = None
amount: Decimal = 0
date: datetime = field(default_factory=datetime.utcnow)
Loading

0 comments on commit aed9022

Please sign in to comment.