Attached Files | LocatorBOMHook.diff [^] (6,394 bytes) 2021-02-05 13:31 [Show Content] [Hide Content]diff -ru --new-file Original/BOMProcess.java Modificado/BOMProcess.java
--- a/src/org/openbravo/retail/autobom/process/BOMProcess.java 2020-08-07 14:04:53.000000000 +0200
+++ b/src/org/openbravo/retail/autobom/process/BOMProcess.java 2021-02-05 09:05:46.974783000 +0100
@@ -66,6 +66,10 @@
@Any
private Instance<BlockBOMProcessHook> blockBOMProcessHook;
+ @Inject
+ @Any
+ private Instance<LocatorBOMProcessHook> locatorBOMProcessHook;
+
public void createProcessBOM(JSONObject jsonorder) throws JSONException {
OBContext.setAdminMode(true);
@@ -110,11 +114,11 @@
productId = lineId + "," + productId;
}
bomProducts.put(productId, productBom);
- createRecurrencyBOM(product, qty, organization, date, productBom);
+ createRecurrencyBOM(product, qty, organization, date, productBom, jsonorder);
}
}
if (!bomProducts.isEmpty()) {
- createAndProcess(bomProducts, organization, date);
+ createAndProcess(bomProducts, organization, date, jsonorder);
}
} finally {
OBContext.restorePreviousMode();
@@ -136,8 +140,20 @@
return blocked;
}
+ private Locator getLocatorHook(JSONObject jsonorder) throws Exception {
+ Locator locator = null;
+ for (Iterator<LocatorBOMProcessHook> procIter = locatorBOMProcessHook.iterator(); procIter
+ .hasNext();) {
+ LocatorBOMProcessHook hook = procIter.next();
+ locator = hook.locatorBOM(jsonorder);
+ }
+
+ return locator;
+ }
+
private void createRecurrencyBOM(Product product, BigDecimal qty, Organization organization,
- Date date, CustomizedProductBom customizedProductBom) throws JSONException {
+ Date date, CustomizedProductBom customizedProductBom, JSONObject jsonorder)
+ throws JSONException {
Map<String, CustomizedProductBom> bomProducts = new HashMap<>();
BOMVersion version = checkVersion(product, date);
if (version != null) {
@@ -147,7 +163,7 @@
continue;
}
subRecurrencyBom(qty, pversion.getBOMQuantity(), bomProduct, bomProducts, organization,
- date);
+ date, jsonorder);
}
} else {
for (ProductBOM productBOM : product.getProductBOMList()) {
@@ -157,18 +173,18 @@
continue;
}
subRecurrencyBom(qty, productBOM.getBOMQuantity(), bomProduct, bomProducts, organization,
- date);
+ date, jsonorder);
}
}
if (!bomProducts.isEmpty()) {
- createAndProcess(bomProducts, organization, date);
+ createAndProcess(bomProducts, organization, date, jsonorder);
}
}
private void createAndProcess(Map<String, CustomizedProductBom> bomProducts,
- Organization organization, Date date) {
+ Organization organization, Date date, JSONObject jsonorder) {
ProductionTransaction production = createProduction(organization, date);
- createProductionPlan(production, bomProducts);
+ createProductionPlan(production, bomProducts, jsonorder);
processProduction(production);
}
@@ -185,7 +201,7 @@
}
private void createProductionPlan(ProductionTransaction productionTransaction,
- Map<String, CustomizedProductBom> bomProducts) {
+ Map<String, CustomizedProductBom> bomProducts, JSONObject jsonorder) {
List<ProductionPlan> productionPlanArray = new ArrayList<>();
long counter = 0;
@@ -207,7 +223,16 @@
}
product = OBDal.getInstance().get(Product.class, keyStr);
- Locator locator = getManufacturingLocator(product, productionTransaction.getOrganization());
+ Locator locator = null;
+ try {
+ locator = getLocatorHook(jsonorder);
+ } catch (Exception e) {
+ throw new OBException("Error in extension LocatorBOMProcessHook " + e.getMessage(), e);
+ }
+
+ if (locator == null) {
+ locator = getManufacturingLocator(product, productionTransaction.getOrganization());
+ }
ProductionPlan productionPlan = OBProvider.getInstance().get(ProductionPlan.class);
productionPlan.setOrganization(productionTransaction.getOrganization());
@@ -519,8 +544,8 @@
}
private void subRecurrencyBom(BigDecimal qty, BigDecimal bomQty, Product bomProduct,
- Map<String, CustomizedProductBom> bomProducts, Organization organization, Date date)
- throws JSONException {
+ Map<String, CustomizedProductBom> bomProducts, Organization organization, Date date,
+ JSONObject jsonorder) throws JSONException {
if (bomProduct.isBillOfMaterials() && bomProduct.isObbomAutogeneratebom()) {
BigDecimal stock = getStock(bomProduct, organization);
@@ -529,7 +554,8 @@
bomProducts.put(bomProduct.getId(),
new CustomizedProductBom(bomProduct, totalQty.subtract(stock), null));
- createRecurrencyBOM(bomProduct, totalQty.subtract(stock), organization, date, null);
+ createRecurrencyBOM(bomProduct, totalQty.subtract(stock), organization, date, null,
+ jsonorder);
}
}
diff -ru --new-file Original/LocatorBOMProcessHook.java Modificado/LocatorBOMProcessHook.java
--- a/src/org/openbravo/retail/autobom/process/LocatorBOMProcessHook.java 1970-01-01 01:00:00.000000000 +0100
+++ b/src/org/openbravo/retail/autobom/process/LocatorBOMProcessHook.java 2021-02-05 09:02:36.276643000 +0100
@@ -0,0 +1,28 @@
+/*
+ ************************************************************************************
+ * Copyright (C) 2021 Openbravo S.L.U.
+ * Licensed under the Openbravo Commercial License version 1.0
+ * You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html
+ * or in the legal folder of this module distribution.
+ ************************************************************************************
+ */
+package org.openbravo.retail.autobom.process;
+
+import org.codehaus.jettison.json.JSONObject;
+import org.openbravo.model.common.enterprise.Locator;
+
+/**
+ * Classes implementing this interface will be executed before running the autobom process.
+ *
+ */
+public abstract class LocatorBOMProcessHook {
+
+ /**
+ * Called before running autoBOM only for BOM and autoBOM products.
+ *
+ * @param jsonorder
+ * the order being loaded
+ * @return locator
+ */
+ public abstract Locator locatorBOM(JSONObject jsonorder) throws Exception;
+}
|