Commit 10d5d6ad authored by Vincent Pelletier's avatar Vincent Pelletier

invoicing: Copy lines by portal type, not by simulation relationship.

Simulation relationship fails in (at least) two cases:
- cancelling an invoice which was entirely created by simulation would
  create an empty invoice
- cancelling an invoice with simulated accounting lines generated from
  temp-object-based simulation would copy those lines, while they should
  not be copied
Also, implement recursive copy of Invoice Lines, as (per portal type
definition) they can be arbitrarily nested.
Also, prepare a place-holder for Invoice Cell copy. As I do not have a
document with cells at hand, and do not know all relevant properties, I
decided to keep this code disabled and raise.
parent a3e2202c
...@@ -54,6 +54,27 @@ ...@@ -54,6 +54,27 @@
This script is supposed to be the common denominator for invoice reversing operations.\n This script is supposed to be the common denominator for invoice reversing operations.\n
Instead of extending it, call it from project-specific script and edit returned document (or its lines).\n Instead of extending it, call it from project-specific script and edit returned document (or its lines).\n
"""\n """\n
def recursiveCopyLine(to_document, from_document):\n
newContent = to_document.newContent\n
for line in from_document.objectValues(portal_type=\'Invoice Line\'):\n
reverse_line = newContent(\n
description=line.getDescription(),\n
int_index=line.getIntIndex(),\n
portal_type=line.getPortalType(),\n
price=line.getPrice(),\n
quantity=-line.getQuantity(), # Notice the "-" !\n
reference=line.getReference(),\n
category_list=line.getCategoryList(),\n
)\n
recursiveCopyLine(reverse_line, line)\n
newCell = reverse_line.newContent\n
for cell in line.objectValues(portal_type=\'Invoice Cell\'):\n
raise NotImplementedError\n
newCell(\n
# TODO: what properties ?\n
portal_type=cell.getPortalType(),\n
category_list=cell.getCategoryList(),\n
)\n
\n \n
portal = context.getPortalObject()\n portal = context.getPortalObject()\n
reverse_invoice = context.getParentValue().newContent(\n reverse_invoice = context.getParentValue().newContent(\n
...@@ -70,18 +91,7 @@ reverse_invoice.edit(\n ...@@ -70,18 +91,7 @@ reverse_invoice.edit(\n
price_currency_list=context.getPriceCurrencyList(),\n price_currency_list=context.getPriceCurrencyList(),\n
resource_list=context.getResourceList(),\n resource_list=context.getResourceList(),\n
)\n )\n
newContent = reverse_invoice.newContent\n recursiveCopyLine(reverse_invoice, context)\n
for line in context.objectValues():\n
if not line.isGeneratedBySimulation():\n
newContent(\n
description=line.getDescription(),\n
int_index=line.getIntIndex(),\n
portal_type=line.getPortalType(),\n
price=line.getPrice(),\n
quantity=-line.getQuantity(), # Notice the "-" !\n
reference=line.getReference(),\n
category_list=line.getCategoryList(),\n
)\n
return reverse_invoice\n return reverse_invoice\n
</string> </value> </string> </value>
</item> </item>
......
391 392
\ 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