Commits

Jason R. Coombs committed a3eebf1

Add support for shared residuals

Comments (0)

Files changed (2)

jaraco/financial/ledger.py

 	def add(self, item):
 		bisect.insort_right(self, item)
 
+	@property
+	def balance(self):
+		return sum(txn.amount for txn in self)
+
 class Named(object):
 	def __init__(self, name, *args, **kwargs):
 		super(Named, self).__init__(*args, **kwargs)

jaraco/financial/merchant.py

 A collection of Merchant-processing routines for Cornerstone, LLC.
 """
 
-from __future__ import print_function, unicode_literals
+from __future__ import print_function, unicode_literals, division
 
 import re
 import collections
 					)
 				txn = ledger.Transaction(date=date,
 					designation=designation)
+				txn.source = 'ISO statement'
+				if txn in agent_lgr:
+					# skip transactions that are already an exact match
+					print('.', end='')
+					continue
 				agent_lgr.add(txn)
+				# pay share to Cornerstone
+				designation = ledger.SimpleDesignation(
+					descriptor = "Residuals Shared : " + unicode(merchant),
+					amount = -txn.amount / 2,
+				)
+				txn = ledger.Transaction(date=date,
+					designation=designation)
+				txn.source = 'calculated'
+				agent_lgr.add(txn)
+
 	with open('portfolio.pickle', 'wb') as pfp:
 		pickle.dump(portfolio, pfp, protocol=pickle.HIGHEST_PROTOCOL)