-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from drym-org/debts-and-advances
Modeling Debts and Advances
- Loading branch information
Showing
25 changed files
with
1,377 additions
and
1,003 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
!/.github/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
#!/bin/sh -l | ||
#!/bin/bash | ||
|
||
# ensure that any errors encountered cause immediate | ||
# termination with a non-zero exit code | ||
set -e | ||
set -eo pipefail | ||
|
||
echo "PWD is: " | ||
echo $(pwd) | ||
|
@@ -23,21 +23,17 @@ echo "... done." | |
|
||
# Note that running this locally would cause your global | ||
# git config to be modified | ||
echo "Committing updated transactions and attributions back to repo..." | ||
echo "Committing updated accounting records back to repo..." | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "Old Abe" | ||
git add abe/transactions.txt abe/attributions.txt abe/valuation.txt abe/itemized_payments.txt | ||
git add abe/transactions.txt abe/attributions.txt abe/valuation.txt abe/itemized_payments.txt abe/advances.txt abe/debts.txt | ||
|
||
set +e | ||
|
||
git commit -m "Updated transactions and attributions" | ||
git commit -m "Updated accounting records" | ||
git fetch | ||
git rebase origin/`git remote set-head origin -a | cut -d' ' -f4` | ||
git push origin `git remote set-head origin -a | cut -d' ' -f4` | ||
echo "... done." | ||
|
||
set -e | ||
|
||
echo "Running money_out script..." | ||
echo balances=$(python -m oldabe.money_out) >> $GITHUB_OUTPUT | ||
echo "... done." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from decimal import Decimal | ||
|
||
ROUNDING_TOLERANCE = Decimal("0.000001") | ||
|
||
|
||
def get_rounding_difference(attributions): | ||
""" | ||
Get the difference of the total of the attributions from 1, which is | ||
expected to occur due to finite precision. If the difference exceeds the | ||
expected error tolerance, an error is signaled. | ||
""" | ||
total = _get_attributions_total(attributions) | ||
difference = total - Decimal("1") | ||
assert abs(difference) <= ROUNDING_TOLERANCE | ||
return difference | ||
|
||
|
||
def correct_rounding_error(attributions, incoming_attribution): | ||
"""Due to finite precision, the Decimal module will round up or down | ||
on the last decimal place. This could result in the aggregate value not | ||
quite totaling to 1. This corrects that total by either adding or | ||
subtracting the difference from the incoming attribution (by convention). | ||
""" | ||
difference = get_rounding_difference(attributions) | ||
attributions[incoming_attribution.email] -= difference | ||
|
||
|
||
def assert_attributions_normalized(attributions): | ||
print(_get_attributions_total(attributions)) | ||
assert _get_attributions_total(attributions) == Decimal("1") | ||
|
||
|
||
def _get_attributions_total(attributions): | ||
return sum(attributions.values()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import os | ||
from decimal import Decimal | ||
|
||
ACCOUNTING_ZERO = Decimal("0.01") | ||
|
||
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' | ||
) | ||
|
||
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 = os.path.join(ABE_ROOT, 'attributions.txt') | ||
INSTRUMENTS_FILE = os.path.join(ABE_ROOT, 'instruments.txt') |
Oops, something went wrong.