Commit d9461ebe authored by Romain Courteaud's avatar Romain Courteaud

slapos_accounting: test: fix create payment tests

parent 416b3627
......@@ -6,8 +6,11 @@ portal = context.getPortalObject()
if not invoice_list:
raise ValueError('You need to provide at least one Invoice transaction')
payment_tag = 'Entity_createPaymentTransaction_%s' % context.getUid()
if context.REQUEST.get(payment_tag, None) is not None:
raise ValueError('This script was already called twice on the same transaction ')
activate_kw = {
'tag': 'Entity_createPaymentTransaction_%s' % context.getUid()
'tag': payment_tag
}
# Ensure all invoice use the same arrow and resource
......@@ -40,6 +43,9 @@ if not price:
if first_invoice.getDestinationSection() != context.getRelativeUrl():
raise ValueError('Invoice not related to the context')
if start_date is None:
start_date = DateTime()
# create the payment transaction
payment_transaction = portal.accounting_module.newContent(
portal_type='Payment Transaction',
......@@ -49,8 +55,8 @@ payment_transaction = portal.accounting_module.newContent(
source_payment=first_invoice.getSourcePayment(),
destination_section=first_invoice.getDestinationSection(),
destination_section_value=context,
start_date=DateTime(),
#payment_mode=,
start_date=start_date,
payment_mode=payment_mode,
#specialise
ledger=first_invoice.getLedger(),
resource=first_invoice.getResource(),
......@@ -82,5 +88,11 @@ for index, line in enumerate(invoice_list):
activate_kw=activate_kw,
)
payment_transaction.stop()
assert len(payment_transaction.checkConsistency()) == 0
payment_transaction.start()
# Set a flag on the request for prevent 2 calls on the same transaction
context.REQUEST.set(payment_tag, 1)
return payment_transaction
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>invoice_list, destination_administration=None, REQUEST=None</string> </value>
<value> <string>invoice_list, destination_administration=None, payment_mode=None, start_date=None, REQUEST=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -25,10 +25,9 @@ payment_transaction = context.Entity_createPaymentTransaction(
resource_uid=outstanding_amount.getPriceCurrencyUid(),
ledger_uid=outstanding_amount.getLedgerUid(),
group_by_node=False
)
)
payment_transaction.edit(
),
start_date=date,
payment_mode=payment_mode
)
payment_transaction.stop()
return payment_transaction.Base_redirect()
......@@ -183,6 +183,7 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
group_by_node=False
)
)
payment_transaction.stop()
self.assertEquals(payment_transaction.AccountingTransaction_getTotalCredit(), 74.78399999999999)
self.tic()
self.assertTrue(owner_person.Entity_hasOutstandingAmount())
......@@ -197,6 +198,9 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
# Ensure no unexpected object has been created
self.assertRelatedObjectCount(project, 22)
payment_tag = "Entity_createPaymentTransaction_%s" % owner_person.getUid()
owner_person.REQUEST.set(payment_tag, None)
payment_transaction = owner_person.Entity_createPaymentTransaction(
owner_person.Entity_getOutstandingAmountList(
include_planned=False,
......@@ -206,6 +210,7 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
group_by_node=False
)
)
payment_transaction.stop()
self.assertEquals(payment_transaction.AccountingTransaction_getTotalCredit(), 50.4)
self.tic()
self.assertTrue(owner_person.Entity_hasOutstandingAmount())
......
......@@ -33,7 +33,8 @@ class TestSlapOSEntityCreatePaymentMixin(SlapOSTestCaseMixin):
portal_type="Bank Account"
)
currency = self.portal.currency_module.newContent(
portal_type="Currency"
portal_type="Currency",
base_unit_quantity=0.1
)
if person is None:
person = self.portal.person_module.template_member\
......@@ -95,31 +96,29 @@ class TestSlapOSEntityCreatePaymentMixin(SlapOSTestCaseMixin):
expected_set = [
'causality/%s' % invoice.getRelativeUrl(),
'destination_section/%s' % invoice.getDestinationSection(),
'destination_project/%s' % invoice.getDestinationProject(),
'price_currency/%s' % invoice.getPriceCurrency(),
'resource/%s' % invoice.getResource(),
'resource/%s' % invoice.getPriceCurrency(),
'source_payment/%s' % invoice.getSourcePayment(),
'payment_mode/%s' % self.payment_mode,
'source_section/%s' % invoice.getSourceSection(),
#'source_project/%s' % invoice.getSourceProject(),
'ledger/%s' % invoice.getLedger(),
]
self.assertSameSet(expected_set, payment.getCategoryList())
self.assertEqual(invoice.getStartDate(), payment.getStartDate())
self.assertEqual(invoice.getStopDate(), payment.getStopDate())
self.assertEqual(invoice.getStartDate(), payment.getStopDate())
invoice_movement_list = invoice.getMovementList()
movement_list = payment.getMovementList()
self.assertEqual(2, len(movement_list))
bank_list = [q for q in movement_list
if q.getSource() == 'account_module/payment_to_encash']
rec_list = [q for q in movement_list
if q.getSource() == 'account_module/receivable']
self.assertEqual(1, len(bank_list))
self.assertEqual(1, len(rec_list))
self.assertEqual(len([q for q in invoice_movement_list
if q.getSource() == 'account_module/receivable']), len(rec_list))
def assertLine(line, quantity, category_list):
self.assertTrue(line.hasStartDate())
self.assertTrue(line.hasStopDate())
self.assertFalse(line.hasStartDate())
self.assertFalse(line.hasStopDate())
self.assertEqual(quantity, line.getQuantity())
self.assertSameSet(category_list, line.getCategoryList())
......@@ -127,18 +126,25 @@ class TestSlapOSEntityCreatePaymentMixin(SlapOSTestCaseMixin):
assertLine(bank_list[0], invoice_amount, [
'destination/account_module/payment_to_encash',
'source/account_module/payment_to_encash'])
assertLine(rec_list[0], -1 * invoice_amount, [
'destination/account_module/payable',
'source/account_module/receivable'])
for rec in rec_list:
assertLine(rec, -invoice_amount / len(rec_list), [
'destination/account_module/payable',
'source/account_module/receivable'])
def fullBuild(self, person, invoice_list):
payment = person.Entity_createPaymentTransaction(invoice_list)
payment = person.Entity_createPaymentTransaction(person.Entity_getOutstandingAmountList(
include_planned=False,
section_uid=invoice_list[0].getSourceSectionUid(),
resource_uid=invoice_list[0].getPriceCurrencyUid(),
ledger_uid=invoice_list[0].getLedgerUid(),
group_by_node=False
), payment_mode=self.payment_mode, start_date=invoice_list[0].getStartDate())
self.assertNotEqual(None, payment)
return payment
def resetPaymentTag(self, invoice):
payment_tag = "sale_invoice_transaction_create_payment_%s" % invoice.getUid()
invoice.REQUEST.set(payment_tag, None)
def resetPaymentTag(self, person):
payment_tag = "Entity_createPaymentTransaction_%s" % person.getUid()
person.REQUEST.set(payment_tag, None)
def _test(self):
person, invoice = self.makeSaleInvoiceTransaction()
......@@ -157,7 +163,7 @@ class TestSlapOSEntityCreatePaymentMixin(SlapOSTestCaseMixin):
payment = self.fullBuild(person, [invoice])
self.assertPayment(payment, invoice)
self.tic()
self.resetPaymentTag(invoice)
self.resetPaymentTag(person)
# Create twice, generate 2 payments
payment = self.fullBuild(person, [invoice])
......@@ -181,7 +187,7 @@ class TestSlapOSEntityCreatePaymentMixin(SlapOSTestCaseMixin):
payment = self.fullBuild(person, [invoice])
self.commit()
# Request was over, so emulate start a new one
self.resetPaymentTag(invoice)
self.resetPaymentTag(person)
# Should we take into account that a payment is ongoing?
payment2 = self.fullBuild(person, [invoice])
......@@ -198,7 +204,7 @@ class TestSlapOSEntityCreatePaymentMixin(SlapOSTestCaseMixin):
payment = self.fullBuild(person, [invoice])
payment.cancel()
self.tic()
self.resetPaymentTag(invoice)
self.resetPaymentTag(person)
payment = self.fullBuild(person, [invoice])
self.tic()
......@@ -212,8 +218,9 @@ class TestSlapOSEntityCreatePaymentMixin(SlapOSTestCaseMixin):
invoice_2.confirm()
invoice_2.stop()
self.tic()
payment_list = [self.fullBuild(person, [invoice_1]),
self.fullBuild(person, [invoice_2])]
payment_list = [self.fullBuild(person, [invoice_1])]
self.resetPaymentTag(person)
payment_list.append(self.fullBuild(person, [invoice_2]))
self.tic()
self.assertEqual(2, len(payment_list))
......
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