Related to Issue
31202. Code Review changes.
While looking for existing Processed Transactions for a Product
it now takes into account costing dimensions, such as Warehouse.
--- a/src/org/openbravo/costing/CostingServer.java Mon Oct 26 16:40:52 2015 +0100
+++ b/src/org/openbravo/costing/CostingServer.java Thu Nov 12 11:48:27 2015 +0100
@@ -294,7 +294,9 @@
&& !adjustmentAlreadyCreated
&& (currentStock.compareTo(transaction.getMovementQuantity()) < 0 || (trxType != TrxType.InventoryOpening
&& currentStock.compareTo(transaction.getMovementQuantity()) == 0 && CostingUtils
- .existsProcessedTransactions(transaction.getProduct())))) {
+ .existsProcessedTransactions(transaction.getProduct(),
+ getCostingAlgorithm().costDimensions, getOrganization(), transaction, transaction
+ .getProduct().isProduction())))) {
CostAdjustment costAdjustmentHeader = CostAdjustmentUtils.insertCostAdjustmentHeader(
transaction.getOrganization(), "NSC"); // NSC= Negative Stock Correction
--- a/src/org/openbravo/costing/CostingUtils.java Mon Oct 26 16:40:52 2015 +0100
+++ b/src/org/openbravo/costing/CostingUtils.java Thu Nov 12 11:48:27 2015 +0100
@@ -608,11 +608,30 @@
/**
* Check if exists processed transactions for this product
*/
- public static boolean existsProcessedTransactions(Product product) {
+ public static boolean existsProcessedTransactions(Product product,
+ HashMap<CostDimension, BaseOBObject> _costDimensions, Organization costorg,
+ MaterialTransaction trx, boolean isManufacturingProduct) {
+
+ // Get child tree of organizations.
+ OrganizationStructureProvider osp = OBContext.getOBContext().getOrganizationStructureProvider(
+ trx.getClient().getId());
+ Set<String> orgs = osp.getChildTree(costorg.getId(), true);
+ HashMap<CostDimension, BaseOBObject> costDimensions = _costDimensions;
+ if (isManufacturingProduct) {
+ orgs = osp.getChildTree("0", false);
+ costDimensions = CostingUtils.getEmptyDimensions();
+ }
+
OBCriteria<MaterialTransaction> criteria = OBDal.getInstance().createCriteria(
MaterialTransaction.class);
criteria.add(Restrictions.eq(MaterialTransaction.PROPERTY_PRODUCT, product));
criteria.add(Restrictions.eq(MaterialTransaction.PROPERTY_ISPROCESSED, true));
+ criteria.add(Restrictions.in(MaterialTransaction.PROPERTY_ORGANIZATION + ".id", orgs));
+ if (costDimensions.get(CostDimension.Warehouse) != null) {
+ criteria.add(Restrictions
+ .eq(MaterialTransaction.PROPERTY_STORAGEBIN + "." + Locator.PROPERTY_WAREHOUSE + ".id",
+ costDimensions.get(CostDimension.Warehouse).getId()));
+ }
criteria.setFilterOnReadableOrganization(false);
criteria.setMaxResults(1);
return criteria.uniqueResult() != null;