Commit 5f8ac014 authored by Jérome Perrin's avatar Jérome Perrin

payment_mean(_sepa): generate reference when grouping

For SEPA files "End to End ID" we need a reference on payment transactions.
In the first prototype, the reference was set at the time of generating the
file, but it's a non common behaviour to generate reference when producing
reports, so we changed to ensuring payment has reference when adding to the
group.
parent 380229bf
"""Adds the payment transaction group to the already aggregated items on this line. """Adds the payment transaction group to the already aggregated items on this line.
This script has a proxy role to be able to modify delivered lines Also ensures that the payment transaction has a reference.
This script has a proxy role to be able to modify delivered lines and to call generateReference.
""" """
portal = context.getPortalObject() portal = context.getPortalObject()
...@@ -8,3 +10,4 @@ assert context.getPortalType() in portal.getPortalAccountingMovementTypeList() ...@@ -8,3 +10,4 @@ assert context.getPortalType() in portal.getPortalAccountingMovementTypeList()
context.setDefaultActivateParameterDict({"activate_kw": activate_kw}) context.setDefaultActivateParameterDict({"activate_kw": activate_kw})
context.setAggregate(aggregate, portal_type='Payment Transaction Group') context.setAggregate(aggregate, portal_type='Payment Transaction Group')
context.getParentValue().getTypeBasedMethod('generateReference')()
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
<value> <value>
<tuple> <tuple>
<string>Manager</string> <string>Manager</string>
<string>Owner</string>
</tuple> </tuple>
</value> </value>
</item> </item>
......
...@@ -283,3 +283,40 @@ class TestPaymentTransactionGroupPaymentSelection(AccountingTestCase): ...@@ -283,3 +283,40 @@ class TestPaymentTransactionGroupPaymentSelection(AccountingTestCase):
for line in line_list if not line.is_title_line]), for line in line_list if not line.is_title_line]),
[(0, 'Client 1', 100.0), (0, 'Client 2', 200.0), (1, None, 300.0)], [(0, 'Client 1', 100.0), (0, 'Client 2', 200.0), (1, None, 300.0)],
) )
def test_adding_to_payment_transaction_set_reference(self):
account_module = self.account_module
payment = self._makeOne(
portal_type='Payment Transaction',
simulation_state='delivered',
source_section_value=self.main_section,
source_payment_value=self.bank_account,
payment_mode_value=self.portal.portal_categories.payment_mode.cash,
resource_value=self.portal.currency_module.euro,
destination_section_value=self.organisation_module.client_1,
start_date=DateTime(2014, 1, 1),
lines=(
dict(
source_value=account_module.bank,
source_debit=100,
id='bank'),
dict(
source_value=account_module.receivable,
source_credit=100)))
self.tic()
self.assertFalse(payment.getReference())
ptg = self.portal.payment_transaction_group_module.newContent(
portal_type='Payment Transaction Group',
source_section_value=self.main_section,
source_payment_value=self.bank_account,
payment_mode_value=self.portal.portal_categories.payment_mode.cash,
price_currency_value=self.portal.currency_module.euro,
stop_date=DateTime(2014, 1, 31),)
self.tic()
ptg.PaymentTransactionGroup_selectPaymentTransactionLineList(mode='stopped_or_delivered')
self.tic()
self.assertEqual(
payment.bank.getAggregateValueList(),
[ptg])
self.assertTrue(payment.getReference())
...@@ -59,7 +59,8 @@ for brain in context.PaymentTransactionGroup_getAccountingTransactionLineList(): ...@@ -59,7 +59,8 @@ for brain in context.PaymentTransactionGroup_getAccountingTransactionLineList():
assert creditor_bank_account.getValidationState() == 'validated', \ assert creditor_bank_account.getValidationState() == 'validated', \
'%s is not validated' % creditor_bank_account.getRelativeUrl() '%s is not validated' % creditor_bank_account.getRelativeUrl()
end_to_end_id = transaction.PaymentTransaction_getOrGenerateReference() end_to_end_id = transaction.getReference()
assert end_to_end_id
assert end_to_end_id not in end_to_end_id_set assert end_to_end_id not in end_to_end_id_set
end_to_end_id_set.add(end_to_end_id) end_to_end_id_set.add(end_to_end_id)
......
"""Returns an unique reference for this payment transaction. If it does not already have a reference, a new one is generated.
"""
context.getTypeBasedMethod('generateReference')()
return context.getReference()
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>PaymentTransaction_getOrGenerateReference</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -52,7 +52,7 @@ class TestPaymentTransactionGroupPaymentSEPA(AccountingTestCase): ...@@ -52,7 +52,7 @@ class TestPaymentTransactionGroupPaymentSEPA(AccountingTestCase):
) )
self.tic() self.tic()
def _createPaymentsAndPTG(self): def _createPTG(self):
ptg = self.portal.payment_transaction_group_module.newContent( ptg = self.portal.payment_transaction_group_module.newContent(
portal_type='Payment Transaction Group', portal_type='Payment Transaction Group',
source_section_value=self.section, source_section_value=self.section,
...@@ -82,10 +82,11 @@ class TestPaymentTransactionGroupPaymentSEPA(AccountingTestCase): ...@@ -82,10 +82,11 @@ class TestPaymentTransactionGroupPaymentSEPA(AccountingTestCase):
bic_code='TESTXXXX' bic_code='TESTXXXX'
) )
bank_account_supplier1.validate() bank_account_supplier1.validate()
payment_1 = self._makeOne( self._makeOne(
portal_type='Payment Transaction', portal_type='Payment Transaction',
simulation_state='delivered', simulation_state='delivered',
title='one', title='one',
reference='PT-1',
causality_value=invoice_1, causality_value=invoice_1,
source_section_value=self.section, source_section_value=self.section,
source_payment_value=self.bank_account, source_payment_value=self.bank_account,
...@@ -112,10 +113,11 @@ class TestPaymentTransactionGroupPaymentSEPA(AccountingTestCase): ...@@ -112,10 +113,11 @@ class TestPaymentTransactionGroupPaymentSEPA(AccountingTestCase):
) )
bank_account_supplier2.validate() bank_account_supplier2.validate()
payment_2 = self._makeOne( self._makeOne(
portal_type='Payment Transaction', portal_type='Payment Transaction',
simulation_state='delivered', simulation_state='delivered',
title='two', title='two',
reference='PT-2',
destination_section_value=self.section, destination_section_value=self.section,
destination_payment_value=self.bank_account, destination_payment_value=self.bank_account,
source_section_value=supplier2, source_section_value=supplier2,
...@@ -130,10 +132,10 @@ class TestPaymentTransactionGroupPaymentSEPA(AccountingTestCase): ...@@ -130,10 +132,10 @@ class TestPaymentTransactionGroupPaymentSEPA(AccountingTestCase):
destination_credit=200, destination_credit=200,
aggregate_value=ptg))) aggregate_value=ptg)))
self.tic() self.tic()
return payment_1, payment_2, ptg return ptg
def test_PaymentTransactionGroup_viewAsSEPACreditTransferPain_001_001_02(self): def test_PaymentTransactionGroup_viewAsSEPACreditTransferPain_001_001_02(self):
payment_1, payment_2, ptg = self._createPaymentsAndPTG() ptg = self._createPTG()
pain = lxml.etree.fromstring( pain = lxml.etree.fromstring(
getattr(ptg, 'PaymentTransactionGroup_viewAsSEPACreditTransferPain.001.001.02')().encode('utf-8')) getattr(ptg, 'PaymentTransactionGroup_viewAsSEPACreditTransferPain.001.001.02')().encode('utf-8'))
...@@ -192,16 +194,14 @@ class TestPaymentTransactionGroupPaymentSEPA(AccountingTestCase): ...@@ -192,16 +194,14 @@ class TestPaymentTransactionGroupPaymentSEPA(AccountingTestCase):
['INVOICE1 Supplier1', 'Supplier2'], ['INVOICE1 Supplier1', 'Supplier2'],
) )
# generating the XML file set reference on payment transactions
self.assertTrue(payment_1.getReference())
self.assertTrue(payment_2.getReference())
self.assertEqual( self.assertEqual(
sorted([node.text for node in pain.findall('.//{*}CdtTrfTxInf/{*}PmtId/{*}EndToEndId')]), sorted([node.text for node in pain.findall('.//{*}CdtTrfTxInf/{*}PmtId/{*}EndToEndId')]),
sorted([payment_1.getReference(), payment_2.getReference()]), ['PT-1', 'PT-2'],
) )
def test_generate_sepa_credit_transfer_action(self): def test_generate_sepa_credit_transfer_action(self):
_, _, ptg = self._createPaymentsAndPTG() ptg = self._createPTG()
ret = ptg.PaymentTransactionGroup_generateSEPACreditTransferFile( ret = ptg.PaymentTransactionGroup_generateSEPACreditTransferFile(
version='pain.001.001.02') version='pain.001.001.02')
self.assertEqual( self.assertEqual(
......
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