Commit 0eda7145 authored by Jérome Perrin's avatar Jérome Perrin

add Invoice_getRemainingTotalPayablePrice

fix Invoice_createRelatedPaymentTransaction to use
Invoice_getRemainingTotalPayablePrice



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@12548 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 33538959
...@@ -107,7 +107,7 @@ related_payment = portal.accounting_module.newContent(\n ...@@ -107,7 +107,7 @@ related_payment = portal.accounting_module.newContent(\n
)\n )\n
if is_source:\n if is_source:\n
related_payment.edit(destination_payment=context.getDestinationPayment(),\n related_payment.edit(destination_payment=context.getDestinationPayment(),\n
source_payment=payment)\n source_payment=payment)\n
section = context.getSourceSection()\n section = context.getSourceSection()\n
mirror_section = context.getDestinationSection()\n mirror_section = context.getDestinationSection()\n
else:\n else:\n
...@@ -120,99 +120,26 @@ bank = related_payment.newContent(\n ...@@ -120,99 +120,26 @@ bank = related_payment.newContent(\n
portal_type=line_portal_type,\n portal_type=line_portal_type,\n
id=\'bank\',\n id=\'bank\',\n
)\n )\n
\n
# Calculate the payable/receivable quantity, for this we sum all lines\n
# using a payable or receivable type account in this invoice ( unless this\n
# line have a "grouping reference") minus the sum of payable/receivable line on\n
# all causality related accounting transactions\n
bank_quantity = 0\n bank_quantity = 0\n
quantity_per_account = {}\n
for line in context.getMovementList(\n
portal_type=portal.getPortalAccountingMovementTypeList()):\n
\n
if line.getGroupingReference():\n
# we ignore line that have a \'letter\'\n
continue\n
\n
if is_source:\n
account = line.getSourceValue(portal_type=\'Account\')\n
mirror_account = line.getDestinationValue(portal_type=\'Account\')\n
line_section = line.getSourceSection()\n
line_mirror_section = line.getDestinationSection()\n
qty = -line.getQuantity()\n
else:\n
account = line.getDestinationValue(portal_type=\'Account\')\n
mirror_account = line.getSourceValue(portal_type=\'Account\')\n
line_section = line.getDestinationSection()\n
line_mirror_section = line.getSourceSection()\n
qty = line.getQuantity()\n
\n
key = (account, mirror_account)\n
if account is not None and \\\n
account.getAccountTypeId() in (\'payable\', \'receivable\'):\n
if line_section == section and line_mirror_section == mirror_section:\n
quantity_per_account[key] = quantity_per_account.get(key, 0) - qty\n
bank_quantity += qty\n
elif line_section == mirror_section and line_mirror_section == section:\n
quantity_per_account[key] = quantity_per_account.get(key, 0) + qty\n
bank_quantity -= qty\n
\n \n
for related_transaction in context.getCausalityRelatedValueList(\n # Calculate the payable/receivable quantity, using\n
portal_type=context.getPortalAccountingTransactionTypeList()):\n # Invoice_getRemainingTotalPayablePrice script.\n
# XXX copy n paste :(\n total_payable_price_details = \\\n
if related_transaction.getSimulationState() in (\n context.Invoice_getRemainingTotalPayablePrice(detailed=True)\n
\'draft\', \'cancelled\', \'deleted\'):\n for (line_node, line_mirror_section), quantity in\\\n
continue\n total_payable_price_details.items():\n
related_transaction_is_source = related_transaction.\\\n if line_mirror_section == mirror_section:\n
AccountingTransaction_isSourceView()\n bank_quantity += quantity\n
for line in related_transaction.getMovementList(\n
portal_type=portal.getPortalAccountingMovementTypeList()):\n
\n
if line.getGroupingReference():\n
# we ignore line that have a \'letter\'\n
continue\n
\n
if related_transaction_is_source:\n
account = line.getSourceValue(portal_type=\'Account\')\n
mirror_account = line.getDestinationValue(portal_type=\'Account\')\n
line_section = line.getSourceSection()\n
line_mirror_section = line.getDestinationSection()\n
else:\n
account = line.getDestinationValue(portal_type=\'Account\')\n
mirror_account = line.getSourceValue(portal_type=\'Account\')\n
line_section = line.getDestinationSection()\n
line_mirror_section = line.getSourceSection()\n
\n
if is_source:\n if is_source:\n
qty = -line.getQuantity()\n line = related_payment.newContent(\n
portal_type=line_portal_type,\n
source=line_node,\n
quantity=quantity)\n
else:\n else:\n
qty = line.getQuantity()\n line = related_payment.newContent(\n
\n portal_type=line_portal_type,\n
key = (account, mirror_account)\n destination=line_node,\n
if account is not None and \\\n quantity=-quantity)\n
account.getAccountTypeId() in (\'payable\', \'receivable\'):\n
if line_section == section and line_mirror_section == mirror_section:\n
quantity_per_account[key] = quantity_per_account.get(key, 0) - qty\n
bank_quantity += qty\n
\n
elif line_section == mirror_section and line_mirror_section == section:\n
quantity_per_account[key] = quantity_per_account.get(key, 0) + qty\n
bank_quantity -= qty\n
\n
# now create lines using the dictionnary\n
for (account, mirror_account), quantity in quantity_per_account.items():\n
if is_source:\n
related_payment.newContent(\n
portal_type=line_portal_type,\n
source_value=account,\n
destination_value=mirror_account,\n
quantity=-quantity)\n
else:\n
related_payment.newContent(\n
portal_type=line_portal_type,\n
source_value=mirror_account,\n
destination_value=account,\n
quantity=quantity)\n
\n \n
if is_source:\n if is_source:\n
bank.edit( source=node,\n bank.edit( source=node,\n
...@@ -241,6 +168,12 @@ else:\n ...@@ -241,6 +168,12 @@ else:\n
<none/> <none/>
</value> </value>
</item> </item>
<item>
<key> <string>_owner</string> </key>
<value>
<none/>
</value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>node, payment_mode, payment, date=None, batch_mode=0</string> </value> <value> <string>node, payment_mode, payment, date=None, batch_mode=0</string> </value>
...@@ -290,20 +223,13 @@ else:\n ...@@ -290,20 +223,13 @@ else:\n
<string>mirror_section</string> <string>mirror_section</string>
<string>bank</string> <string>bank</string>
<string>bank_quantity</string> <string>bank_quantity</string>
<string>quantity_per_account</string> <string>True</string>
<string>total_payable_price_details</string>
<string>_getiter_</string> <string>_getiter_</string>
<string>line</string> <string>line_node</string>
<string>account</string>
<string>mirror_account</string>
<string>line_section</string>
<string>line_mirror_section</string> <string>line_mirror_section</string>
<string>qty</string>
<string>key</string>
<string>None</string>
<string>_write_</string>
<string>related_transaction</string>
<string>related_transaction_is_source</string>
<string>quantity</string> <string>quantity</string>
<string>line</string>
</tuple> </tuple>
</value> </value>
</item> </item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>Products.PythonScripts.PythonScript</string>
<string>PythonScript</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Python_magic</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</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>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
"""Returns the difference between the original total payable price of this\n
invoice and all payments that have been made on this invoice.\n
For this, we use both causality relation between transactions and grouping\n
reference for lines.\n
If `detailed` argument is set to a true value, instead of returning the price\n
as a float value, it returns a mapping (node, mirror_section) -> total_price.\n
"""\n
portal = context.getPortalObject()\n
total_payable_price_per_node_section = dict()\n
\n
if context.AccountingTransaction_isSourceView():\n
is_source = 1\n
section = context.getSourceSection()\n
else:\n
is_source = 0\n
section = context.getDestinationSection()\n
\n
\n
# calculate the total price of this invoice (according to accounting\n
# transaction lines)\n
groupped_line_list = []\n
for line in context.getMovementList(\n
portal_type=portal.getPortalAccountingMovementTypeList()):\n
\n
if line.getGroupingReference():\n
continue\n
\n
if is_source:\n
node_value = line.getSourceValue(portal_type=\'Account\')\n
line_section = line.getSourceSection()\n
mirror_section = line.getDestinationSection()\n
amount = line.getSourceInventoriatedTotalAssetPrice() or 0\n
else:\n
node_value = line.getDestinationValue(portal_type=\'Account\')\n
line_section = line.getDestinationSection()\n
mirror_section = line.getSourceSection()\n
amount = line.getDestinationInventoriatedTotalAssetPrice() or 0\n
\n
if node_value is not None and \\\n
node_value.getAccountTypeId() in (\'payable\', \'receivable\'):\n
key = (node_value.getRelativeUrl(), mirror_section)\n
total_payable_price_per_node_section[key] =\\\n
total_payable_price_per_node_section.get(key, 0) + amount\n
if line.getGroupingReference():\n
# we rememeber this line to check if there is any line grouped with it\n
groupped_line_list.append(line)\n
\n
\n
# substract all causalities\n
for related_transaction in context.getCausalityRelatedValueList(\n
portal_type=context.getPortalAccountingTransactionTypeList()):\n
if related_transaction.getSimulationState() in (\n
\'draft\', \'cancelled\', \'deleted\'):\n
continue\n
related_transaction_is_source = related_transaction.\\\n
AccountingTransaction_isSourceView()\n
for line in related_transaction.getMovementList(\n
portal_type=portal.getPortalAccountingMovementTypeList()):\n
\n
if line.getGroupingReference():\n
continue\n
\n
if related_transaction_is_source:\n
node_value = line.getSourceValue(portal_type=\'Account\')\n
line_section = line.getSourceSection()\n
mirror_section = line.getDestinationSection()\n
amount = line.getSourceInventoriatedTotalAssetPrice() or 0\n
else:\n
node_value = line.getDestinationValue(portal_type=\'Account\')\n
line_section = line.getDestinationSection()\n
mirror_section = line.getSourceSection()\n
amount = line.getDestinationInventoriatedTotalAssetPrice() or 0\n
\n
if node_value is not None and \\\n
node_value.getAccountTypeId() in (\'payable\', \'receivable\'):\n
key = (node_value.getRelativeUrl(), mirror_section)\n
total_payable_price_per_node_section[key] =\\\n
total_payable_price_per_node_section.get(key, 0) + amount\n
\n
if detailed:\n
return total_payable_price_per_node_section\n
else:\n
return sum(total_payable_price_per_node_section.values())\n
]]></string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_filepath</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_owner</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>detailed=0</string> </value>
</item>
<item>
<key> <string>errors</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>func_code</string> </key>
<value>
<object>
<klass>
<global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>co_argcount</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>detailed</string>
<string>_getattr_</string>
<string>context</string>
<string>portal</string>
<string>dict</string>
<string>total_payable_price_per_node_section</string>
<string>is_source</string>
<string>section</string>
<string>groupped_line_list</string>
<string>_getiter_</string>
<string>line</string>
<string>node_value</string>
<string>line_section</string>
<string>mirror_section</string>
<string>amount</string>
<string>None</string>
<string>key</string>
<string>_write_</string>
<string>related_transaction</string>
<string>related_transaction_is_source</string>
<string>sum</string>
</tuple>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>func_defaults</string> </key>
<value>
<tuple>
<int>0</int>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Invoice_getRemainingTotalPayablePrice</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
172 173
\ No newline at end of file \ No newline at end of file
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