Author: lektran
Date: Fri Nov 13 04:48:51 2009
New Revision: 835738
URL: http://svn.apache.org/viewvc?rev=835738&view=rev
Log:
During invoiceServiceItems check to make sure each item hasn't already been
invoiced before sending it off to createInvoiceForOrder, fixes OFBIZ-3084
reported by Jacques Le Roux
Modified:
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java
Modified:
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java?rev=835738&r1=835737&r2=835738&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java
(original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java
Fri Nov 13 04:48:51 2009
@@ -3225,11 +3225,21 @@
// now process the service items
if (UtilValidate.isNotEmpty(serviceItems)) {
+ // Make sure there is actually something needing invoicing because
createInvoiceForOrder doesn't check
+ List<GenericValue> billItems = FastList.newInstance();
+ for (GenericValue item : serviceItems) {
+ BigDecimal orderQuantity =
OrderReadHelper.getOrderItemQuantity(item);
+ BigDecimal invoiceQuantity =
OrderReadHelper.getOrderItemInvoicedQuantity(item);
+ BigDecimal outstandingQuantity =
orderQuantity.subtract(invoiceQuantity);
+ if (outstandingQuantity.compareTo(ZERO) > 0) {
+ billItems.add(item);
+ }
+ }
// do something tricky here: run as a different user that can
actually create an invoice, post transaction, etc
Map<String, Object> invoiceResult = null;
try {
GenericValue permUserLogin = ServiceUtil.getUserLogin(dctx,
context, "system");
- Map<String, Object> invoiceContext = UtilMisc.toMap("orderId",
orderId, "billItems", serviceItems, "userLogin", permUserLogin);
+ Map<String, Object> invoiceContext = UtilMisc.toMap("orderId",
orderId, "billItems", billItems, "userLogin", permUserLogin);
invoiceResult = dispatcher.runSync("createInvoiceForOrder",
invoiceContext);
} catch (GenericServiceException e) {
Debug.logError(e, "ERROR: Unable to invoice service items",
module);