Commit 7eec86d9 authored by Jérome Perrin's avatar Jérome Perrin

when creating a related payement, use the quantities from the movements, not...

when creating a related payement, use the quantities from the movements, not the asset price. In case of foreign currency, we want to pay the amount in foreign currency, not the converted amount

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@34491 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent bbb181e2
......@@ -79,7 +79,8 @@ portal.portal_selections.setSelectionParamsFor(\n
# Calculate the payable/receivable quantity, using\n
# Invoice_getRemainingTotalPayablePrice script.\n
total_payable_price_details = \\\n
context.Invoice_getRemainingTotalPayablePrice(detailed=True)\n
context.Invoice_getRemainingTotalPayablePrice(detailed=True,\n
quantity=True)\n
\n
# if there\'s nothing more to pay, don\'t create an empty transaction\n
if sum(total_payable_price_details.values()) == 0:\n
......
......@@ -76,6 +76,10 @@ only transactions in those states. By default it will use all but \'draft\', \n
\n
The `mirror_section_relative_url` parameter must be passed explicitly if the\n
context invoice has multiple sections.\n
\n
If `quantity` parameter is true, this script will return the quantities in the\n
original transaction currency. If currencies on this invoice and the related\n
payments are not consistent, a ValueError is raised.\n
"""\n
portal = context.getPortalObject()\n
total_payable_price_per_node_section = dict()\n
......@@ -115,6 +119,7 @@ def getIsSourceMovementItemList(invoice):\n
return movement_item_list\n
\n
\n
invoice_currency = context.getResource()\n
# calculate the total price of this invoice (according to accounting\n
# transaction lines)\n
for is_source, line in getIsSourceMovementItemList(context):\n
......@@ -123,12 +128,18 @@ for is_source, line in getIsSourceMovementItemList(context):\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
if quantity:\n
amount = -line.getQuantity()\n
else:\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
if quantity:\n
amount = line.getQuantity()\n
else:\n
amount = line.getDestinationInventoriatedTotalAssetPrice() or 0\n
\n
if at_date is None and line.getGroupingReference():\n
continue\n
......@@ -185,18 +196,30 @@ for related_transaction in related_transaction_list:\n
\n
if at_date is None and line.getGroupingReference():\n
continue\n
\n
if quantity:\n
if line.getResource() != invoice_currency:\n
raise ValueError("Unable to calculate"\n
", related transaction %s uses different currency" %\n
line.getRelativeUrl())\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
if quantity:\n
amount = -line.getQuantity()\n
else:\n
amount = line.getSourceInventoriatedTotalAssetPrice() or 0\n
date = line.getStartDate().earliestTime()\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
if quantity:\n
amount = -line.getQuantity()\n
else:\n
amount = line.getDestinationInventoriatedTotalAssetPrice() or 0\n
date = line.getStopDate().earliestTime()\n
\n
if node_value is not None:\n
......@@ -233,7 +256,7 @@ else:\n
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>detailed=0, at_date=None, account_id=None, simulation_state=None, mirror_section_relative_url=None</string> </value>
<value> <string>detailed=0, at_date=None, account_id=None, simulation_state=None, mirror_section_relative_url=None, quantity=False</string> </value>
</item>
<item>
<key> <string>errors</string> </key>
......@@ -253,7 +276,7 @@ else:\n
<dictionary>
<item>
<key> <string>co_argcount</string> </key>
<value> <int>5</int> </value>
<value> <int>6</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
......@@ -264,6 +287,7 @@ else:\n
<string>account_id</string>
<string>simulation_state</string>
<string>mirror_section_relative_url</string>
<string>quantity</string>
<string>_getattr_</string>
<string>context</string>
<string>portal</string>
......@@ -281,6 +305,7 @@ else:\n
<string>str</string>
<string>accounting_transaction_type_list</string>
<string>getIsSourceMovementItemList</string>
<string>invoice_currency</string>
<string>is_source</string>
<string>line</string>
<string>node_value</string>
......@@ -321,6 +346,7 @@ else:\n
<none/>
<none/>
<none/>
<int>0</int>
</tuple>
</value>
</item>
......
1163
\ No newline at end of file
1164
\ 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