Commit 4c608567 authored by Jérome Perrin's avatar Jérome Perrin

accounting_l10n_fr: fix ValidDate computation for FEC

According to https://www.legifrance.gouv.fr/codes/article_lc/LEGIARTI000027804775/
ValidDate is the date when the transaction was validated ( "16. La date
de validation de l'écriture comptable"), this implementation was simply
returning the modification date, which was not always correct, for
example after causality state was recaculated.

This keeps the `getModificationDate` fallback for cases where FEC is
used with some non validated transactions, in order to keep compatibility
parent 2c17315c
Pipeline #27174 failed with stage
"""Returns the date when the `deliver` transaction was passed"""
portal = context.getPortalObject()
getInfoFor = portal.portal_workflow.getInfoFor
for wf_id in context.getTypeInfo().getTypeWorkflowList():
for item in getInfoFor(context, 'history', wf_id=wf_id, default=[]):
if item['action'] == 'deliver':
return item['time']
return context.getModificationDate()
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</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>AccountingTransaction_getDeliverDate</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<PieceDate tal:content="python: context.getStopDate().strftime('%Y-%m-%d')"></PieceDate> <PieceDate tal:content="python: context.getStopDate().strftime('%Y-%m-%d')"></PieceDate>
<tal:block tal:replace="nothing"><EcritureLet></EcritureLet> <tal:block tal:replace="nothing"><EcritureLet></EcritureLet>
<DateLet></DateLet></tal:block> <DateLet></DateLet></tal:block>
<ValidDate tal:content="python: context.getModificationDate().strftime('%Y-%m-%d')">Modification Date</ValidDate> <ValidDate tal:content="python: context.AccountingTransaction_getDeliverDate().strftime('%Y-%m-%d')">Modification Date</ValidDate>
<tal:block tal:repeat="line python:context.contentValues(portal_type=context.getPortalAccountingMovementTypeList())"><ligne <tal:block tal:repeat="line python:context.contentValues(portal_type=context.getPortalAccountingMovementTypeList())"><ligne
tal:define="account python:line.getDestinationValue(portal_type='Account')" tal:condition="python: account is not None"> tal:define="account python:line.getDestinationValue(portal_type='Account')" tal:condition="python: account is not None">
<CompteNum tal:content="account/Account_getGapId">Reference Compte (Account_getGapId)</CompteNum> <CompteNum tal:content="account/Account_getGapId">Reference Compte (Account_getGapId)</CompteNum>
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<PieceDate tal:content="python: context.getStartDate().strftime('%Y-%m-%d')"></PieceDate> <PieceDate tal:content="python: context.getStartDate().strftime('%Y-%m-%d')"></PieceDate>
<tal:block tal:replace="nothing"><EcritureLet></EcritureLet> <tal:block tal:replace="nothing"><EcritureLet></EcritureLet>
<DateLet></DateLet></tal:block> <DateLet></DateLet></tal:block>
<ValidDate tal:content="python: context.getModificationDate().strftime('%Y-%m-%d')">Modification Date</ValidDate> <ValidDate tal:content="python: context.AccountingTransaction_getDeliverDate().strftime('%Y-%m-%d')">Modification Date</ValidDate>
<tal:block tal:repeat="line python:context.contentValues(portal_type=context.getPortalAccountingMovementTypeList())"><ligne <tal:block tal:repeat="line python:context.contentValues(portal_type=context.getPortalAccountingMovementTypeList())"><ligne
tal:define="account python:line.getSourceValue(portal_type='Account')" tal:condition="python: account is not None"> tal:define="account python:line.getSourceValue(portal_type='Account')" tal:condition="python: account is not None">
<CompteNum tal:content="account/Account_getGapId">Reference Compte (Account_getGapId)</CompteNum> <CompteNum tal:content="account/Account_getGapId">Reference Compte (Account_getGapId)</CompteNum>
......
...@@ -406,8 +406,32 @@ class TestAccounting_l10n_fr(AccountingTestCase): ...@@ -406,8 +406,32 @@ class TestAccounting_l10n_fr(AccountingTestCase):
self.assertEqual(3, len(credit_list)) self.assertEqual(3, len(credit_list))
self.assertEqual(185, sum([float(x.text) for x in credit_list])) self.assertEqual(185, sum([float(x.text) for x in credit_list]))
def test_ValidDate(self):
account_module = self.portal.account_module
invoice = self._makeOne(
portal_type='Purchase Invoice Transaction',
title='Première Écriture',
simulation_state='delivered',
reference='1',
source_section_value=self.organisation_module.supplier,
stop_date=DateTime(2014, 2, 2),
lines=(dict(destination_value=account_module.payable,
destination_debit=132.00),
dict(destination_value=account_module.refundable_vat,
destination_credit=22.00),
dict(destination_value=account_module.goods_purchase,
destination_credit=110.00)))
assert invoice.workflow_history['accounting_workflow'][-1]['action'] == 'deliver'
invoice.workflow_history['accounting_workflow'][-1]['time'] = DateTime(2001, 2, 3)
tree = etree.fromstring(invoice.AccountingTransaction_viewAsSourceFECXML())
self.assertEqual(tree.xpath('//ValidDate/text()'), ['2001-02-03'])
tree = etree.fromstring(invoice.AccountingTransaction_viewAsDestinationFECXML())
self.assertEqual(tree.xpath('//ValidDate/text()'), ['2001-02-03'])
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestAccounting_l10n_fr)) suite.addTest(unittest.makeSuite(TestAccounting_l10n_fr))
return suite return suite
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