Commit b2a2c97c authored by Jérome Perrin's avatar Jérome Perrin

accounting_l10n_fr: Fixes for FEC

This change modifies the FEC export to conform to the test software from
https://www.economie.gouv.fr/dgfip/outil-test-des-fichiers-des-ecritures-comptables-fec 
/ https://github.com/DGFiP/Test-Compta-Demat.

A new `test_compta_demat_compatibility` to enable compatibility mode was introduced.
This will be True when rendering the report from the dialog, i.e., using `AccountingTransactionModule_viewFrenchAccountingTransactionFile` and False when
using `AccountingTransactionModule_viewFrenchAccountingTransactionFileActive` directly
so the behavior of reusing FEC export for accounting interfaces should be the same as before.


See merge request !1764
parents 7c24c322 827410dc
# coding: utf-8
from cStringIO import StringIO from cStringIO import StringIO
import zipfile import zipfile
from Products.ERP5Type.Message import translateString from Products.ERP5Type.Message import translateString
...@@ -11,11 +12,30 @@ result_list = active_process.getResultList() ...@@ -11,11 +12,30 @@ result_list = active_process.getResultList()
fec_file = context.AccountingTransactionModule_viewComptabiliteAsFECXML( fec_file = context.AccountingTransactionModule_viewComptabiliteAsFECXML(
at_date=at_date, at_date=at_date,
result_list=result_list) result_list=result_list)
if test_compta_demat_compatibility:
fec_file = (fec_file
# https://github.com/DGFiP/Test-Compta-Demat/issues/37
.replace(u"’", u"'")
.replace(u"Œ", u"OE")
.replace(u"œ", u"oe")
.replace(u"Ÿ", u"Y")
# https://github.com/DGFiP/Test-Compta-Demat/issues/39
.replace(u"€", u"EUR")
)
zipbuffer = StringIO() zipbuffer = StringIO()
zipfilename = at_date.strftime('FEC-%Y%m%d.zip') zipfilename = at_date.strftime('FEC-%Y%m%d.zip')
zipfileobj = zipfile.ZipFile(zipbuffer, 'w', compression=zipfile.ZIP_DEFLATED) zipfileobj = zipfile.ZipFile(zipbuffer, 'w', compression=zipfile.ZIP_DEFLATED)
zipfileobj.writestr('FEC.xml', fec_file.encode('utf8')) filename = 'FEC.xml'
if test_compta_demat_compatibility:
siren = ''
if section_uid_list:
siret_list = [b.getObject().getCorporateRegistrationCode() for b in portal.portal_catalog(uid=section_uid_list)]
siret_list = [siret for siret in siret_list if siret]
if len(siret_list) == 1:
siren = siret_list[0][:8]
filename = at_date.strftime('{siren}FEC%Y%m%d.xml').format(siren=siren)
zipfileobj.writestr(filename, fec_file.encode('utf8'))
zipfileobj.close() zipfileobj.close()
attachment_list = ( attachment_list = (
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>at_date, active_process, user_name</string> </value> <value> <string>at_date, active_process, user_name, test_compta_demat_compatibility, section_uid_list</string> </value>
</item> </item>
<item> <item>
<key> <string>_proxy_roles</string> </key> <key> <string>_proxy_roles</string> </key>
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<comptabilite xmlns:tal="http://xml.zope.org/namespaces/tal"> <comptabilite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="formatA47A-I-VII-1.xsd" xmlns:tal="http://xml.zope.org/namespaces/tal">
<exercice> <exercice>
<DateCloture tal:content="python: options['at_date'].strftime('%Y-%m-%d')">20141231</DateCloture> <DateCloture tal:content="python: options['at_date'].strftime('%Y-%m-%d')">20141231</DateCloture>
<tal:block tal:repeat="result options/result_list"><tal:block tal:replace="structure python: result.detail.decode('zlib')"/></tal:block> <tal:block tal:repeat="result options/result_list"><tal:block tal:replace="structure python: result.detail.decode('zlib')"/></tal:block>
......
...@@ -29,7 +29,9 @@ context.activate().AccountingTransactionModule_viewFrenchAccountingTransactionFi ...@@ -29,7 +29,9 @@ context.activate().AccountingTransactionModule_viewFrenchAccountingTransactionFi
tag=tag, tag=tag,
aggregate_tag=aggregate_tag, aggregate_tag=aggregate_tag,
date_column=date_column, date_column=date_column,
search_kw=search_kw) search_kw=search_kw,
test_compta_demat_compatibility=True
)
return context.Base_redirect(form_id, keep_items=dict( return context.Base_redirect(form_id, keep_items=dict(
portal_status_message=translateString("Report Started"))) portal_status_message=translateString("Report Started")))
...@@ -88,7 +88,11 @@ for journal_code, journal_lib, journal_search_kw in _groupedJournalTupleDict(): ...@@ -88,7 +88,11 @@ for journal_code, journal_lib, journal_search_kw in _groupedJournalTupleDict():
portal.portal_catalog.searchAndActivate( portal.portal_catalog.searchAndActivate(
method_id='AccountingTransaction_postFECResult', method_id='AccountingTransaction_postFECResult',
method_kw=dict(section_uid_list=section_uid_list, active_process=this_journal_active_process.getRelativeUrl()), method_kw=dict(
section_uid_list=section_uid_list,
active_process=this_journal_active_process.getRelativeUrl(),
test_compta_demat_compatibility=test_compta_demat_compatibility,
),
activate_kw=dict(tag=tag, priority=priority), activate_kw=dict(tag=tag, priority=priority),
**journal_search_kw) **journal_search_kw)
...@@ -105,4 +109,7 @@ for journal_code, journal_lib, journal_search_kw in _groupedJournalTupleDict(): ...@@ -105,4 +109,7 @@ for journal_code, journal_lib, journal_search_kw in _groupedJournalTupleDict():
context.activate(after_tag=(tag, aggregate_tag)).AccountingTransactionModule_aggregateFrenchAccountingTransactionFile( context.activate(after_tag=(tag, aggregate_tag)).AccountingTransactionModule_aggregateFrenchAccountingTransactionFile(
at_date, at_date,
active_process.getRelativeUrl(), active_process.getRelativeUrl(),
user_name=user_name) user_name=user_name,
test_compta_demat_compatibility=test_compta_demat_compatibility,
section_uid_list=section_uid_list,
)
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>section_category, section_category_strict, from_date, at_date, group_by, simulation_state, ledger, user_name=None, tag=None, aggregate_tag=None, date_column=None, search_kw=None, **kw</string> </value> <value> <string>section_category, section_category_strict, from_date, at_date, group_by, simulation_state, ledger, user_name=None, tag=None, aggregate_tag=None, date_column=None, search_kw=None, test_compta_demat_compatibility=False, **kw</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -10,10 +10,12 @@ accounting_line_list = context.contentValues(portal_type=portal.getPortalAccount ...@@ -10,10 +10,12 @@ accounting_line_list = context.contentValues(portal_type=portal.getPortalAccount
if context.getSourceSectionUid() in section_uid_list: if context.getSourceSectionUid() in section_uid_list:
if any([line.getSource(portal_type='Account') for line in accounting_line_list]): if any([line.getSource(portal_type='Account') for line in accounting_line_list]):
source_xml = context.AccountingTransaction_viewAsSourceFECXML() source_xml = context.AccountingTransaction_viewAsSourceFECXML(
test_compta_demat_compatibility=test_compta_demat_compatibility)
active_process.postResult(ActiveResult(detail=source_xml.encode('utf8').encode('zlib'))) active_process.postResult(ActiveResult(detail=source_xml.encode('utf8').encode('zlib')))
if context.getDestinationSectionUid() in section_uid_list: if context.getDestinationSectionUid() in section_uid_list:
if any([line.getDestination(portal_type='Account') for line in accounting_line_list]): if any([line.getDestination(portal_type='Account') for line in accounting_line_list]):
destination_xml = context.AccountingTransaction_viewAsDestinationFECXML() destination_xml = context.AccountingTransaction_viewAsDestinationFECXML(
test_compta_demat_compatibility=test_compta_demat_compatibility)
active_process.postResult(ActiveResult(detail=destination_xml.encode('utf8').encode('zlib'))) active_process.postResult(ActiveResult(detail=destination_xml.encode('utf8').encode('zlib')))
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>active_process, section_uid_list</string> </value> <value> <string>active_process, section_uid_list, test_compta_demat_compatibility</string> </value>
</item> </item>
<item> <item>
<key> <string>_proxy_roles</string> </key> <key> <string>_proxy_roles</string> </key>
......
...@@ -2,13 +2,14 @@ ...@@ -2,13 +2,14 @@
<EcritureNum tal:content="context/getDestinationReference">Specific Reference</EcritureNum> <EcritureNum tal:content="context/getDestinationReference">Specific Reference</EcritureNum>
<EcritureDate tal:content="python: context.getStopDate().strftime('%Y-%m-%d')">Specific Date</EcritureDate> <EcritureDate tal:content="python: context.getStopDate().strftime('%Y-%m-%d')">Specific Date</EcritureDate>
<EcritureLib tal:content="context/getTitle">Title</EcritureLib> <EcritureLib tal:content="context/getTitle">Title</EcritureLib>
<PieceRef tal:content="context/getReference">Reference</PieceRef> <PieceRef tal:content="python: (context.getReference() or context.getDestinationReference() if options['test_compta_demat_compatibility'] else context.getReference())">Reference</PieceRef>
<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.AccountingTransaction_getDeliverDate().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 and (line.getQuantity() or line.getDestinationAssetDebit() or line.getDestinationAssetCredit() or not options['test_compta_demat_compatibility'])">
<CompteNum tal:content="account/Account_getGapId">Reference Compte (Account_getGapId)</CompteNum> <CompteNum tal:content="account/Account_getGapId">Reference Compte (Account_getGapId)</CompteNum>
<CompteLib tal:content="line/Movement_getDestinationCompteLib">Translated Title Compte</CompteLib> <CompteLib tal:content="line/Movement_getDestinationCompteLib">Translated Title Compte</CompteLib>
<tal:block tal:condition="python: account.getAccountType() in ('asset/receivable', 'liability/payable')" <tal:block tal:condition="python: account.getAccountType() in ('asset/receivable', 'liability/payable')"
......
...@@ -2,13 +2,14 @@ ...@@ -2,13 +2,14 @@
<EcritureNum tal:content="context/getSourceReference">Specific Reference</EcritureNum> <EcritureNum tal:content="context/getSourceReference">Specific Reference</EcritureNum>
<EcritureDate tal:content="python: context.getStartDate().strftime('%Y-%m-%d')">Specific Date</EcritureDate> <EcritureDate tal:content="python: context.getStartDate().strftime('%Y-%m-%d')">Specific Date</EcritureDate>
<EcritureLib tal:content="context/getTitle">Title</EcritureLib> <EcritureLib tal:content="context/getTitle">Title</EcritureLib>
<PieceRef tal:content="context/getReference">Reference</PieceRef> <PieceRef tal:content="python: (context.getReference() or context.getSourceReference() if options['test_compta_demat_compatibility'] else context.getReference())">Reference</PieceRef>
<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.AccountingTransaction_getDeliverDate().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 and (line.getQuantity() or line.getSourceAssetDebit() or line.getSourceAssetCredit() or not options['test_compta_demat_compatibility'])">
<CompteNum tal:content="account/Account_getGapId">Reference Compte (Account_getGapId)</CompteNum> <CompteNum tal:content="account/Account_getGapId">Reference Compte (Account_getGapId)</CompteNum>
<CompteLib tal:content="line/Movement_getSourceCompteLib">Translated Title Compte</CompteLib> <CompteLib tal:content="line/Movement_getSourceCompteLib">Translated Title Compte</CompteLib>
<tal:block tal:condition="python: account.getAccountType() in ('asset/receivable', 'liability/payable')" <tal:block tal:condition="python: account.getAccountType() in ('asset/receivable', 'liability/payable')"
......
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