Author: jleroux
Date: Sun Feb 9 11:12:11 2014
New Revision: 1566273
URL: http://svn.apache.org/r1566273
Log:
A patch from Chris Lombardi for "Void item, quantity update, and discounts
don't work for configurable items"
https://issues.apache.org/jira/browse/OFBIZ-5535
Void item, quantity update and discounts work off of the sku in the pos. I
fixed it to use the cart index so these operations will work when there are
multiple configurations per sku in the cart.
Modified:
ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java
ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/event/ManagerEvents.java
ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/event/MenuEvents.java
Modified: ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java?rev=1566273&r1=1566272&r2=1566273&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java
(original)
+++ ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java Sun
Feb 9 11:12:11 2014
@@ -118,7 +118,6 @@ public class PosTransaction implements S
protected int drawerIdx = 0;
private GenericValue shipAddress = null;
- private Map<String, Integer> skuDiscounts = FastMap.newInstance();
private int cartDiscount = -1;
@@ -419,13 +418,14 @@ public class PosTransaction implements S
return payInfo;
}
- public BigDecimal getItemQuantity(String productId) {
- trace("request item quantity", productId);
- ShoppingCartItem item = cart.findCartItem(productId, null, null, null,
BigDecimal.ZERO);
+ public BigDecimal getItemQuantity(String cartIndex) {
+ trace("request item quantity", cartIndex);
+ int index = Integer.parseInt(cartIndex);
+ ShoppingCartItem item = cart.findCartItem(index);
if (item != null) {
return item.getQuantity();
} else {
- trace("item not found", productId);
+ trace("item not found", cartIndex);
return BigDecimal.ZERO;
}
}
@@ -517,11 +517,11 @@ public class PosTransaction implements S
}
}
- public void addItem(String productId, ProductConfigWrapper pcw)
+ public void addItem(String productId, BigDecimal quantity,
ProductConfigWrapper pcw)
throws ItemNotFoundException, CartItemModifyException {
- trace("add item with ProductConfigWrapper", productId);
+ trace("add item with ProductConfigWrapper", productId + "/" +
quantity);
try {
- cart.addOrIncreaseItem(productId, null, BigDecimal.ONE, null,
null, null, null, null, null, null, null, pcw, null, null, null,
session.getDispatcher());
+ cart.addOrIncreaseItem(productId, null, quantity, null, null,
null, null, null, null, null, null, pcw, null, null, null,
session.getDispatcher());
} catch (ItemNotFoundException e) {
trace("item not found", e);
throw e;
@@ -557,9 +557,10 @@ public class PosTransaction implements S
return;
}
- public void modifyQty(String productId, BigDecimal quantity) throws
CartItemModifyException {
- trace("modify item quantity", productId + "/" + quantity);
- ShoppingCartItem item = cart.findCartItem(productId, null, null, null,
BigDecimal.ZERO);
+ public void modifyQty(String cartIndex, BigDecimal quantity) throws
CartItemModifyException {
+ trace("modify item quantity", cartIndex + "/" + quantity);
+ int index = Integer.parseInt(cartIndex);
+ ShoppingCartItem item = cart.findCartItem(index);
if (item != null) {
try {
item.setQuantity(quantity, session.getDispatcher(), cart,
true);
@@ -569,21 +570,22 @@ public class PosTransaction implements S
throw e;
}
} else {
- trace("item not found", productId);
+ trace("item not found", cartIndex);
}
}
- public void modifyPrice(String productId, BigDecimal price) {
- trace("modify item price", productId + "/" + price);
- ShoppingCartItem item = cart.findCartItem(productId, null, null, null,
BigDecimal.ZERO);
+ public void modifyPrice(String cartIndex, BigDecimal price) {
+ trace("modify item price", cartIndex + "/" + price);
+ int index = Integer.parseInt(cartIndex);
+ ShoppingCartItem item = cart.findCartItem(index);
if (item != null) {
item.setBasePrice(price);
} else {
- trace("item not found", productId);
+ trace("item not found", cartIndex);
}
}
- public void addDiscount(String productId, BigDecimal discount, boolean
percent) {
+ public void addDiscount(String cartIndex, BigDecimal discount, boolean
percent) {
GenericValue adjustment =
session.getDelegator().makeValue("OrderAdjustment");
adjustment.set("orderAdjustmentTypeId", "DISCOUNT_ADJUSTMENT");
if (percent) {
@@ -592,15 +594,15 @@ public class PosTransaction implements S
adjustment.set("amount", discount);
}
- if (productId != null) {
+ if (cartIndex != null) {
trace("add item adjustment");
- ShoppingCartItem item = cart.findCartItem(productId, null, null,
null, BigDecimal.ZERO);
- Integer itemAdj = skuDiscounts.get(productId);
- if (itemAdj != null) {
- item.removeAdjustment(itemAdj.intValue());
+ int iCartIndex = Integer.parseInt(cartIndex);
+ ShoppingCartItem item = cart.findCartItem(iCartIndex);
+ List<GenericValue> adjustments = item.getAdjustments();
+ for (GenericValue gvAdjustment : adjustments){
+ item.removeAdjustment(gvAdjustment);
}
int idx = item.addAdjustment(adjustment);
- skuDiscounts.put(productId, idx);
} else {
trace("add sale adjustment");
if (cartDiscount > -1) {
@@ -615,11 +617,13 @@ public class PosTransaction implements S
cart.removeAdjustment(cartDiscount);
cartDiscount = -1;
}
- for (String productId : skuDiscounts.keySet()) {
- ShoppingCartItem item = cart.findCartItem(productId, null, null,
null, BigDecimal.ZERO);
- Integer itemAdj = skuDiscounts.remove(productId);
- if (itemAdj != null) {
- item.removeAdjustment(itemAdj.intValue());
+
+ Iterator<ShoppingCartItem> cartIterator = cart.iterator();
+ while(cartIterator.hasNext()){
+ ShoppingCartItem item = (ShoppingCartItem) cartIterator.next();
+ List<GenericValue> adjustments = item.getAdjustments();
+ for (GenericValue gvAdjustment : adjustments){
+ item.removeAdjustment(gvAdjustment);
}
}
}
@@ -628,22 +632,18 @@ public class PosTransaction implements S
return cart.getOrderOtherAdjustmentTotal();
}
- public void voidItem(String productId) throws CartItemModifyException {
- trace("void item", productId);
- ShoppingCartItem item = cart.findCartItem(productId, null, null, null,
BigDecimal.ZERO);
- if (item != null) {
+ public void voidItem(String cartIndex) throws CartItemModifyException {
+ trace("void item", cartIndex);
+ int index;
try {
- int itemIdx = cart.getItemIndex(item);
- cart.removeCartItem(itemIdx, session.getDispatcher());
+ index = Integer.parseInt(cartIndex);
+ cart.removeCartItem(index, session.getDispatcher());
} catch (CartItemModifyException e) {
Debug.logError(e, module);
- trace("void item error", productId, e);
+ trace("void item error", cartIndex, e);
throw e;
}
- } else {
- trace("item not found", productId);
}
- }
public void voidSale(PosScreen pos) {
trace("void sale");
Modified:
ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/event/ManagerEvents.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/event/ManagerEvents.java?rev=1566273&r1=1566272&r2=1566273&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/event/ManagerEvents.java
(original)
+++ ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/event/ManagerEvents.java
Sun Feb 9 11:12:11 2014
@@ -72,13 +72,13 @@ public class ManagerEvents {
public static synchronized void modifyPrice(PosScreen pos) {
PosTransaction trans = PosTransaction.getCurrentTx(pos.getSession());
- String sku = null;
+ String cartIndex = null;
try {
- sku = MenuEvents.getSelectedItem(pos);
+ cartIndex = MenuEvents.getSelectedIdx(pos);
} catch (ArrayIndexOutOfBoundsException e) {
}
- if (sku == null) {
+ if (cartIndex == null) {
pos.getOutput().print(UtilProperties.getMessage(PosTransaction.resource,"PosInvalidSelection",Locale.getDefault()));
pos.getJournal().refresh(pos);
pos.getInput().clear();
@@ -97,7 +97,7 @@ public class ManagerEvents {
if (parsed) {
price = price.movePointLeft(2);
- trans.modifyPrice(sku, price);
+ trans.modifyPrice(cartIndex, price);
// re-calc tax
trans.calcTax();
Modified: ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/event/MenuEvents.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/event/MenuEvents.java?rev=1566273&r1=1566272&r2=1566273&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/event/MenuEvents.java
(original)
+++ ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/event/MenuEvents.java Sun
Feb 9 11:12:11 2014
@@ -216,7 +216,7 @@ public class MenuEvents {
if (!aggregatedItem) {
trans.addItem(productId, quantity);
} else {
- trans.addItem(productId, pcw);
+ trans.addItem(productId, quantity, pcw);
}
} catch (CartItemModifyException e) {
Debug.logError(e, module);
@@ -241,13 +241,13 @@ public class MenuEvents {
public static synchronized void changeQty(PosScreen pos) {
PosTransaction trans = PosTransaction.getCurrentTx(pos.getSession());
- String sku = null;
+ String index = null;
try {
- sku = getSelectedItem(pos);
+ index = getSelectedIdx(pos);
} catch (ArrayIndexOutOfBoundsException e) {
}
- if (sku == null) {
+ if (index == null) {
pos.getOutput().print("Invalid Selection!");
pos.getJournal().refresh(pos);
pos.getInput().clear();
@@ -271,16 +271,16 @@ public class MenuEvents {
try {
quantity = new BigDecimal(func[1]);
} catch (NumberFormatException e) {
- quantity = trans.getItemQuantity(sku);
+ quantity = trans.getItemQuantity(index);
}
}
}
// adjust the quantity
- quantity = (increment ? trans.getItemQuantity(sku).add(quantity) :
quantity);
+ quantity = (increment ? trans.getItemQuantity(index).add(quantity) :
quantity);
try {
- trans.modifyQty(sku, quantity);
+ trans.modifyQty(index, quantity);
} catch (CartItemModifyException e) {
Debug.logError(e, module);
pos.showDialog("dialog/error/producterror");
@@ -328,13 +328,13 @@ public class MenuEvents {
if (!trans.isOpen()) {
pos.showDialog("dialog/error/terminalclosed");
} else {
- String sku = null;
+ String index = null;
try {
- sku = getSelectedItem(pos);
+ index = getSelectedIdx(pos);
} catch (ArrayIndexOutOfBoundsException e) {
}
- if (sku == null) {
+ if (index == null) {
pos.getOutput().print("Invalid Selection!");
pos.getJournal().refresh(pos);
pos.getInput().clear();
@@ -355,7 +355,7 @@ public class MenuEvents {
}
amount = amount.movePointLeft(2).negate();
- trans.addDiscount(sku, amount, percent);
+ trans.addDiscount(index, amount, percent);
trans.calcTax();
}
}
@@ -379,20 +379,20 @@ public class MenuEvents {
public static synchronized void voidItem(PosScreen pos) {
PosTransaction trans = PosTransaction.getCurrentTx(pos.getSession());
- String sku = null;
+ String index = null;
try {
- sku = getSelectedItem(pos);
+ index = getSelectedIdx(pos);
} catch (ArrayIndexOutOfBoundsException e) {
}
- if (sku == null) {
+ if (index == null) {
pos.getOutput().print("Invalid Selection!");
pos.getJournal().refresh(pos);
pos.getInput().clear();
}
try {
- trans.voidItem(sku);
+ trans.voidItem(index);
} catch (CartItemModifyException e) {
pos.getOutput().print(e.getMessage());
}
@@ -425,6 +425,11 @@ public class MenuEvents {
return journal.getSelectedSku();
}
+ public static synchronized String getSelectedIdx(PosScreen pos) {
+ Journal journal = pos.getJournal();
+ return journal.getSelectedIdx();
+ }
+
public static synchronized void configureItem(PosScreen pos) {
PosTransaction trans = PosTransaction.getCurrentTx(pos.getSession());
Journal journal = pos.getJournal();