Commit a4a94b43 authored by Kevin Deldycke's avatar Kevin Deldycke

* Add a test on portal type to bypass bad acquisition of group category from...

  * Add a test on portal type to bypass bad acquisition of group category from person to Orignisation. This help us filter employee of the source_section: because of acquisition via subordination they are seen as part of the group but in this accounting context group define a business unit composed of organisation.
  * Light reformating of code.
  * Don't call getSourceInventory and getDestinationInventory twice.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6371 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 647fcaa5
...@@ -69,21 +69,19 @@ ...@@ -69,21 +69,19 @@
<value> <string encoding="cdata"><![CDATA[ <value> <string encoding="cdata"><![CDATA[
"""\n """\n
Journal entries, for use with AccountingTransactionModule_viewJournal\n Journal entries, for use with AccountingTransactionModule_viewJournal\n
\n \n
return a list of dictionnaries like that : \n return a list of dictionnaries like that :\n
\n \n
{\n { \'date\' : Date\n
\'date\' : Date\n , \'description\': String\n
\'description\' : String\n , \'currency\' : String\n
\'currency\' : String\n , \'lines\' : { \'debtor\' : Bool\n
\'lines\' : {\n , \'account_gap_id\': String\n
\'debtor\' : Bool, \n , \'account_name\' : String # with extra-description (ie. bank name if a bank, organisation name if an other party)\n
\'account_gap_id\' : String\n , \'amount\' : Float\n
\'account_name\' : String # with extra-description (ie. bank name if a bank, organisation name if an other party)\n }\n
\'amount\' : Float\n }\n
}\n
}\n
"""\n """\n
\n \n
request = context.REQUEST\n request = context.REQUEST\n
...@@ -95,58 +93,60 @@ from_date = request.get(\'from_date\', None)\n ...@@ -95,58 +93,60 @@ from_date = request.get(\'from_date\', None)\n
\n \n
N_ = context.Base_translateString\n N_ = context.Base_translateString\n
\n \n
params = {\n params = { \'sort_on\' : \'delivery.start_date\'\n
\'sort_on\' : \'delivery.start_date\',\n , \'at_date\' : at_date\n
\'at_date\' : at_date,\n , \'simulation_state\': transaction_simulation_state\n
\'simulation_state\': transaction_simulation_state,\n , \'section_category\': transaction_section_category\n
\'section_category\' : transaction_section_category,\n , \'portal_type\' : transaction_portal_type\n
\'portal_type\': transaction_portal_type,\n }\n
}\n
\n \n
if from_date:\n if from_date:\n
params[\'from_date\'] = from_date\n params[\'from_date\'] = from_date\n
\n \n
result=[]\n result = []\n
journal_total_debit = 0\n journal_total_debit = 0\n
journal_total_credit = 0\n journal_total_credit = 0\n
\n \n
for transaction in context\\\n zGetList = context.AccountingTransactionModule_zGetAccountingTransactionList\n
.AccountingTransactionModule_zGetAccountingTransactionList(\n transaction_list = zGetList( selection_params = params\n
selection_params = params, selection=None, **params):\n , selection = None\n
transaction = transaction.getObject()\n , **params\n
\n )\n
\n
for transaction in transaction_list:\n
transaction = transaction.getObject()\n
destination_section = transaction.getDestinationSectionValue()\n destination_section = transaction.getDestinationSectionValue()\n
we_are_destination = destination_section is not None and (\'group/%s\' %\n source_section = transaction.getSourceSectionValue()\n
destination_section.getProperty(\'group\', \'\'))\\\n \n
.startswith(transaction_section_category)\n # add a test on portal type to bypass bad acquisition of group category from person to Orignisation\n
source_section = transaction.getSourceSectionValue()\n # This help us filter employee of the source_section: because of acquisition via subordination they are seen as part of the group but in this accounting context group define a business unit composed of organisation\n
we_are_destination = (destination_section is not None) and (\'group/%s\' %\n
destination_section.getGroup(\'\')).startswith(transaction_section_category) and destination_section.getPortalType() == "Organisation"\n
we_are_source = (source_section is not None) and (\'group/%s\' %\n we_are_source = (source_section is not None) and (\'group/%s\' %\n
source_section.getProperty(\'group\', \'\'))\\\n source_section.getGroup(\'\')).startswith(transaction_section_category) and source_section.getPortalType() == "Organisation"\n
.startswith(transaction_section_category)\n \n
\n if we_are_source:\n
if we_are_source :\n
specific_reference = transaction.getSourceReference()\n specific_reference = transaction.getSourceReference()\n
date = transaction.getStartDate()\n date = transaction.getStartDate()\n
else :\n else:\n
specific_reference = transaction.getDestinationReference()\n specific_reference = transaction.getDestinationReference()\n
date = transaction.getStopDate()\n date = transaction.getStopDate()\n
\n \n
lines = []\n lines = []\n
transaction_dict={\n transaction_dict = { \\\n
\'date\' : context.Base_FormatDate( date ),\n \'date\' : context.Base_FormatDate( date )\n
\'description\' : N_("${transaction_title} (Transaction Reference "+\n , \'lines\' : lines\n
"= ${transaction_reference},\\n Creation Date = "+\n , \'description\': N_( "${transaction_title} (Transaction Reference " +\n
"${creation_date} \\n Currency = ${currency_title})" ,\n "= ${transaction_reference},\\n Creation Date = " +\n
mapping = { "transaction_title": unicode(transaction.getTitle()\n "${creation_date} \\n Currency = ${currency_title})"\n
or \'\', \'utf8\'),\n , mapping = { "transaction_title": unicode(transaction.getTitle() or \'\', \'utf8\')\n
"transaction_reference": unicode(\n , "transaction_reference": unicode(specific_reference or \'\', \'utf8\')\n
specific_reference or \'\', \'utf8\'),\n , "creation_date": context.Base_FormatDate(transaction.getCreationDate())\n
"creation_date" : context.Base_FormatDate(\n , "currency_title": transaction.getResourceTitle() or \'\'\n
transaction.getCreationDate()),\n }\n
"currency_title" : transaction.getResourceTitle() or \'\'\n )\n
}),\n }\n
\'lines\' : lines, }\n \n
\n
result.append(transaction_dict)\n result.append(transaction_dict)\n
transaction_lines = transaction.contentValues(\n transaction_lines = transaction.contentValues(\n
filter = {\'portal_type\' : context.getPortalAccountingMovementTypeList()})\n filter = {\'portal_type\' : context.getPortalAccountingMovementTypeList()})\n
...@@ -159,71 +159,66 @@ for transaction in context\\\n ...@@ -159,71 +159,66 @@ for transaction in context\\\n
transaction_lines.sort(lambda x,y: cmp(\n transaction_lines.sort(lambda x,y: cmp(\n
y.getObject().getDestinationInventoriatedTotalAssetPrice(),\n y.getObject().getDestinationInventoriatedTotalAssetPrice(),\n
x.getObject().getDestinationInventoriatedTotalAssetPrice()))\n x.getObject().getDestinationInventoriatedTotalAssetPrice()))\n
\n \n
for line in transaction_lines :\n for line in transaction_lines:\n
line = line.getObject()\n line = line.getObject()\n
\n
if we_are_source :\n if we_are_source :\n
debtor = (line.getSourceInventoriatedTotalAssetPrice() > 0)\n debit = line.getSourceInventoriatedTotalAssetDebit() or 0.0\n
credit = line.getSourceInventoriatedTotalAssetCredit() or 0.0\n
debtor = (line.getSourceInventoriatedTotalAssetPrice() > 0)\n
account = line.getSourceValue()\n account = line.getSourceValue()\n
if account is None: continue\n if account is None: continue\n
if account.isMemberOf( \'account_type/asset/cash\' ) :\n if account.isMemberOf(\'account_type/asset/cash\'):\n
account_description = "%s (%s)"%(\n account_description = "%s (%s)" % ( line.getSourceTitle()\n
line.getSourceTitle(),\n , line.getSourcePaymentTitle()\n
line.getSourcePaymentTitle())\n )\n
elif account.getAccountType() in (\n elif account.getAccountType() in (\'asset/receivable\', \'liability/payable\'):\n
\'asset/receivable\',\n account_description = "%s (%s)" % ( line.getSourceTitle()\n
\'liability/payable\'):\n , line.getDestinationSectionTitle()\n
account_description = "%s (%s)"%(\n )\n
line.getSourceTitle(),\n else:\n
line.getDestinationSectionTitle())\n
else :\n
account_description = line.getSourceTitle()\n account_description = line.getSourceTitle()\n
lines.append({\n lines.append({ \'debtor\' : debtor\n
\'debtor\' : debtor,\n , \'account_gap_id\': account.Account_getGapId()\n
\'account_gap_id\' : account.Account_getGapId(),\n , \'account_name\' : account_description\n
\'account_name\' : account_description,\n , \'amount\' : debtor and (debit) or (credit)\n
\'amount\' : debtor and (\n })\n
line.getSourceInventoriatedTotalAssetDebit()) \\\n if debtor:\n
or ( line.getSourceInventoriatedTotalAssetCredit())\n journal_total_debit += debit\n
})\n
if debtor :\n
journal_total_debit += line.getSourceInventoriatedTotalAssetDebit()\n
else:\n else:\n
journal_total_credit += line.getSourceInventoriatedTotalAssetCredit()\n journal_total_credit += credit\n
\n \n
if we_are_destination :\n if we_are_destination:\n
debtor = (line.getDestinationInventoriatedTotalAssetDebit() >\n debit = line.getDestinationInventoriatedTotalAssetDebit() or 0.0\n
line.getDestinationInventoriatedTotalAssetCredit())\n credit = line.getDestinationInventoriatedTotalAssetCredit() or 0.0\n
debtor = (debit > credit)\n
account = line.getDestinationValue()\n account = line.getDestinationValue()\n
if account is None : continue\n if account is None: continue\n
if account.isMemberOf( \'account_type/asset/cash\' ) :\n if account.isMemberOf(\'account_type/asset/cash\'):\n
account_description = "%s (%s)"%(\n account_description = "%s (%s)" % ( line.getDestinationTitle()\n
line.getDestinationTitle(),\n , line.getDestinationPaymentTitle()\n
line.getDestinationPaymentTitle())\n )\n
elif account.getAccountType() in (\n elif account.getAccountType() in (\'asset/receivable\' ,\'liability/payable\'):\n
\'asset/receivable\',\n account_description = "%s (%s)" % ( line.getDestinationTitle()\n
\'liability/payable\'):\n , line.getSourceSectionTitle()\n
account_description = "%s (%s)"%(\n )\n
line.getDestinationTitle(),\n else:\n
line.getSourceSectionTitle())\n
else :\n
account_description = line.getDestinationTitle()\n account_description = line.getDestinationTitle()\n
lines.append({\n lines.append({ \'debtor\' : debtor\n
\'debtor\' : debtor,\n , \'account_gap_id\': account.Account_getGapId()\n
\'account_gap_id\' : account.Account_getGapId(),\n , \'account_name\' : account_description\n
\'account_name\' : account_description,\n , \'amount\' : debtor and (debit) or (credit)\n
\'amount\' : debtor and (\n })\n
line.getDestinationInventoriatedTotalAssetDebit()) \\\n if debtor:\n
or ( line.getDestinationInventoriatedTotalAssetCredit())\n journal_total_debit += debit\n
})\n
if debtor :\n
journal_total_debit += line.getDestinationInventoriatedTotalAssetDebit()\n
else:\n else:\n
journal_total_credit += line.getDestinationInventoriatedTotalAssetCredit()\n journal_total_credit += credit\n
\n \n
return result + [{ "journal_total_debit": journal_total_debit,\n \n
"journal_total_credit": journal_total_credit }]\n return result + [{ "journal_total_debit" : journal_total_debit\n
# vim: syntax=python\n , "journal_total_credit": journal_total_credit\n
}]\n
]]></string> </value> ]]></string> </value>
...@@ -288,12 +283,14 @@ return result + [{ "journal_total_debit": journal_total_debit,\n ...@@ -288,12 +283,14 @@ return result + [{ "journal_total_debit": journal_total_debit,\n
<string>result</string> <string>result</string>
<string>journal_total_debit</string> <string>journal_total_debit</string>
<string>journal_total_credit</string> <string>journal_total_credit</string>
<string>_getiter_</string> <string>zGetList</string>
<string>_apply_</string> <string>_apply_</string>
<string>transaction_list</string>
<string>_getiter_</string>
<string>transaction</string> <string>transaction</string>
<string>destination_section</string> <string>destination_section</string>
<string>we_are_destination</string>
<string>source_section</string> <string>source_section</string>
<string>we_are_destination</string>
<string>we_are_source</string> <string>we_are_source</string>
<string>specific_reference</string> <string>specific_reference</string>
<string>date</string> <string>date</string>
...@@ -302,6 +299,8 @@ return result + [{ "journal_total_debit": journal_total_debit,\n ...@@ -302,6 +299,8 @@ return result + [{ "journal_total_debit": journal_total_debit,\n
<string>transaction_dict</string> <string>transaction_dict</string>
<string>transaction_lines</string> <string>transaction_lines</string>
<string>line</string> <string>line</string>
<string>debit</string>
<string>credit</string>
<string>debtor</string> <string>debtor</string>
<string>account</string> <string>account</string>
<string>account_description</string> <string>account_description</string>
......
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