Created
December 13, 2016 10:39
-
-
Save mianos/f6b5bacc6fde8f685eee7156da1a5a71 to your computer and use it in GitHub Desktop.
Dispatch on value examples on how to use account names to dispatch.
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
import sys | |
sys.path.append('dispatch-on-value-for-python') | |
import dispatchonvalue as dispatchonvalue | |
# Register your overloaded functions: | |
class abc: | |
dispatch_on_value = dispatchonvalue.DispatchOnValue() | |
@classmethod | |
def dispatch(cls, pattern, *args, **kwargs): | |
cls.dispatch_on_value.dispatch(pattern, cls, *args, **kwargs) | |
@dispatch_on_value.add_method({ | |
'account_type': 'bill', | |
'counterparty_account_type': 'pu', | |
'float': False | |
}) | |
def _(disp, pattern, cls, a, *args, **kwargs): | |
print "billing to unallocated no float", pattern | |
@dispatch_on_value.add_method({ | |
'account_type': 'bill', | |
'counterparty_account_type': 'pu', | |
'float': True | |
}) | |
def _(disp, pattern, cls, a, *args, **kwargs): | |
print "billing to unallocated WITH float", pattern | |
@dispatch_on_value.add_method({ | |
'account_type': 'spend', | |
'counterparty_account_type': 'system' | |
}) | |
def _(disp, pattern, cls, a, *args, **kwargs): | |
print "on market", pattern | |
@dispatch_on_value.add_method({ | |
'account_type': 'spend', | |
'counterparty_account_type': 'pu', | |
}) | |
def _(disp, pattern, cls, a, *args, **kwargs): | |
print "return money spend to wallet" | |
r = abc.dispatch({ | |
'account_type': 'bill', | |
'counterparty_account_type': 'pu', | |
'account': 'Rob Bank', | |
'counterparty_account': 'Rob Unallocated', | |
'float': False | |
}, 123) | |
r = abc.dispatch({ | |
'account_type': 'bill', | |
'counterparty_account_type': 'pu', | |
'account': 'Rob Bank', | |
'counterparty_account': 'Rob Unallocated', | |
'float': True | |
}, 123) | |
r = abc.dispatch({ | |
'account_type': 'spend', | |
'counterparty_account_type': 'system', | |
'account': 'Rob Card', | |
'counterparty_account': 'Indue Market', | |
'float': True | |
}, 123) | |
r = abc.dispatch({ | |
'account_type': 'spend', | |
'counterparty_account_type': 'pu', | |
'account': 'Rob Card', | |
'counterparty_account': 'Rob Wallet', | |
}, 123) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment