Commit b52d05a1 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_accounting: get BalanceAmount from Subscription List

   Use subscription_list to calculate Balance amount for the ledger, currency, section from the list. It keeps consistency with the Entity_createDepositPaymentTransaction implementation.
parent 31fdae73
portal = context.getPortalObject()
# Ensure all invoice use the same arrow and resource
first_subscription = subscription_list[0]
identical_dict = {
'getSourceSection': first_subscription.getSourceSection(),
'getDestinationSection': first_subscription.getDestinationSection(),
'getPriceCurrency': first_subscription.getPriceCurrency(),
'getLedger': first_subscription.getLedger(),
}
for subscription in subscription_list:
for method_id, method_value in identical_dict.items():
if getattr(subscription, method_id)() != method_value:
raise ValueError('Subscription Requests do not match on method: %s' % method_id)
if subscription.getPortalType() != "Subscription Request":
raise ValueError('Not an Subscription Request')
assert_price_kw = {
'resource_uid': currency_uid,
'resource_uid': first_subscription.getPriceCurrencyUid(),
'portal_type': portal.getPortalAccountingMovementTypeList(),
'ledger_uid': portal.portal_categories.ledger.automated.getUid(),
'ledger_uid': first_subscription.getLedgerUid(),
}
if first_subscription.getDestinationSection() != context.getRelativeUrl():
raise ValueError("Subscription not related to the context")
# entity is the depositor
# mirror_section_uid is the payee/recipient
entity_uid = context.getUid()
mirror_section_uid = first_subscription.getSourceSectionUid()
# Total received
deposit_amount = portal.portal_simulation.getInventoryAssetPrice(
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>currency_uid, mirror_section_uid</string> </value>
<value> <string>subscription_list, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -459,7 +459,8 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin):
def test_deposit_with_accounting_scenario(self):
currency, _, _, _ = self.bootstrapVirtualMasterTest(is_virtual_master_accountable=True)
currency, seller_organisation, _, _ = \
self.bootstrapVirtualMasterTest(is_virtual_master_accountable=True)
self.logout()
# lets join as slapos administrator, which will own few compute_nodes
......@@ -479,28 +480,32 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin):
# to check if other services are ok
total_price = 1234
# Action to submit project subscription
def wrapWithShadow(person, total_price, currency):
# pre-include a large amount of w/o any subscription request using a temp
# object. It requires to be created under shadow user for security reasons.
tmp_subscription_request = self.portal.portal_trash.newContent(
def createTempSubscription(person, source_section, total_price, currency):
return self.portal.portal_trash.newContent(
portal_type='Subscription Request',
temp_object=True,
start_date=DateTime(),
source_section=source_section,
destination_value=person,
destination_section_value=person,
ledger_value=self.portal.portal_categories.ledger.automated,
price_currency=currency,
total_price=total_price
)
# Action to submit project subscription
def wrapWithShadow(person, source_section, total_price, currency):
# pre-include a large amount of w/o any subscription request using a temp
# object. It requires to be created under shadow user for security reasons.
tmp_subscription_request = createTempSubscription(person, source_section, total_price, currency)
return person.Entity_createDepositPaymentTransaction([tmp_subscription_request])
payment_transaction = owner_person.Person_restrictMethodAsShadowUser(
shadow_document=owner_person,
callable_object=wrapWithShadow,
argument_list=[owner_person, total_price, currency.getRelativeUrl()])
argument_list=[owner_person, seller_organisation.getRelativeUrl(),
total_price, currency.getRelativeUrl()])
self.tic()
self.logout()
......@@ -512,10 +517,11 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin):
assert payment_transaction.receivable.getGroupingReference(None) is not None
# Check if the Deposit lead to proper balance.
tmp_subscription_request = createTempSubscription(
owner_person, seller_organisation.getRelativeUrl(), total_price, currency.getRelativeUrl())
self.assertEqual(
owner_person.Entity_getDepositBalanceAmount(
currency_uid=currency.getUid(),
mirror_section_uid=payment_transaction.getSourceSectionUid()),
owner_person.Entity_getDepositBalanceAmount([tmp_subscription_request]),
total_price)
self.checkERP5StateBeforeExit()
......
......@@ -34,9 +34,7 @@ total_price = subscription_request.getTotalPrice()
if 0 < total_price:
customer = subscription_request.getDestinationSectionValue()
balance = customer.Entity_getDepositBalanceAmount(
subscription_request.getPriceCurrencyUid(),
subscription_request.getSourceSectionUid())
balance = customer.Entity_getDepositBalanceAmount([subscription_request])
# XXX what is the guarantee deposit account_type?
if balance < total_price:
......
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