Commit f1dfe71b authored by Vincent Pelletier's avatar Vincent Pelletier

Use BankAccount_getAvailablePosition to factorise code.

Also, serialise bank account when checking if an operation can happen,
so it doesn't have to be done in each caller script.
This should not be a performance problem to serialise multiple time the
same account per transaction, and BankAccount_checkBalance should
only be called when there is an intent to withdraw cash from the account.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@41551 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e465b414
...@@ -76,19 +76,16 @@ payment_value = context.restrictedTraverse(payment)\n ...@@ -76,19 +76,16 @@ payment_value = context.restrictedTraverse(payment)\n
if not payment_value.BankAccount_isOpened():\n if not payment_value.BankAccount_isOpened():\n
return {\'error_code\':2} # closed account\n return {\'error_code\':2} # closed account\n
\n \n
resource = payment_value.getPriceCurrencyValue()\n account_balance = payment_value.BankAccount_getAvailablePosition(src__=src__)\n
\n if src__:\n
if resource is None :\n return account_balance\n
raise AttributeError, \'No currency defined on %s\' % payment\n # XXX: BankAccount_getAvailablePosition returns position as a string for some reason...\n
\n account_balance = float(account_balance)\n
# Next, check the balance of the account\n
account_balance = resource.getAvailableInventory(payment=payment, src__=src__)\n
if src__ :\n
return account_balance \n
\n \n
if account_balance - quantity < 0 :\n if account_balance - quantity < 0 :\n
return {\'error_code\':1, \'balance\':account_balance} # insufficient balance\n return {\'error_code\':1, \'balance\':account_balance} # insufficient balance\n
\n \n
payment_value.serialize()\n
return {\'error_code\':0, \'balance\':account_balance} # ok\n return {\'error_code\':0, \'balance\':account_balance} # ok\n
...@@ -148,10 +145,8 @@ return {\'error_code\':0, \'balance\':account_balance} # ok\n ...@@ -148,10 +145,8 @@ return {\'error_code\':0, \'balance\':account_balance} # ok\n
<string>_getattr_</string> <string>_getattr_</string>
<string>context</string> <string>context</string>
<string>payment_value</string> <string>payment_value</string>
<string>resource</string>
<string>None</string>
<string>AttributeError</string>
<string>account_balance</string> <string>account_balance</string>
<string>float</string>
</tuple> </tuple>
</value> </value>
</item> </item>
......
546 547
\ No newline at end of file \ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment