Commit 0153f990 authored by Jérome Perrin's avatar Jérome Perrin

use total_price instead of quantity

be side independant


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@5617 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d384dc78
......@@ -72,16 +72,23 @@ LOG=lambda message: context.log("AccountModule_statBalance", message)\n
\n
# read settings from user preference\n
preference = context.getPortalObject().portal_preferences\n
from_date = preference.getPreferredAccountingTransactionFromDate()\n
from_date = preference.getPreferredAccountingTransactionFromDate()\\\n
or kw.get(\'from_date\', None)\n
if from_date :\n
params[\'from_date\'] = from_date\n
at_date = preference.getPreferredAccountingTransactionAtDate()\n
\n
at_date = preference.getPreferredAccountingTransactionAtDate()\\\n
or kw.get(\'at_date\', None)\n
if at_date :\n
params[\'at_date\'] = at_date\n
simulation_state = preference.getPreferredAccountingTransactionSimulationStateList()\n
\n
simulation_state = preference.getPreferredAccountingTransactionSimulationStateList()\\\n
or kw.get(\'simulation_state\', kw.get(\'transaction_simulation_state\', None))\n
if simulation_state :\n
params[\'simulation_state\'] = simulation_state\n
section_category = preference.getPreferredAccountingTransactionSectionCategory()\n
\n
section_category = preference.getPreferredAccountingTransactionSectionCategory()\\\n
or kw.get(\'section_category\', kw.get(\'transaction_section_category\', None))\n
if section_category :\n
params[\'section_category\'] = section_category\n
\n
......@@ -116,12 +123,14 @@ if kw.get(\'omit_input\'):\n
if kw.get(\'omit_output\'):\n
params[\'omit_output\'] = 1\n
\n
context.log(\'params\', params)\n
context.log(\'at_date\', at_date)\n
results = context.Resource_zStatInventory(omit_simulation=1,\n
**params)\n
row = results[0]\n
total = 0\n
if row.quantity :\n
total = row.quantity or 0.00\n
if row.total_price :\n
total = row.total_price or 0.00\n
return total\n
\n
# FIXME:\n
......@@ -145,7 +154,7 @@ return context.portal_simulation.getInventory( omit_simulation=1, **params )\n
</item>
<item>
<key> <string>_filepath</string> </key>
<value> <string>Script (Python):/nexedi/portal_skins/erp5_accounting/AccountModule_statBalance</string> </value>
<value> <string>Script (Python):/erp5/portal_skins/erp5_accounting/AccountModule_statBalance</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
......@@ -183,6 +192,7 @@ return context.portal_simulation.getInventory( omit_simulation=1, **params )\n
<string>LOG</string>
<string>context</string>
<string>preference</string>
<string>None</string>
<string>from_date</string>
<string>_write_</string>
<string>at_date</string>
......
......@@ -47,31 +47,31 @@
</value>
</item>
<item>
<key> <string>destination_section_uid</string> </key>
<key> <string>from_date</string> </key>
<value>
<dictionary/>
</value>
</item>
<item>
<key> <string>from_date</string> </key>
<key> <string>getUid</string> </key>
<value>
<dictionary/>
</value>
</item>
<item>
<key> <string>getUid</string> </key>
<key> <string>mirror_section_uid</string> </key>
<value>
<dictionary/>
</value>
</item>
<item>
<key> <string>no_destination_section_uid</string> </key>
<key> <string>no_mirror_section_uid</string> </key>
<value>
<dictionary/>
</value>
</item>
<item>
<key> <string>no_source_payment_uid</string> </key>
<key> <string>no_payment_uid</string> </key>
<value>
<dictionary/>
</value>
......@@ -88,6 +88,12 @@
<dictionary/>
</value>
</item>
<item>
<key> <string>payment_uid</string> </key>
<value>
<dictionary/>
</value>
</item>
<item>
<key> <string>resource_uid</string> </key>
<value>
......@@ -117,12 +123,6 @@
<dictionary/>
</value>
</item>
<item>
<key> <string>source_payment_uid</string> </key>
<value>
<dictionary/>
</value>
</item>
<item>
<key> <string>to_date</string> </key>
<value>
......@@ -159,23 +159,23 @@
<key> <string>_keys</string> </key>
<value>
<list>
<string>selection</string>
<string>selection_domain</string>
<string>selection_report</string>
<string>getUid</string>
<string>where_expression</string>
<string>omit_input</string>
<string>omit_output</string>
<string>resource_uid</string>
<string>from_date</string>
<string>to_date</string>
<string>at_date</string>
<string>transaction_simulation_state</string>
<string>transaction_section_category</string>
<string>source_payment_uid</string>
<string>no_source_payment_uid</string>
<string>destination_section_uid</string>
<string>no_destination_section_uid</string>
<string>selection</string>
<string>selection_domain</string>
<string>selection_report</string>
<string>getUid</string>
<string>where_expression</string>
<string>omit_input</string>
<string>omit_output</string>
<string>resource_uid</string>
<string>from_date</string>
<string>to_date</string>
<string>at_date</string>
<string>transaction_simulation_state</string>
<string>transaction_section_category</string>
<string>payment_uid</string>
<string>no_payment_uid</string>
<string>mirror_section_uid</string>
<string>no_mirror_section_uid</string>
</list>
</value>
</item>
......@@ -217,10 +217,10 @@ to_date\r\n
at_date\r\n
transaction_simulation_state:list\r\n
transaction_section_category\r\n
source_payment_uid\r\n
no_source_payment_uid\r\n
destination_section_uid\r\n
no_destination_section_uid</string> </value>
payment_uid\r\n
no_payment_uid\r\n
mirror_section_uid\r\n
no_mirror_section_uid</string> </value>
</item>
<item>
<key> <string>cache_time_</string> </key>
......@@ -265,13 +265,14 @@ SELECT\n
DISTINCT transaction.uid, transaction.path,\n
transaction_line.path as current_transaction_line_path,\n
transaction.title as transaction_title,\n
destination_section.title AS third_party,\n
IF(stock.quantity > 0, stock.quantity, 0.0) AS source_debit,\n
IF(stock.quantity < 0, - stock.quantity, 0.0) AS source_credit,\n
stock.quantity AS source_balance,\n
stock.payment_uid AS source_payment_uid\n
mirror_section.title AS third_party,\n
IF(stock.total_price > 0, stock.total_price, 0.0) AS debit,\n
IF(stock.total_price < 0, - stock.total_price, 0.0) AS credit,\n
stock.date AS date,\n
transaction.source_reference AS specific_reference,\n
stock.total_price AS balance,\n
stock.payment_uid AS payment_uid\n
FROM\n
movement,\n
catalog,\n
catalog AS transaction_line,\n
catalog AS transaction,\n
......@@ -283,38 +284,37 @@ FROM\n
<dtml-if selection_report><dtml-var "selection_report.asSqlJoinExpression()">, </dtml-if>\n
<dtml-if where_expression>, category </dtml-if>\n
stock\n
LEFT JOIN catalog AS destination_section \n
ON destination_section.uid = stock.mirror_section_uid\n
LEFT JOIN catalog AS mirror_section\n
ON mirror_section.uid = stock.mirror_section_uid\n
AND stock.node_uid = <dtml-var getUid>\n
\n
WHERE stock.node_uid = <dtml-var getUid>\n
AND transaction_line.uid = stock.uid \n
AND transaction_line.uid = stock.uid\n
AND transaction_line.portal_type <> \'Simulation Movement\'\n
AND transaction_line.parent_uid = transaction.uid\n
AND catalog.uid = stock.section_uid\n
AND movement.uid = stock.uid\n
AND movement.is_accountable = 1\n
<dtml-if resource_uid>\n
AND (\n
<dtml-in resource_uid>\n
movement.resource_uid = <dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else> OR </dtml-if>\n
stock.resource_uid = <dtml-sqlvar sequence-item type="int">\n
<dtml-unless sequence-end> OR </dtml-unless>\n
</dtml-in>\n
)\n
</dtml-if>\n
<dtml-if from_date>\n
AND movement.start_date >= <dtml-sqlvar from_date type="datetime">\n
AND stock.date >= <dtml-sqlvar from_date type="datetime">\n
</dtml-if>\n
<dtml-if at_date>\n
AND movement.start_date <= <dtml-sqlvar at_date type="datetime">\n
AND stock.date <= <dtml-sqlvar at_date type="datetime">\n
</dtml-if>\n
<dtml-if to_date>\n
AND movement.start_date < <dtml-sqlvar to_date type="datetime">\n
AND stock.date < <dtml-sqlvar to_date type="datetime">\n
</dtml-if>\n
<dtml-if omit_input>\n
AND stock.quantity < 0\n
AND stock.total_price < 0\n
</dtml-if>\n
<dtml-if omit_output>\n
AND stock.quantity > 0\n
AND stock.total_price > 0\n
</dtml-if>\n
<dtml-if source_payment_uid>\n
AND stock.payment_uid = <dtml-sqlvar source_payment_uid type="int">\n
......@@ -322,16 +322,17 @@ WHERE stock.node_uid = <dtml-var getUid>\n
<dtml-if no_source_payment_uid>\n
AND stock.payment_uid IS NULL\n
</dtml-if>\n
<dtml-if destination_section_uid>\n
AND stock.mirror_section_uid = <dtml-sqlvar destination_section_uid type="int">\n
<dtml-if mirror_section_uid>\n
AND stock.mirror_section_uid = <dtml-sqlvar mirror_section_uid type="int">\n
</dtml-if>\n
<dtml-if no_destination_section_uid>\n
<dtml-if no_mirror_section_uid>\n
AND stock.mirror_section_uid IS NULL\n
</dtml-if>\n
<dtml-if transaction_simulation_state>\n
AND (\n
<dtml-in transaction_simulation_state>\n
transaction.simulation_state = <dtml-sqlvar sequence-item type="string"><dtml-if sequence-end><dtml-else> OR </dtml-if>\n
transaction.simulation_state = <dtml-sqlvar sequence-item type="string">\n
<dtml-if sequence-end><dtml-else> OR </dtml-if>\n
</dtml-in>\n
)\n
<dtml-else>\n
......@@ -340,7 +341,8 @@ WHERE stock.node_uid = <dtml-var getUid>\n
</dtml-if>\n
AND section.uid = stock.section_uid\n
<dtml-if transaction_section_category>\n
AND section_c.relative_url = <dtml-sqlvar transaction_section_category type="string">\n
AND section_c.relative_url = <dtml-sqlvar\n
transaction_section_category type="string">\n
</dtml-if>\n
AND section_membership.category_uid = section_c.uid\n
AND section_membership.base_category_uid = section_bc.uid\n
......@@ -356,7 +358,7 @@ WHERE stock.node_uid = <dtml-var getUid>\n
AND <dtml-var "selection_report.asSqlExpression(strict_membership=1)">\n
</dtml-if>\n
ORDER BY\n
stop_date, transaction_line.uid\n
stock.date, transaction_line.uid\n
</dtml-if>\n
......@@ -401,13 +403,14 @@ SELECT\n
DISTINCT transaction.uid, transaction.path,\n
transaction_line.path as current_transaction_line_path,\n
transaction.title as transaction_title,\n
destination_section.title AS third_party,\n
IF(stock.quantity > 0, stock.quantity, 0.0) AS source_debit,\n
IF(stock.quantity < 0, - stock.quantity, 0.0) AS source_credit,\n
stock.quantity AS source_balance,\n
stock.payment_uid AS source_payment_uid\n
mirror_section.title AS third_party,\n
IF(stock.total_price > 0, stock.total_price, 0.0) AS debit,\n
IF(stock.total_price < 0, - stock.total_price, 0.0) AS credit,\n
stock.date AS date,\n
transaction.source_reference AS specific_reference,\n
stock.total_price AS balance,\n
stock.payment_uid AS payment_uid\n
FROM\n
movement,\n
catalog,\n
catalog AS transaction_line,\n
catalog AS transaction,\n
......@@ -419,38 +422,37 @@ FROM\n
<dtml-if selection_report><dtml-var "selection_report.asSqlJoinExpression()">, </dtml-if>\n
<dtml-if where_expression>, category </dtml-if>\n
stock\n
LEFT JOIN catalog AS destination_section \n
ON destination_section.uid = stock.mirror_section_uid\n
LEFT JOIN catalog AS mirror_section\n
ON mirror_section.uid = stock.mirror_section_uid\n
AND stock.node_uid = <dtml-var getUid>\n
\n
WHERE stock.node_uid = <dtml-var getUid>\n
AND transaction_line.uid = stock.uid \n
AND transaction_line.uid = stock.uid\n
AND transaction_line.portal_type <> \'Simulation Movement\'\n
AND transaction_line.parent_uid = transaction.uid\n
AND catalog.uid = stock.section_uid\n
AND movement.uid = stock.uid\n
AND movement.is_accountable = 1\n
<dtml-if resource_uid>\n
AND (\n
<dtml-in resource_uid>\n
movement.resource_uid = <dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else> OR </dtml-if>\n
stock.resource_uid = <dtml-sqlvar sequence-item type="int">\n
<dtml-unless sequence-end> OR </dtml-unless>\n
</dtml-in>\n
)\n
</dtml-if>\n
<dtml-if from_date>\n
AND movement.start_date >= <dtml-sqlvar from_date type="datetime">\n
AND stock.date >= <dtml-sqlvar from_date type="datetime">\n
</dtml-if>\n
<dtml-if at_date>\n
AND movement.start_date <= <dtml-sqlvar at_date type="datetime">\n
AND stock.date <= <dtml-sqlvar at_date type="datetime">\n
</dtml-if>\n
<dtml-if to_date>\n
AND movement.start_date < <dtml-sqlvar to_date type="datetime">\n
AND stock.date < <dtml-sqlvar to_date type="datetime">\n
</dtml-if>\n
<dtml-if omit_input>\n
AND stock.quantity < 0\n
AND stock.total_price < 0\n
</dtml-if>\n
<dtml-if omit_output>\n
AND stock.quantity > 0\n
AND stock.total_price > 0\n
</dtml-if>\n
<dtml-if source_payment_uid>\n
AND stock.payment_uid = <dtml-sqlvar source_payment_uid type="int">\n
......@@ -458,16 +460,17 @@ WHERE stock.node_uid = <dtml-var getUid>\n
<dtml-if no_source_payment_uid>\n
AND stock.payment_uid IS NULL\n
</dtml-if>\n
<dtml-if destination_section_uid>\n
AND stock.mirror_section_uid = <dtml-sqlvar destination_section_uid type="int">\n
<dtml-if mirror_section_uid>\n
AND stock.mirror_section_uid = <dtml-sqlvar mirror_section_uid type="int">\n
</dtml-if>\n
<dtml-if no_destination_section_uid>\n
<dtml-if no_mirror_section_uid>\n
AND stock.mirror_section_uid IS NULL\n
</dtml-if>\n
<dtml-if transaction_simulation_state>\n
AND (\n
<dtml-in transaction_simulation_state>\n
transaction.simulation_state = <dtml-sqlvar sequence-item type="string"><dtml-if sequence-end><dtml-else> OR </dtml-if>\n
transaction.simulation_state = <dtml-sqlvar sequence-item type="string">\n
<dtml-if sequence-end><dtml-else> OR </dtml-if>\n
</dtml-in>\n
)\n
<dtml-else>\n
......@@ -476,7 +479,8 @@ WHERE stock.node_uid = <dtml-var getUid>\n
</dtml-if>\n
AND section.uid = stock.section_uid\n
<dtml-if transaction_section_category>\n
AND section_c.relative_url = <dtml-sqlvar transaction_section_category type="string">\n
AND section_c.relative_url = <dtml-sqlvar\n
transaction_section_category type="string">\n
</dtml-if>\n
AND section_membership.category_uid = section_c.uid\n
AND section_membership.base_category_uid = section_bc.uid\n
......@@ -492,7 +496,7 @@ WHERE stock.node_uid = <dtml-var getUid>\n
AND <dtml-var "selection_report.asSqlExpression(strict_membership=1)">\n
</dtml-if>\n
ORDER BY\n
stop_date, transaction_line.uid\n
stock.date, transaction_line.uid\n
</dtml-if>\n
......
......@@ -104,12 +104,16 @@ net_balance = 0.0\n
# \n
for l in result:\n
o = l.getObject()\n
net_balance += l.source_balance or 0.0\n
net_balance += l.balance or 0.0\n
if o is not None:\n
c = o.asContext(net_balance = net_balance,\n
source_balance=l.source_balance,\n
source_credit=l.source_credit,\n
source_debit=l.source_debit )\n
c = o.asContext( net_balance = net_balance,\n
balance=l.balance,\n
credit=l.credit,\n
debit=l.debit,\n
section_title=l.section_title,\n
specific_reference=l.specific_reference,\n
date=l.date,\n
)\n
new_result.append(c)\n
\n
return new_result\n
......@@ -130,7 +134,7 @@ return new_result\n
</item>
<item>
<key> <string>_filepath</string> </key>
<value> <string>Script (Python):/nexedi/portal_skins/erp5_accounting/BankAccount_getAccountingTransactionList</string> </value>
<value> <string>Script (Python):/erp5/portal_skins/erp5_accounting/BankAccount_getAccountingTransactionList</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
......
......@@ -134,18 +134,18 @@
<key> <string>_keys</string> </key>
<value>
<list>
<string>getUid</string>
<string>getParentUid</string>
<string>query</string>
<string>omit_input</string>
<string>omit_output</string>
<string>resource_uid</string>
<string>from_date</string>
<string>at_date</string>
<string>to_date</string>
<string>transaction_simulation_state</string>
<string>node_uid</string>
<string>stat</string>
<string>getUid</string>
<string>getParentUid</string>
<string>query</string>
<string>omit_input</string>
<string>omit_output</string>
<string>resource_uid</string>
<string>from_date</string>
<string>at_date</string>
<string>to_date</string>
<string>transaction_simulation_state</string>
<string>node_uid</string>
<string>stat</string>
</list>
</value>
</item>
......@@ -195,7 +195,9 @@ stat</string> </value>
</item>
<item>
<key> <string>connection_hook</string> </key>
<value> <string></string> </value>
<value>
<none/>
</value>
</item>
<item>
<key> <string>connection_id</string> </key>
......@@ -220,14 +222,18 @@ stat</string> </value>
<dtml-if getParentUid>\n
SELECT\n
<dtml-if stat>\n
SUM(stock.quantity) AS quantity\n
SUM(stock.total_price) AS quantity\n
<dtml-else>\n
catalog.uid\n
, catalog.path\n
-- , @runningTotal:=IFNULL(SUM(IF(stock.quantity < 0, - stock.quantity, 0)), 0) - IFNULL(SUM(IF(stock.quantity > 0, stock.quantity, 0)), 0) + @runningTotal AS net_balance\n
, IFNULL(SUM(IF(stock.quantity > 0, stock.quantity, 0)), 0) AS source_debit\n
, IFNULL(SUM(IF(stock.quantity < 0, - stock.quantity, 0)), 0) AS source_credit\n
, - IFNULL(SUM(IF(stock.quantity < 0, - stock.quantity, 0)), 0) + IFNULL(SUM(IF(stock.quantity > 0, stock.quantity, 0)), 0) AS source_balance\n
, stock.date as date\n
, section.title as section_title\n
, IF(delivery.source_section_uid = stock.section_uid,\n
catalog.source_reference, catalog.destination_reference) AS specific_reference\n
, IFNULL(SUM(IF(stock.total_price > 0, stock.total_price, 0)), 0) AS debit\n
, IFNULL(SUM(IF(stock.total_price < 0, - stock.total_price, 0)), 0) AS credit\n
, - IFNULL(SUM(IF(stock.total_price < 0, - stock.total_price, 0)), 0)\n
+ IFNULL(SUM(IF(stock.total_price > 0, stock.total_price, 0)), 0) AS balance\n
</dtml-if>\n
FROM\n
movement\n
......@@ -236,29 +242,36 @@ FROM\n
, catalog\n
, catalog AS node\n
, category AS node_category\n
, catalog AS section\n
, delivery\n
<dtml-if query>\n
, category\n
</dtml-if>\n
WHERE stock.section_uid = <dtml-var getParentUid>\n
AND stock.payment_uid = <dtml-var getUid>\n
AND child.uid = stock.uid \n
AND stock.mirror_section_uid = section.uid\n
AND delivery.uid = catalog.uid\n
AND child.uid = stock.uid\n
AND child.parent_uid = catalog.uid\n
AND movement.uid = stock.uid\n
AND movement.is_accountable = 1\n
AND node.uid = stock.node_uid\n
AND node.uid = node_category.uid\n
AND node_category.category_uid = <dtml-sqlvar "portal_categories.account_type.asset.cash.getUid()" type="int">\n
AND node_category.category_uid = <dtml-sqlvar\n
"portal_categories.account_type.asset.cash.getUid()" type="int">\n
<dtml-if node_uid>\n
AND (\n
<dtml-in node_uid>\n
stock.node_uid = <dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else> OR </dtml-if>\n
stock.node_uid = <dtml-sqlvar sequence-item type="int">\n
<dtml-unless sequence-end> OR </dtml-unless>\n
</dtml-in>\n
)\n
</dtml-if>\n
<dtml-if resource_uid>\n
AND (\n
<dtml-in resource_uid>\n
movement.resource_uid = <dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else> OR </dtml-if>\n
movement.resource_uid = <dtml-sqlvar sequence-item type="int">\n
<dtml-unless sequence-end> OR </dtml-unless>\n
</dtml-in>\n
)\n
</dtml-if>\n
......@@ -272,15 +285,16 @@ WHERE stock.section_uid = <dtml-var getParentUid>\n
AND stock.date < <dtml-sqlvar to_date type="datetime">\n
</dtml-if>\n
<dtml-if omit_input>\n
AND stock.quantity > 0\n
AND stock.total_price > 0\n
</dtml-if>\n
<dtml-if omit_output>\n
AND stock.quantity < 0\n
AND stock.total_price < 0\n
</dtml-if>\n
<dtml-if transaction_simulation_state>\n
AND (\n
<dtml-in transaction_simulation_state>\n
catalog.simulation_state = <dtml-sqlvar sequence-item type="string"><dtml-if sequence-end><dtml-else> OR </dtml-if>\n
catalog.simulation_state = <dtml-sqlvar sequence-item type="string">\n
<dtml-unless sequence-end> OR </dtml-unless>\n
</dtml-in>\n
)\n
</dtml-if>\n
......@@ -289,9 +303,9 @@ WHERE stock.section_uid = <dtml-var getParentUid>\n
AND <dtml-var query>\n
</dtml-if>\n
<dtml-unless stat>\n
GROUP BY catalog.uid\n
GROUP BY catalog.uid\n
</dtml-unless>\n
ORDER BY stock.date, movement.uid\n
ORDER BY stock.date, movement.uid\n
</dtml-if>\n
......@@ -334,14 +348,18 @@ ORDER BY stock.date, movement.uid\n
<dtml-if getParentUid>\n
SELECT\n
<dtml-if stat>\n
SUM(stock.quantity) AS quantity\n
SUM(stock.total_price) AS quantity\n
<dtml-else>\n
catalog.uid\n
, catalog.path\n
-- , @runningTotal:=IFNULL(SUM(IF(stock.quantity < 0, - stock.quantity, 0)), 0) - IFNULL(SUM(IF(stock.quantity > 0, stock.quantity, 0)), 0) + @runningTotal AS net_balance\n
, IFNULL(SUM(IF(stock.quantity > 0, stock.quantity, 0)), 0) AS source_debit\n
, IFNULL(SUM(IF(stock.quantity < 0, - stock.quantity, 0)), 0) AS source_credit\n
, - IFNULL(SUM(IF(stock.quantity < 0, - stock.quantity, 0)), 0) + IFNULL(SUM(IF(stock.quantity > 0, stock.quantity, 0)), 0) AS source_balance\n
, stock.date as date\n
, section.title as section_title\n
, IF(delivery.source_section_uid = stock.section_uid,\n
catalog.source_reference, catalog.destination_reference) AS specific_reference\n
, IFNULL(SUM(IF(stock.total_price > 0, stock.total_price, 0)), 0) AS debit\n
, IFNULL(SUM(IF(stock.total_price < 0, - stock.total_price, 0)), 0) AS credit\n
, - IFNULL(SUM(IF(stock.total_price < 0, - stock.total_price, 0)), 0)\n
+ IFNULL(SUM(IF(stock.total_price > 0, stock.total_price, 0)), 0) AS balance\n
</dtml-if>\n
FROM\n
movement\n
......@@ -350,29 +368,36 @@ FROM\n
, catalog\n
, catalog AS node\n
, category AS node_category\n
, catalog AS section\n
, delivery\n
<dtml-if query>\n
, category\n
</dtml-if>\n
WHERE stock.section_uid = <dtml-var getParentUid>\n
AND stock.payment_uid = <dtml-var getUid>\n
AND child.uid = stock.uid \n
AND stock.mirror_section_uid = section.uid\n
AND delivery.uid = catalog.uid\n
AND child.uid = stock.uid\n
AND child.parent_uid = catalog.uid\n
AND movement.uid = stock.uid\n
AND movement.is_accountable = 1\n
AND node.uid = stock.node_uid\n
AND node.uid = node_category.uid\n
AND node_category.category_uid = <dtml-sqlvar "portal_categories.account_type.asset.cash.getUid()" type="int">\n
AND node_category.category_uid = <dtml-sqlvar\n
"portal_categories.account_type.asset.cash.getUid()" type="int">\n
<dtml-if node_uid>\n
AND (\n
<dtml-in node_uid>\n
stock.node_uid = <dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else> OR </dtml-if>\n
stock.node_uid = <dtml-sqlvar sequence-item type="int">\n
<dtml-unless sequence-end> OR </dtml-unless>\n
</dtml-in>\n
)\n
</dtml-if>\n
<dtml-if resource_uid>\n
AND (\n
<dtml-in resource_uid>\n
movement.resource_uid = <dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else> OR </dtml-if>\n
movement.resource_uid = <dtml-sqlvar sequence-item type="int">\n
<dtml-unless sequence-end> OR </dtml-unless>\n
</dtml-in>\n
)\n
</dtml-if>\n
......@@ -386,15 +411,16 @@ WHERE stock.section_uid = <dtml-var getParentUid>\n
AND stock.date < <dtml-sqlvar to_date type="datetime">\n
</dtml-if>\n
<dtml-if omit_input>\n
AND stock.quantity > 0\n
AND stock.total_price > 0\n
</dtml-if>\n
<dtml-if omit_output>\n
AND stock.quantity < 0\n
AND stock.total_price < 0\n
</dtml-if>\n
<dtml-if transaction_simulation_state>\n
AND (\n
<dtml-in transaction_simulation_state>\n
catalog.simulation_state = <dtml-sqlvar sequence-item type="string"><dtml-if sequence-end><dtml-else> OR </dtml-if>\n
catalog.simulation_state = <dtml-sqlvar sequence-item type="string">\n
<dtml-unless sequence-end> OR </dtml-unless>\n
</dtml-in>\n
)\n
</dtml-if>\n
......@@ -403,9 +429,9 @@ WHERE stock.section_uid = <dtml-var getParentUid>\n
AND <dtml-var query>\n
</dtml-if>\n
<dtml-unless stat>\n
GROUP BY catalog.uid\n
GROUP BY catalog.uid\n
</dtml-unless>\n
ORDER BY stock.date, movement.uid\n
ORDER BY stock.date, movement.uid\n
</dtml-if>\n
......
......@@ -77,13 +77,18 @@ preference = context.getPortalObject().portal_preferences\n
from_date = preference.getPreferredAccountingTransactionFromDate()\n
if from_date :\n
kwd[\'from_date\'] = from_date\n
\n
at_date = preference.getPreferredAccountingTransactionAtDate()\n
if at_date :\n
kwd[\'at_date\'] = at_date\n
simulation_state = preference.getPreferredAccountingTransactionSimulationStateList()\n
\n
simulation_state = preference\\\n
.getPreferredAccountingTransactionSimulationStateList()\n
if simulation_state :\n
kwd[\'transaction_simulation_state\'] = simulation_state\n
section_category = preference.getPreferredAccountingTransactionSectionCategory()\n
\n
section_category = preference\\\n
.getPreferredAccountingTransactionSectionCategory()\n
if section_category :\n
kwd[\'transaction_section_category\'] = section_category\n
\n
......@@ -93,9 +98,9 @@ if kw.has_key(\'transaction_portal_type\'):\n
kwd[\'transaction_portal_type\'] = kw[\'transaction_portal_type\']\n
\n
\n
# FIXME: same problem as in BankAccount_getAccountingTransactionList\n
\n
#LOG("SQL used: %s" % context.Entity_zGetAccountingTransactionList(src__=1, **kwd))\n
# FIXME: same problem as in BankAccount_getAccountingTransactionList\n
# LOG("SQL used: %s" % context.Entity_zGetAccountingTransactionList(src__=1, **kwd))\n
\n
new_result = []\n
result = context.Entity_zGetAccountingTransactionList(**kwd)\n
......@@ -104,17 +109,20 @@ if src__:\n
net_balance = 0.0\n
for l in result:\n
o = l.getObject()\n
net_balance += l.source_balance or 0.0\n
net_balance += l.balance or 0.0\n
if o is not None:\n
c = o.asContext(net_balance = net_balance,\n
source_balance=l.source_balance,\n
source_credit=l.source_credit,\n
source_debit=l.source_debit,\n
date=l.date,\n
parent_reference=l.parent_reference,\n
parent_source_reference=l.parent_source_reference,\n
translated_simulation_state_title = o.getTranslatedSimulationStateTitle(),\n
portal_type=l.portal_type )\n
c = o.asContext( net_balance = net_balance,\n
balance=l.balance,\n
credit=l.credit,\n
debit=l.debit,\n
date=l.date,\n
section_title=l.section_title,\n
parent_reference=l.parent_reference,\n
parent_specific_reference=l.parent_specific_reference,\n
translated_simulation_state_title =\n
o.getTranslatedSimulationStateTitle(),\n
portal_type=l.portal_type,\n
account_uid=l.account_uid, )\n
new_result.append(c)\n
\n
return new_result\n
......@@ -135,7 +143,7 @@ return new_result\n
</item>
<item>
<key> <string>_filepath</string> </key>
<value> <string>Script (Python):/nexedi/portal_skins/erp5_accounting/Entity_getAccountingTransactionList</string> </value>
<value> <string>Script (Python):/erp5/portal_skins/erp5_accounting/Entity_getAccountingTransactionList</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
......
......@@ -103,8 +103,8 @@
<value>
<dictionary>
<item>
<key> <string>type</string> </key>
<value> <string>list</string> </value>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
......@@ -156,20 +156,21 @@
<key> <string>_keys</string> </key>
<value>
<list>
<string>getUid</string>
<string>query</string>
<string>omit_input</string>
<string>omit_output</string>
<string>resource_uid</string>
<string>from_date</string>
<string>at_date</string>
<string>to_date</string>
<string>transaction_simulation_state</string>
<string>transaction_section_category</string>
<string>transaction_portal_type</string>
<string>node_uid</string>
<string>hide_grouping</string>
<string>stat</string>
<string>getUid</string>
<string>query</string>
<string>omit_input</string>
<string>omit_output</string>
<string>resource_uid</string>
<string>from_date</string>
<string>at_date</string>
<string>to_date</string>
<string>transaction_simulation_state</string>
<string>transaction_section_category</string>
<string>transaction_portal_type</string>
<string>node_uid</string>
<string>hide_grouping</string>
<string>resource_uid</string>
<string>stat</string>
</list>
</value>
</item>
......@@ -205,6 +206,7 @@ transaction_section_category\r\n
transaction_portal_type:list\r\n
node_uid:list\r\n
hide_grouping=""\r\n
resource_uid=""\n
stat</string> </value>
</item>
<item>
......@@ -248,48 +250,65 @@ stat</string> </value>
<dtml-if getUid>\n
SELECT\n
<dtml-if stat>\n
IFNULL(SUM(stock.total_price), 0.00) AS total_price,\n
IFNULL(SUM(stock.quantity), 0.00) AS quantity\n
<dtml-else>\n
DISTINCT child.uid AS uid\n
, child.path AS path\n
, stock.node_uid AS account_uid\n
, stock.date AS date\n
, stock.node_uid AS account_uid\n
, catalog.reference AS parent_reference\n
, catalog.source_reference AS parent_source_reference -- FIXME\n
, mirror_section.title AS section_title\n
, IF(stock.section_uid = delivery.source_section_uid,\n
catalog.source_reference,\n
catalog.destination_reference) AS parent_specific_reference\n
, catalog.portal_type AS portal_type\n
, IFNULL(SUM(IF(stock.quantity > 0, stock.quantity, 0)), 0.00) AS source_debit\n
, IFNULL(SUM(IF(stock.quantity < 0, - stock.quantity, 0)), 0.00) AS source_credit\n
, IFNULL(SUM(stock.quantity), 0.00) AS source_balance\n
<dtml-if resource_uid>\n
, IFNULL(SUM(IF(stock.quantity > 0,\n
stock.quantity, 0)), 0.00) AS debit\n
, IFNULL(SUM(IF(stock.quantity < 0,\n
- stock.quantity, 0)), 0.00) AS credit\n
, IFNULL(SUM(stock.quantity), 0.00) AS balance\n
<dtml-else>\n
, IFNULL(SUM(IF(stock.total_price > 0,\n
stock.total_price, 0)), 0.00) AS debit\n
, IFNULL(SUM(IF(stock.total_price < 0,\n
- stock.total_price, 0)), 0.00) AS credit\n
, IFNULL(SUM(stock.total_price), 0.00) AS balance\n
</dtml-if>\n
</dtml-if>\n
FROM\n
movement\n
, stock\n
stock\n
, catalog AS child\n
, catalog\n
, catalog AS node\n
, category AS node_category\n
, category AS section_category\n
, catalog AS mirror_section\n
, delivery\n
<dtml-if query>\n
, category\n
</dtml-if>\n
WHERE stock.mirror_section_uid = <dtml-var getUid>\n
AND child.uid = stock.uid \n
AND child.uid = stock.uid\n
AND delivery.uid = catalog.uid\n
AND child.parent_uid = catalog.uid\n
AND child.portal_type <> "Simulation Movement"\n
AND movement.uid = stock.uid\n
AND movement.source_uid = node.uid\n
AND movement.is_accountable = 1\n
AND node.uid = stock.node_uid\n
AND node.uid = node_category.uid\n
AND stock.section_uid = section_category.uid\n
AND (node_category.category_uid = <dtml-var expr="getPortalObject().portal_categories.account_type.asset.receivable.getUid()">\n
OR node_category.category_uid = <dtml-var expr="getPortalObject().portal_categories.account_type.liability.payable.getUid()">\n
AND section_category.uid = mirror_section.uid\n
AND (node_category.category_uid = <dtml-var\n
expr="getPortalObject().portal_categories.account_type.asset.receivable.getUid()">\n
OR node_category.category_uid = <dtml-var\n
expr="getPortalObject().portal_categories.account_type.liability.payable.getUid()">\n
)\n
AND node_category.category_strict_membership = 1\n
<dtml-if transaction_portal_type>\n
AND (\n
<dtml-in transaction_portal_type>\n
catalog.portal_type = <dtml-sqlvar sequence-item type="string"><dtml-unless sequence-end> OR </dtml-unless>\n
catalog.portal_type = <dtml-sqlvar sequence-item type="string">\n
<dtml-unless sequence-end> OR </dtml-unless>\n
</dtml-in>\n
)\n
</dtml-if>\n
......@@ -297,14 +316,16 @@ WHERE stock.mirror_section_uid = <dtml-var getUid>\n
<dtml-if node_uid>\n
AND (\n
<dtml-in node_uid>\n
stock.node_uid = <dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else> OR </dtml-if>\n
stock.node_uid = <dtml-sqlvar sequence-item type="int">\n
<dtml-unless sequence-end> OR </dtml-unless>\n
</dtml-in>\n
)\n
</dtml-if>\n
<dtml-if resource_uid>\n
AND (\n
<dtml-in resource_uid>\n
movement.resource_uid = <dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else> OR </dtml-if>\n
stock.resource_uid = <dtml-sqlvar sequence-item type="int">\n
<dtml-unless sequence-end> OR </dtml-unless>\n
</dtml-in>\n
)\n
</dtml-if>\n
......@@ -318,15 +339,17 @@ WHERE stock.mirror_section_uid = <dtml-var getUid>\n
AND stock.date < <dtml-sqlvar to_date type="datetime">\n
</dtml-if>\n
<dtml-if omit_input>\n
AND stock.quantity > 0\n
AND stock.total_price > 0\n
</dtml-if>\n
<dtml-if omit_output>\n
AND stock.quantity < 0\n
AND stock.total_price < 0\n
</dtml-if>\n
AND stock.total_price != 0\n
<dtml-if transaction_simulation_state>\n
AND (\n
<dtml-in transaction_simulation_state>\n
catalog.simulation_state = <dtml-sqlvar sequence-item type="string"><dtml-if sequence-end><dtml-else> OR </dtml-if>\n
catalog.simulation_state = <dtml-sqlvar sequence-item type="string">\n
<dtml-unless sequence-end> OR </dtml-unless>\n
</dtml-in>\n
)\n
</dtml-if>\n
......@@ -335,16 +358,16 @@ WHERE stock.mirror_section_uid = <dtml-var getUid>\n
<dtml-var expr="portal_categories.resolveCategory(transaction_section_category).getUid()">\n
</dtml-if>\n
<dtml-if hide_grouping>\n
AND (child.grouping_reference IS NULL or child.grouping_reference ="")\n
AND (child.grouping_reference IS NULL or child.grouping_reference = "")\n
</dtml-if hide_grouping>\n
<dtml-if query>\n
AND category.uid = stock.section_uid\n
AND <dtml-var query>\n
AND <dtml-var query>\n
</dtml-if>\n
<dtml-unless stat>\n
GROUP BY catalog.uid, stock.node_uid\n
GROUP BY catalog.uid, stock.node_uid\n
</dtml-unless>\n
ORDER BY stock.date, child.uid\n
ORDER BY stock.date, child.uid\n
</dtml-if>\n
......@@ -387,48 +410,65 @@ ORDER BY stock.date, child.uid\n
<dtml-if getUid>\n
SELECT\n
<dtml-if stat>\n
IFNULL(SUM(stock.total_price), 0.00) AS total_price,\n
IFNULL(SUM(stock.quantity), 0.00) AS quantity\n
<dtml-else>\n
DISTINCT child.uid AS uid\n
, child.path AS path\n
, stock.node_uid AS account_uid\n
, stock.date AS date\n
, stock.node_uid AS account_uid\n
, catalog.reference AS parent_reference\n
, catalog.source_reference AS parent_source_reference -- FIXME\n
, mirror_section.title AS section_title\n
, IF(stock.section_uid = delivery.source_section_uid,\n
catalog.source_reference,\n
catalog.destination_reference) AS parent_specific_reference\n
, catalog.portal_type AS portal_type\n
, IFNULL(SUM(IF(stock.quantity > 0, stock.quantity, 0)), 0.00) AS source_debit\n
, IFNULL(SUM(IF(stock.quantity < 0, - stock.quantity, 0)), 0.00) AS source_credit\n
, IFNULL(SUM(stock.quantity), 0.00) AS source_balance\n
<dtml-if resource_uid>\n
, IFNULL(SUM(IF(stock.quantity > 0,\n
stock.quantity, 0)), 0.00) AS debit\n
, IFNULL(SUM(IF(stock.quantity < 0,\n
- stock.quantity, 0)), 0.00) AS credit\n
, IFNULL(SUM(stock.quantity), 0.00) AS balance\n
<dtml-else>\n
, IFNULL(SUM(IF(stock.total_price > 0,\n
stock.total_price, 0)), 0.00) AS debit\n
, IFNULL(SUM(IF(stock.total_price < 0,\n
- stock.total_price, 0)), 0.00) AS credit\n
, IFNULL(SUM(stock.total_price), 0.00) AS balance\n
</dtml-if>\n
</dtml-if>\n
FROM\n
movement\n
, stock\n
stock\n
, catalog AS child\n
, catalog\n
, catalog AS node\n
, category AS node_category\n
, category AS section_category\n
, catalog AS mirror_section\n
, delivery\n
<dtml-if query>\n
, category\n
</dtml-if>\n
WHERE stock.mirror_section_uid = <dtml-var getUid>\n
AND child.uid = stock.uid \n
AND child.uid = stock.uid\n
AND delivery.uid = catalog.uid\n
AND child.parent_uid = catalog.uid\n
AND child.portal_type <> "Simulation Movement"\n
AND movement.uid = stock.uid\n
AND movement.source_uid = node.uid\n
AND movement.is_accountable = 1\n
AND node.uid = stock.node_uid\n
AND node.uid = node_category.uid\n
AND stock.section_uid = section_category.uid\n
AND (node_category.category_uid = <dtml-var expr="getPortalObject().portal_categories.account_type.asset.receivable.getUid()">\n
OR node_category.category_uid = <dtml-var expr="getPortalObject().portal_categories.account_type.liability.payable.getUid()">\n
AND section_category.uid = mirror_section.uid\n
AND (node_category.category_uid = <dtml-var\n
expr="getPortalObject().portal_categories.account_type.asset.receivable.getUid()">\n
OR node_category.category_uid = <dtml-var\n
expr="getPortalObject().portal_categories.account_type.liability.payable.getUid()">\n
)\n
AND node_category.category_strict_membership = 1\n
<dtml-if transaction_portal_type>\n
AND (\n
<dtml-in transaction_portal_type>\n
catalog.portal_type = <dtml-sqlvar sequence-item type="string"><dtml-unless sequence-end> OR </dtml-unless>\n
catalog.portal_type = <dtml-sqlvar sequence-item type="string">\n
<dtml-unless sequence-end> OR </dtml-unless>\n
</dtml-in>\n
)\n
</dtml-if>\n
......@@ -436,14 +476,16 @@ WHERE stock.mirror_section_uid = <dtml-var getUid>\n
<dtml-if node_uid>\n
AND (\n
<dtml-in node_uid>\n
stock.node_uid = <dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else> OR </dtml-if>\n
stock.node_uid = <dtml-sqlvar sequence-item type="int">\n
<dtml-unless sequence-end> OR </dtml-unless>\n
</dtml-in>\n
)\n
</dtml-if>\n
<dtml-if resource_uid>\n
AND (\n
<dtml-in resource_uid>\n
movement.resource_uid = <dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else> OR </dtml-if>\n
stock.resource_uid = <dtml-sqlvar sequence-item type="int">\n
<dtml-unless sequence-end> OR </dtml-unless>\n
</dtml-in>\n
)\n
</dtml-if>\n
......@@ -457,15 +499,17 @@ WHERE stock.mirror_section_uid = <dtml-var getUid>\n
AND stock.date < <dtml-sqlvar to_date type="datetime">\n
</dtml-if>\n
<dtml-if omit_input>\n
AND stock.quantity > 0\n
AND stock.total_price > 0\n
</dtml-if>\n
<dtml-if omit_output>\n
AND stock.quantity < 0\n
AND stock.total_price < 0\n
</dtml-if>\n
AND stock.total_price != 0\n
<dtml-if transaction_simulation_state>\n
AND (\n
<dtml-in transaction_simulation_state>\n
catalog.simulation_state = <dtml-sqlvar sequence-item type="string"><dtml-if sequence-end><dtml-else> OR </dtml-if>\n
catalog.simulation_state = <dtml-sqlvar sequence-item type="string">\n
<dtml-unless sequence-end> OR </dtml-unless>\n
</dtml-in>\n
)\n
</dtml-if>\n
......@@ -474,16 +518,16 @@ WHERE stock.mirror_section_uid = <dtml-var getUid>\n
<dtml-var expr="portal_categories.resolveCategory(transaction_section_category).getUid()">\n
</dtml-if>\n
<dtml-if hide_grouping>\n
AND (child.grouping_reference IS NULL or child.grouping_reference ="")\n
AND (child.grouping_reference IS NULL or child.grouping_reference = "")\n
</dtml-if hide_grouping>\n
<dtml-if query>\n
AND category.uid = stock.section_uid\n
AND <dtml-var query>\n
AND <dtml-var query>\n
</dtml-if>\n
<dtml-unless stat>\n
GROUP BY catalog.uid, stock.node_uid\n
GROUP BY catalog.uid, stock.node_uid\n
</dtml-unless>\n
ORDER BY stock.date, child.uid\n
ORDER BY stock.date, child.uid\n
</dtml-if>\n
......
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