Attached Files | fixStockValidation1.1.500.diff [^] (9,088 bytes) 2017-01-13 19:41 [Show Content] [Hide Content]diff --git a/src/org/openbravo/retail/stockvalidation/OrderFromQuotationStockChecker.java b/src/org/openbravo/retail/stockvalidation/OrderFromQuotationStockChecker.java
--- a/src/org/openbravo/retail/stockvalidation/OrderFromQuotationStockChecker.java
+++ b/src/org/openbravo/retail/stockvalidation/OrderFromQuotationStockChecker.java
@@ -23,46 +23,56 @@
try {
JSONArray dataToReturn = new JSONArray();
for (int i = 0; i < linesOfTicket.length(); i++) {
+ JSONObject preFinalResult = new JSONObject();
JSONObject currentTicketLine = linesOfTicket.getJSONObject(i);
-
- BigDecimal unitsFound = new BigDecimal(0);
-
- String orgId = OBContext.getOBContext().getCurrentOrganization().getId();
- String productId = "";
- String productIdentifier = "";
- String lineIndex = "";
- BigDecimal qtyToBuy;
- currentTicketLine = linesOfTicket.getJSONObject(i);
- qtyToBuy = new BigDecimal(currentTicketLine.getString("qty"));
- productId = currentTicketLine.getString("productid");
- productIdentifier = currentTicketLine.getString("productidentifier");
- lineIndex = currentTicketLine.getString("index");
- String hqlQuery = "select sum(ms.quantityOnHand) as qtyonhand "
- + "from MaterialMgmtStorageDetail ms " + "where ms.storageBin.warehouse.id in ("
- + "SELECT ow.warehouse.id " + "FROM OrganizationWarehouse as ow " + "WHERE "
- + "ow.organization.id = '" + orgId + "') " + "and ms.product.id = '" + productId + "'";
-
- final Session session = OBDal.getInstance().getSession();
- final Query query = session.createQuery(hqlQuery);
-
- if (query.uniqueResult() != null) {
- unitsFound = new BigDecimal(query.uniqueResult().toString());
- } else {
- unitsFound = BigDecimal.ZERO;
+ Boolean stocked = true;
+ if (currentTicketLine.has("stocked")) {
+ stocked = currentTicketLine.getBoolean("stocked");
}
- if (unitsFound.compareTo(qtyToBuy) >= 0) {
+ if (stocked) {
+ BigDecimal unitsFound = new BigDecimal(0);
+
+ String orgId = OBContext.getOBContext().getCurrentOrganization().getId();
+ String productId = "";
+ String productIdentifier = "";
+ String lineIndex = "";
+ BigDecimal qtyToBuy;
+ currentTicketLine = linesOfTicket.getJSONObject(i);
+ qtyToBuy = new BigDecimal(currentTicketLine.getString("qty"));
+ productId = currentTicketLine.getString("productid");
+ productIdentifier = currentTicketLine.getString("productidentifier");
+ lineIndex = currentTicketLine.getString("index");
+ String hqlQuery = "select sum(ms.quantityOnHand) as qtyonhand "
+ + "from MaterialMgmtStorageDetail ms " + "where ms.storageBin.warehouse.id in ("
+ + "SELECT ow.warehouse.id " + "FROM OrganizationWarehouse as ow " + "WHERE "
+ + "ow.organization.id = :orgId) and ms.product.id = :productId ";
+
+ final Session session = OBDal.getInstance().getSession();
+ final Query query = session.createQuery(hqlQuery);
+ query.setString("orgId", orgId);
+ query.setString("productId", productId);
+
+ if (query.uniqueResult() != null) {
+ unitsFound = new BigDecimal(query.uniqueResult().toString());
+ } else {
+ unitsFound = BigDecimal.ZERO;
+ }
+
+ allowSell = unitsFound.compareTo(qtyToBuy) >= 0;
+
+ preFinalResult.put("allowSell", allowSell);
+ if (allowSell == false) {
+ preFinalResult.put("availableQty", unitsFound);
+ preFinalResult.put("originalQty", qtyToBuy);
+ preFinalResult.put("productIdentifier", productIdentifier);
+ preFinalResult.put("index", lineIndex);
+ }
+ } else {
allowSell = true;
+ preFinalResult.put("allowSell", allowSell);
}
- JSONObject preFinalResult = new JSONObject();
- preFinalResult.put("allowSell", allowSell);
- if (allowSell == false) {
- preFinalResult.put("availableQty", unitsFound);
- preFinalResult.put("originalQty", qtyToBuy);
- preFinalResult.put("productIdentifier", productIdentifier);
- preFinalResult.put("index", lineIndex);
- }
dataToReturn.put(preFinalResult);
}
JSONObject finalResult = new JSONObject();
diff --git a/web/org.openbravo.retail.stockvalidation/js/modals.js b/web/org.openbravo.retail.stockvalidation/js/modals.js
--- a/web/org.openbravo.retail.stockvalidation/js/modals.js
+++ b/web/org.openbravo.retail.stockvalidation/js/modals.js
@@ -120,13 +120,13 @@
label: OB.I18N.getLabel('OBMOBC_LblCancel')
}], {
onHideFunction: function (popup) {
+ var count = 0;
_.each(notValidLines, function (curLine) {
if (curLine.availableQty <= 0) {
- me.model.get('order').deleteLine(me.model.get('order').get('lines').at(curLine.index));
+ me.model.get('order').deleteLine(me.model.get('order').get('lines').at(curLine.index - count));
+ count++;
} else {
- me.model.get('order').get('lines').at(curLine.index).set('qty', curLine.availableQty, {
- silent: true
- });
+ me.model.get('order').get('lines').at(curLine.index - count).set('qty', curLine.availableQty);
}
}, this);
},
@@ -142,13 +142,13 @@
modalMessage = modalMessage + OB.I18N.getLabel('OBPOSSV_notAllowedNegativeStock');
OB.UTIL.showConfirmation.display(OB.I18N.getLabel('OBPOSSV_modalHeader'), modalMessage, null, {
onHideFunction: function (popup) {
+ var count = 0;
_.each(notValidLines, function (curLine) {
if (curLine.availableQty <= 0) {
- me.model.get('order').deleteLine(me.model.get('order').get('lines').at(curLine.index));
+ me.model.get('order').deleteLine(me.model.get('order').get('lines').at(curLine.index - count));
+ count++;
} else {
- me.model.get('order').get('lines').at(curLine.index).set('qty', curLine.availableQty, {
- silent: true
- });
+ me.model.get('order').get('lines').at(curLine.index - count).set('qty', curLine.availableQty);
}
}, this);
}
@@ -167,29 +167,34 @@
if (!OB.MobileApp.model.hasPermission('OBPOSSV_EnableStockValidation', true)) {
return;
}
- if (!addedModel.get('product').get('stocked') || addedModel.get('qty') < 0 || this.model.get('order').get('orderType') === 1 || this.model.get('order').get('isPaid') === true || this.model.get('order').get('isQuotation') === true) {
- return;
- }
- executeCallToServer(addedModel);
addedModel.on('change:qty', function (changedModel) {
if (!addedModel.get('product').get('stocked') || addedModel.get('qty') < 0 || this.model.get('order').get('orderType') === 1 || this.model.get('order').get('isPaid') === true || this.model.get('order').get('isQuotation') === true) {
return;
}
executeCallToServer(changedModel);
}, this);
+ if (!addedModel.get('product').get('stocked') || addedModel.get('qty') < 0 || this.model.get('order').get('orderType') === 1 || this.model.get('order').get('isPaid') === true || this.model.get('order').get('isQuotation') === true) {
+ return;
+ }
+ executeCallToServer(addedModel);
}, this);
this.model.get('order').on('orderCreatedFromQuotation', function () {
var dataToSend = [];
_.each(this.model.get('order').get('lines').models, function (curLine, index) {
var lineToSend = {};
- lineToSend.productid = curLine.get('product').id;
- lineToSend.productidentifier = curLine.get('product').get('_identifier');
- lineToSend.qty = curLine.get('qty');
- lineToSend.index = index;
- dataToSend.push(lineToSend);
+ if (curLine.get('product').get('stocked')) {
+ lineToSend.productid = curLine.get('product').id;
+ lineToSend.productidentifier = curLine.get('product').get('_identifier');
+ lineToSend.qty = curLine.get('qty');
+ lineToSend.index = index;
+ lineToSend.stocked = curLine.get('product').get('stocked');
+ dataToSend.push(lineToSend);
+ }
}, this);
- executeCallToServerForNewOrderFromQuotation(dataToSend);
+ if (dataToSend.length > 0) {
+ executeCallToServerForNewOrderFromQuotation(dataToSend);
+ }
}, this);
}
});
|