List of usage examples for java.math BigDecimal ONE
BigDecimal ONE
To view the source code for java.math BigDecimal ONE.
Click Source Link
From source file:org.openbravo.test.costing.TestCosting.java
@Test public void testCostingLC5551() throws Exception { final int day0 = 0; final int day1 = 5; final int day2 = 10; final BigDecimal price1 = new BigDecimal("555.00"); final BigDecimal price2 = new BigDecimal("100.00"); final BigDecimal price3 = new BigDecimal("645.00"); final BigDecimal price4 = new BigDecimal("125.00"); final BigDecimal quantity1 = BigDecimal.ONE; final BigDecimal rate = new BigDecimal("0.90"); try {/*from ww w.ja v a 2 s . com*/ OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID); OBContext.setAdminMode(true); // Create a new product for the test Product product = createProduct(price1); // Create goods receipt, run costing background, post it and assert it ShipmentInOut goodsReceipt = createGoodsReceipt(product, price1, quantity1, day0); // Create Landed Cost List<String> landedCostTypeIdList = new ArrayList<String>(); landedCostTypeIdList.add(LANDEDCOSTTYPE3_ID); List<BigDecimal> amountList = new ArrayList<BigDecimal>(); amountList.add(quantity1.multiply(price2)); List<ShipmentInOut> receiptList = new ArrayList<ShipmentInOut>(); receiptList.add(goodsReceipt); LandedCost landedCost = createLandedCost(landedCostTypeIdList, amountList, receiptList, null, day1); // Create purchase invoice with landed cost, post it and assert it Invoice purchaseInvoiceLandedCost1 = createPurchaseInvoiceLandedCost(LANDEDCOSTTYPE3_ID, price2, quantity1, rate, day2); // Match invoice landed cost matchInvoiceLandedCost(purchaseInvoiceLandedCost1.getInvoiceLineList().get(0), landedCost.getLandedCostCostList().get(0), true); // Post landed cost cost and assert it postLandedCostLine(landedCost.getLandedCostCostList().get(0), purchaseInvoiceLandedCost1.getInvoiceLineList().get(0)); // Assert product transactions List<ProductTransactionAssert> productTransactionAssertList1 = new ArrayList<ProductTransactionAssert>(); productTransactionAssertList1.add( new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt.getId()) .getMaterialMgmtShipmentInOutLineList().get(0), price1, price3, price1)); assertProductTransaction(product.getId(), productTransactionAssertList1); // Assert product costing List<MaterialTransaction> transactionList = getProductTransactions(product.getId()); List<ProductCostingAssert> productCostingAssertList1 = new ArrayList<ProductCostingAssert>(); productCostingAssertList1 .add(new ProductCostingAssert(transactionList.get(0), price1, price1, price3, quantity1)); assertProductCosting(product.getId(), productCostingAssertList1); // Assert cost adjustment List<CostAdjustment> costAdjustmentList = getCostAdjustment(product.getId()); List<List<CostAdjustmentAssert>> costAdjustmentAssertList = new ArrayList<List<CostAdjustmentAssert>>(); List<CostAdjustmentAssert> costAdjustmentAssertLineList1 = new ArrayList<CostAdjustmentAssert>(); costAdjustmentAssertLineList1.add(new CostAdjustmentAssert(transactionList.get(0), CURRENCY2_ID, "LC", quantity1.multiply(price2), day1, true, false)); costAdjustmentAssertList.add(costAdjustmentAssertLineList1); List<CostAdjustmentAssert> costAdjustmentAssertLineList2 = new ArrayList<CostAdjustmentAssert>(); costAdjustmentAssertLineList2.add(new CostAdjustmentAssert(transactionList.get(0), CURRENCY2_ID, "LC", quantity1.multiply(price4), day1, true, false)); costAdjustmentAssertList.add(costAdjustmentAssertLineList2); assertCostAdjustment(costAdjustmentList, costAdjustmentAssertList); OBDal.getInstance().commitAndClose(); } catch (Exception e) { System.out.println(e.getMessage()); throw new OBException(e); } finally { OBContext.restorePreviousMode(); } }
From source file:org.openbravo.test.costing.TestCosting.java
@Test public void testCostingLC5552() throws Exception { final int day0 = 0; final int day1 = 5; final int day2 = 10; final BigDecimal price1 = new BigDecimal("555.00"); final BigDecimal price2 = new BigDecimal("100.00"); final BigDecimal price3 = new BigDecimal("645.00"); final BigDecimal price4 = new BigDecimal("125.00"); final BigDecimal quantity1 = BigDecimal.ONE; final BigDecimal rate = new BigDecimal("0.90"); try {//w ww . j a v a2s. com OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID); OBContext.setAdminMode(true); // Create a new product for the test Product product = createProduct(price1); // Create goods receipt, run costing background, post it and assert it ShipmentInOut goodsReceipt = createGoodsReceipt(product, price1, quantity1, day0); // Create purchase invoice with landed cost, post it and assert it Invoice purchaseInvoiceLandedCost1 = createPurchaseInvoiceLandedCost(LANDEDCOSTTYPE3_ID, price2, quantity1, rate, day1); // Create Landed Cost List<Invoice> invoiceList = new ArrayList<Invoice>(); invoiceList.add(purchaseInvoiceLandedCost1); List<ShipmentInOut> receiptList = new ArrayList<ShipmentInOut>(); receiptList.add(goodsReceipt); createLandedCost(invoiceList, receiptList, day2); // Assert product transactions List<ProductTransactionAssert> productTransactionAssertList1 = new ArrayList<ProductTransactionAssert>(); productTransactionAssertList1.add( new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt.getId()) .getMaterialMgmtShipmentInOutLineList().get(0), price1, price3, price1)); assertProductTransaction(product.getId(), productTransactionAssertList1); // Assert product costing List<MaterialTransaction> transactionList = getProductTransactions(product.getId()); List<ProductCostingAssert> productCostingAssertList1 = new ArrayList<ProductCostingAssert>(); productCostingAssertList1 .add(new ProductCostingAssert(transactionList.get(0), price1, price1, price3, quantity1)); assertProductCosting(product.getId(), productCostingAssertList1); // Assert cost adjustment List<CostAdjustment> costAdjustmentList = getCostAdjustment(product.getId()); List<List<CostAdjustmentAssert>> costAdjustmentAssertList = new ArrayList<List<CostAdjustmentAssert>>(); List<CostAdjustmentAssert> costAdjustmentAssertLineList1 = new ArrayList<CostAdjustmentAssert>(); costAdjustmentAssertLineList1.add(new CostAdjustmentAssert(transactionList.get(0), CURRENCY2_ID, "LC", quantity1.multiply(price4), day2, true, false)); costAdjustmentAssertList.add(costAdjustmentAssertLineList1); List<CostAdjustmentAssert> costAdjustmentAssertLineList2 = new ArrayList<CostAdjustmentAssert>(); costAdjustmentAssertLineList2.add(new CostAdjustmentAssert(transactionList.get(0), CURRENCY2_ID, "LC", quantity1.multiply(price2), day2, true, false)); costAdjustmentAssertList.add(costAdjustmentAssertLineList2); assertCostAdjustment(costAdjustmentList, costAdjustmentAssertList); OBDal.getInstance().commitAndClose(); } catch (Exception e) { System.out.println(e.getMessage()); throw new OBException(e); } finally { OBContext.restorePreviousMode(); } }
From source file:org.openbravo.test.costing.TestCosting.java
@Test public void testCostingLC5553() throws Exception { final int day0 = 0; final int day1 = 5; final int day2 = 10; final BigDecimal price1 = new BigDecimal("555.00"); final BigDecimal price2 = new BigDecimal("100.00"); final BigDecimal price3 = new BigDecimal("585.00"); final BigDecimal price4 = new BigDecimal("-25.00"); final BigDecimal quantity1 = BigDecimal.ONE; final BigDecimal rate = new BigDecimal("0.30"); try {// www. j av a2 s . c om OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID); OBContext.setAdminMode(true); // Create a new product for the test Product product = createProduct(price1); // Create goods receipt, run costing background, post it and assert it ShipmentInOut goodsReceipt = createGoodsReceipt(product, price1, quantity1, day0); // Create Landed Cost List<String> landedCostTypeIdList = new ArrayList<String>(); landedCostTypeIdList.add(LANDEDCOSTTYPE3_ID); List<BigDecimal> amountList = new ArrayList<BigDecimal>(); amountList.add(quantity1.multiply(price2)); List<ShipmentInOut> receiptList = new ArrayList<ShipmentInOut>(); receiptList.add(goodsReceipt); LandedCost landedCost = createLandedCost(landedCostTypeIdList, amountList, receiptList, null, day1); // Create purchase invoice with landed cost, post it and assert it Invoice purchaseInvoiceLandedCost1 = createPurchaseInvoiceLandedCost(LANDEDCOSTTYPE3_ID, price2, quantity1, rate, day2); // Match invoice landed cost matchInvoiceLandedCost(purchaseInvoiceLandedCost1.getInvoiceLineList().get(0), landedCost.getLandedCostCostList().get(0), true); // Post landed cost cost and assert it postLandedCostLine(landedCost.getLandedCostCostList().get(0), purchaseInvoiceLandedCost1.getInvoiceLineList().get(0)); // Assert product transactions List<ProductTransactionAssert> productTransactionAssertList1 = new ArrayList<ProductTransactionAssert>(); productTransactionAssertList1.add( new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt.getId()) .getMaterialMgmtShipmentInOutLineList().get(0), price1, price3, price1)); assertProductTransaction(product.getId(), productTransactionAssertList1); // Assert product costing List<MaterialTransaction> transactionList = getProductTransactions(product.getId()); List<ProductCostingAssert> productCostingAssertList1 = new ArrayList<ProductCostingAssert>(); productCostingAssertList1 .add(new ProductCostingAssert(transactionList.get(0), price1, price1, price3, quantity1)); assertProductCosting(product.getId(), productCostingAssertList1); // Assert cost adjustment List<CostAdjustment> costAdjustmentList = getCostAdjustment(product.getId()); List<List<CostAdjustmentAssert>> costAdjustmentAssertList = new ArrayList<List<CostAdjustmentAssert>>(); List<CostAdjustmentAssert> costAdjustmentAssertLineList1 = new ArrayList<CostAdjustmentAssert>(); costAdjustmentAssertLineList1.add(new CostAdjustmentAssert(transactionList.get(0), CURRENCY2_ID, "LC", quantity1.multiply(price2), day1, true, false)); costAdjustmentAssertList.add(costAdjustmentAssertLineList1); List<CostAdjustmentAssert> costAdjustmentAssertLineList2 = new ArrayList<CostAdjustmentAssert>(); costAdjustmentAssertLineList2.add(new CostAdjustmentAssert(transactionList.get(0), CURRENCY2_ID, "LC", quantity1.multiply(price4), day1, true, false)); costAdjustmentAssertList.add(costAdjustmentAssertLineList2); assertCostAdjustment(costAdjustmentList, costAdjustmentAssertList); OBDal.getInstance().commitAndClose(); } catch (Exception e) { System.out.println(e.getMessage()); throw new OBException(e); } finally { OBContext.restorePreviousMode(); } }
From source file:org.openbravo.test.costing.TestCosting.java
@Test public void testCostingLC5554() throws Exception { final int day0 = 0; final int day1 = 5; final int day2 = 10; final BigDecimal price1 = new BigDecimal("555.00"); final BigDecimal price2 = new BigDecimal("100.00"); final BigDecimal price3 = new BigDecimal("585.00"); final BigDecimal price4 = new BigDecimal("-25.00"); final BigDecimal quantity1 = BigDecimal.ONE; final BigDecimal rate = new BigDecimal("0.30"); try {/*from w w w . ja v a 2 s . co m*/ OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID); OBContext.setAdminMode(true); // Create a new product for the test Product product = createProduct(price1); // Create goods receipt, run costing background, post it and assert it ShipmentInOut goodsReceipt = createGoodsReceipt(product, price1, quantity1, day0); // Create purchase invoice with landed cost, post it and assert it Invoice purchaseInvoiceLandedCost1 = createPurchaseInvoiceLandedCost(LANDEDCOSTTYPE3_ID, price2, quantity1, rate, day1); // Create Landed Cost List<Invoice> invoiceList = new ArrayList<Invoice>(); invoiceList.add(purchaseInvoiceLandedCost1); List<ShipmentInOut> receiptList = new ArrayList<ShipmentInOut>(); receiptList.add(goodsReceipt); createLandedCost(invoiceList, receiptList, day2); // Assert product transactions List<ProductTransactionAssert> productTransactionAssertList1 = new ArrayList<ProductTransactionAssert>(); productTransactionAssertList1.add( new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt.getId()) .getMaterialMgmtShipmentInOutLineList().get(0), price1, price3, price1)); assertProductTransaction(product.getId(), productTransactionAssertList1); // Assert product costing List<MaterialTransaction> transactionList = getProductTransactions(product.getId()); List<ProductCostingAssert> productCostingAssertList1 = new ArrayList<ProductCostingAssert>(); productCostingAssertList1 .add(new ProductCostingAssert(transactionList.get(0), price1, price1, price3, quantity1)); assertProductCosting(product.getId(), productCostingAssertList1); // Assert cost adjustment List<CostAdjustment> costAdjustmentList = getCostAdjustment(product.getId()); List<List<CostAdjustmentAssert>> costAdjustmentAssertList = new ArrayList<List<CostAdjustmentAssert>>(); List<CostAdjustmentAssert> costAdjustmentAssertLineList1 = new ArrayList<CostAdjustmentAssert>(); costAdjustmentAssertLineList1.add(new CostAdjustmentAssert(transactionList.get(0), CURRENCY2_ID, "LC", quantity1.multiply(price4), day2, true, false)); costAdjustmentAssertList.add(costAdjustmentAssertLineList1); List<CostAdjustmentAssert> costAdjustmentAssertLineList2 = new ArrayList<CostAdjustmentAssert>(); costAdjustmentAssertLineList2.add(new CostAdjustmentAssert(transactionList.get(0), CURRENCY2_ID, "LC", quantity1.multiply(price2), day2, true, false)); costAdjustmentAssertList.add(costAdjustmentAssertLineList2); assertCostAdjustment(costAdjustmentList, costAdjustmentAssertList); OBDal.getInstance().commitAndClose(); } catch (Exception e) { System.out.println(e.getMessage()); throw new OBException(e); } finally { OBContext.restorePreviousMode(); } }
From source file:org.openbravo.test.costing.TestCosting.java
@Test public void testCostingLC9() throws Exception { final int day0 = 0; final int day1 = 5; final int day2 = 10; final int day3 = 15; final int day4 = 20; final int day5 = 25; final int day6 = 30; final BigDecimal price1 = new BigDecimal("120.00"); final BigDecimal price2 = new BigDecimal("210.00"); final BigDecimal price3 = new BigDecimal("120.21"); final BigDecimal price4 = new BigDecimal("150.00"); final BigDecimal price5 = new BigDecimal("120.30"); final BigDecimal price6 = new BigDecimal("120.3250"); final BigDecimal price7 = new BigDecimal("120.2938"); final BigDecimal quantity1 = new BigDecimal("1000"); final BigDecimal quantity2 = BigDecimal.ONE; final BigDecimal quantity3 = new BigDecimal("200"); final BigDecimal quantity4 = new BigDecimal("2"); final BigDecimal amount1 = new BigDecimal("5.00"); try {/*from w w w. jav a 2 s . com*/ OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID); OBContext.setAdminMode(true); // Create a new product for the test Product product = createProduct(price1); // Create purchase order and book it Order purchaseOrder = createPurchaseOrder(product, price1, quantity1, day0); // Create goods receipt, run costing background, post it and assert it ShipmentInOut goodsReceipt = createGoodsReceipt(purchaseOrder, price1, quantity1, day1); // Create goods shipment, run costing background, post it and assert it ShipmentInOut goodsShipment1 = createGoodsShipment(product, price1, quantity3, day2); // Create Landed Cost List<String> landedCostTypeIdList = new ArrayList<String>(); landedCostTypeIdList.add(LANDEDCOSTTYPE2_ID); List<BigDecimal> amountList = new ArrayList<BigDecimal>(); amountList.add(quantity2.multiply(price2)); List<ShipmentInOut> receiptList = new ArrayList<ShipmentInOut>(); receiptList.add(goodsReceipt); LandedCost landedCost = createLandedCost(landedCostTypeIdList, amountList, receiptList, null, day3); // Create goods shipment, run costing background, post it and assert it ShipmentInOut goodsShipment2 = createGoodsShipment(product, price3, quantity3, day4); // Create purchase invoice with landed cost, post it and assert it Invoice purchaseInvoiceLandedCost = createPurchaseInvoiceLandedCost(LANDEDCOSTTYPE2_ID, price4, quantity4, day5); // Match invoice landed cost matchInvoiceLandedCost(purchaseInvoiceLandedCost.getInvoiceLineList().get(0), landedCost.getLandedCostCostList().get(0), true); // Post landed cost cost and assert it postLandedCostLine(landedCost.getLandedCostCostList().get(0), purchaseInvoiceLandedCost.getInvoiceLineList().get(0)); // Update transaction total cost amount manualCostAdjustment(getProductTransactions(product.getId()).get(1), amount1, true, true, day6); // Assert product transactions List<ProductTransactionAssert> productTransactionAssertList1 = new ArrayList<ProductTransactionAssert>(); productTransactionAssertList1.add( new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt.getId()) .getMaterialMgmtShipmentInOutLineList().get(0), price1, price5, price1)); productTransactionAssertList1.add(new ProductTransactionAssert(OBDal.getInstance() .get(ShipmentInOut.class, goodsShipment1.getId()).getMaterialMgmtShipmentInOutLineList().get(0), price1, price6)); productTransactionAssertList1.add(new ProductTransactionAssert(OBDal.getInstance() .get(ShipmentInOut.class, goodsShipment2.getId()).getMaterialMgmtShipmentInOutLineList().get(0), price3, price7)); assertProductTransaction(product.getId(), productTransactionAssertList1); // Assert product costing List<MaterialTransaction> transactionList = getProductTransactions(product.getId()); List<ProductCostingAssert> productCostingAssertList1 = new ArrayList<ProductCostingAssert>(); productCostingAssertList1 .add(new ProductCostingAssert(transactionList.get(0), price1, price1, price5, quantity1)); productCostingAssertList1.add(new ProductCostingAssert(transactionList.get(1), price7, null, price7, quantity1.add(quantity3.negate()))); assertProductCosting(product.getId(), productCostingAssertList1); // Assert cost adjustment List<CostAdjustment> costAdjustmentList = getCostAdjustment(product.getId()); List<List<CostAdjustmentAssert>> costAdjustmentAssertList = new ArrayList<List<CostAdjustmentAssert>>(); List<CostAdjustmentAssert> costAdjustmentAssertLineList1 = new ArrayList<CostAdjustmentAssert>(); costAdjustmentAssertLineList1.add(new CostAdjustmentAssert(transactionList.get(0), "LC", quantity2.multiply(price2), day3, true, false)); costAdjustmentAssertLineList1.add(new CostAdjustmentAssert(transactionList.get(1), "PDC", quantity3.multiply(price3).add(quantity3.multiply(price1).negate()), day3, false)); costAdjustmentAssertList.add(costAdjustmentAssertLineList1); List<CostAdjustmentAssert> costAdjustmentAssertLineList2 = new ArrayList<CostAdjustmentAssert>(); costAdjustmentAssertLineList2.add(new CostAdjustmentAssert(transactionList.get(0), "LC", quantity4.multiply(price4).add(quantity2.multiply(price2).negate()), day3, true, false)); costAdjustmentAssertLineList2.add(new CostAdjustmentAssert(transactionList.get(1), "PDC", quantity3.multiply(price5).add(quantity3.multiply(price3).negate()), day3, false)); costAdjustmentAssertLineList2.add(new CostAdjustmentAssert(transactionList.get(2), "PDC", quantity3.multiply(price5).add(quantity3.multiply(price3).negate()), day4, false)); costAdjustmentAssertList.add(costAdjustmentAssertLineList2); List<CostAdjustmentAssert> costAdjustmentAssertLineList3 = new ArrayList<CostAdjustmentAssert>(); costAdjustmentAssertLineList3 .add(new CostAdjustmentAssert(transactionList.get(1), "MCC", amount1, day6, true)); costAdjustmentAssertLineList3.add(new CostAdjustmentAssert(transactionList.get(2), "PDC", quantity3.multiply(price7).add(quantity3.multiply(price5).negate()), day6, false)); costAdjustmentAssertList.add(costAdjustmentAssertLineList3); assertCostAdjustment(costAdjustmentList, costAdjustmentAssertList); // Post cost adjustment and assert it postDocument(costAdjustmentList.get(0)); List<DocumentPostAssert> documentPostAssertList1 = new ArrayList<DocumentPostAssert>(); documentPostAssertList1.add(new DocumentPostAssert("99900", quantity3.multiply(price3).add(quantity3.multiply(price1).negate()), amount0, null)); documentPostAssertList1.add(new DocumentPostAssert("35000", amount0, quantity3.multiply(price3).add(quantity3.multiply(price1).negate()), null)); CostAdjustment costAdjustment1 = OBDal.getInstance().get(CostAdjustment.class, costAdjustmentList.get(0).getId()); assertDocumentPost(costAdjustment1, product.getId(), documentPostAssertList1); // Post cost adjustment and assert it postDocument(costAdjustmentList.get(1)); List<DocumentPostAssert> documentPostAssertList2 = new ArrayList<DocumentPostAssert>(); documentPostAssertList2.add(new DocumentPostAssert("99900", quantity3.multiply(price5).add(quantity3.multiply(price3).negate()), amount0, null)); documentPostAssertList2.add(new DocumentPostAssert("35000", amount0, quantity3.multiply(price5).add(quantity3.multiply(price3).negate()), null)); documentPostAssertList2.add(new DocumentPostAssert("99900", quantity3.multiply(price5).add(quantity3.multiply(price3).negate()), amount0, null)); documentPostAssertList2.add(new DocumentPostAssert("35000", amount0, quantity3.multiply(price5).add(quantity3.multiply(price3).negate()), null)); CostAdjustment costAdjustment2 = OBDal.getInstance().get(CostAdjustment.class, costAdjustmentList.get(1).getId()); assertDocumentPost(costAdjustment2, product.getId(), documentPostAssertList2); // Post cost adjustment and assert it postDocument(costAdjustmentList.get(2)); List<DocumentPostAssert> documentPostAssertList3 = new ArrayList<DocumentPostAssert>(); documentPostAssertList3.add(new DocumentPostAssert("99900", amount1, amount0, null)); documentPostAssertList3.add(new DocumentPostAssert("35000", amount0, amount1, null)); documentPostAssertList3.add(new DocumentPostAssert("99900", amount0, quantity3.multiply(price5).add(quantity3.multiply(price7).negate()), null)); documentPostAssertList3.add(new DocumentPostAssert("35000", quantity3.multiply(price5).add(quantity3.multiply(price7).negate()), amount0, null)); CostAdjustment costAdjustment3 = OBDal.getInstance().get(CostAdjustment.class, costAdjustmentList.get(2).getId()); assertDocumentPost(costAdjustment3, product.getId(), documentPostAssertList3); OBDal.getInstance().commitAndClose(); } catch (Exception e) { System.out.println(e.getMessage()); throw new OBException(e); } finally { OBContext.restorePreviousMode(); } }
From source file:org.openbravo.test.costing.TestCosting.java
@Test public void testCostingMC444() throws Exception { final int day0 = 0; final int day1 = 5; final int day2 = 10; final BigDecimal price1 = new BigDecimal("444.00"); final BigDecimal price2 = new BigDecimal("355.20"); final BigDecimal price3 = new BigDecimal("177.60"); final BigDecimal quantity1 = BigDecimal.ONE; final BigDecimal rate = new BigDecimal("0.80"); try {//from w ww . j a va 2 s. c om OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID); OBContext.setAdminMode(true); // Create a new product for the test Product product = createProduct(price1, CURRENCY2_ID); // Create purchase order and book it Order purchaseOrder = createPurchaseOrder(product, price1, quantity1, day0); // Create goods receipt, run costing background, post it and assert it ShipmentInOut goodsReceipt = createGoodsReceipt(purchaseOrder, price1, quantity1, day1); // Create purchase invoice, post it and assert it createPurchaseInvoice(goodsReceipt, price1, quantity1, rate, day2); // Run price correction background runPriceBackground(); // Assert product transactions List<ProductTransactionAssert> productTransactionAssertList1 = new ArrayList<ProductTransactionAssert>(); productTransactionAssertList1.add( new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt.getId()) .getMaterialMgmtShipmentInOutLineList().get(0), price3, price2)); assertProductTransaction(product.getId(), productTransactionAssertList1); // Assert product costing List<MaterialTransaction> transactionList = getProductTransactions(product.getId()); List<ProductCostingAssert> productCostingAssertList1 = new ArrayList<ProductCostingAssert>(); productCostingAssertList1 .add(new ProductCostingAssert(transactionList.get(0), price2, price3, price2, quantity1)); assertProductCosting(product.getId(), productCostingAssertList1); // Assert cost adjustment List<CostAdjustment> costAdjustmentList = getCostAdjustment(product.getId()); List<List<CostAdjustmentAssert>> costAdjustmentAssertList = new ArrayList<List<CostAdjustmentAssert>>(); List<CostAdjustmentAssert> costAdjustmentAssertLineList1 = new ArrayList<CostAdjustmentAssert>(); costAdjustmentAssertLineList1.add(new CostAdjustmentAssert(transactionList.get(0), "PDC", quantity1.multiply(price2).add(quantity1.multiply(price3).negate()), day2, true)); costAdjustmentAssertList.add(costAdjustmentAssertLineList1); assertCostAdjustment(costAdjustmentList, costAdjustmentAssertList); // Post cost adjustment and assert it postDocument(costAdjustmentList.get(0)); List<DocumentPostAssert> documentPostAssertList1 = new ArrayList<DocumentPostAssert>(); documentPostAssertList1.add(new DocumentPostAssert("99904", amount0, quantity1.multiply(price2).add(quantity1.multiply(price3).negate()), null)); documentPostAssertList1.add(new DocumentPostAssert("35000", quantity1.multiply(price2).add(quantity1.multiply(price3).negate()), amount0, null)); CostAdjustment costAdjustment1 = OBDal.getInstance().get(CostAdjustment.class, costAdjustmentList.get(0).getId()); assertDocumentPost(costAdjustment1, product.getId(), documentPostAssertList1); OBDal.getInstance().commitAndClose(); } catch (Exception e) { System.out.println(e.getMessage()); throw new OBException(e); } finally { OBContext.restorePreviousMode(); } }
From source file:pe.gob.mef.gescon.web.ui.PendienteMB.java
public void addSection(ActionEvent event) { try {// w w w .j a v a 2 s.co m if (StringUtils.isBlank(this.getTitulo())) { FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.", "Ttulo de la seccin requerido. Ingrese el ttulo de la seccin a agregar."); FacesContext.getCurrentInstance().addMessage(null, message); return; } if (StringUtils.isBlank(this.getDetalleHtml())) { FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.", "Detalle de la seccin requerido. Ingrese el detalle de la seccin a agregar."); FacesContext.getCurrentInstance().addMessage(null, message); return; } Seccion seccion = new Seccion(); seccion.setVtitulo(this.getTitulo()); seccion.setDetalleHtml(this.getDetalleHtml()); seccion.setDetallePlain(Jsoup.parse(seccion.getDetalleHtml()).text()); if (org.apache.commons.collections.CollectionUtils.isEmpty(this.getListaSeccion())) { this.setListaSeccion(new ArrayList<Seccion>()); seccion.setNorden(BigDecimal.ONE); } else { seccion.setNorden(BigDecimal.valueOf(this.getListaSeccion().size() + 1)); } this.getListaSeccion().add(seccion); RequestContext.getCurrentInstance().execute("PF('secDialog').hide();"); } catch (Exception e) { e.getMessage(); e.printStackTrace(); } }
From source file:org.openbravo.test.costing.TestCosting.java
@Test public void testCostingMC445() throws Exception { final int day0 = 0; final int day1 = 5; final int day2 = 10; final int day3 = 15; final int day4 = 20; final int day5 = 25; final BigDecimal price1 = new BigDecimal("500.00"); final BigDecimal price2 = new BigDecimal("600.00"); final BigDecimal price3 = new BigDecimal("700.00"); final BigDecimal price4 = new BigDecimal("1500.00"); final BigDecimal price5 = new BigDecimal("1750.00"); final BigDecimal price6 = new BigDecimal("1375.00"); final BigDecimal quantity1 = BigDecimal.ONE; try {//from www . ja v a 2s .c o m OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID); OBContext.setAdminMode(true); // Create a new product for the test Product product = createProduct(price1); // Create purchase order and book it Order purchaseOrder1 = createPurchaseOrder(product, price1, quantity1, day0); // Create goods receipt, run costing background, post it and assert it ShipmentInOut goodsReceipt1 = createGoodsReceipt(purchaseOrder1, price1, quantity1, day1); // Create purchase invoice, post it and assert it createPurchaseInvoice(goodsReceipt1, price1, quantity1, day2); // Change organization currency changeOrganizationCurrency(ORGANIZATION_ID, CURRENCY2_ID); // Create purchase order and book it Order purchaseOrder2 = createPurchaseOrder(product, price2, quantity1, day3); // Create goods receipt, run costing background, post it and assert it ShipmentInOut goodsReceipt2 = createGoodsReceipt(purchaseOrder2, price2, quantity1, day4); // Create purchase invoice, post it and assert it createPurchaseInvoice(goodsReceipt2, price3, quantity1, day5); // Run price correction background runPriceBackground(); // Assert product transactions List<ProductTransactionAssert> productTransactionAssertList1 = new ArrayList<ProductTransactionAssert>(); productTransactionAssertList1.add( new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt1.getId()) .getMaterialMgmtShipmentInOutLineList().get(0), CURRENCY1_ID, price1, price1)); productTransactionAssertList1.add( new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt2.getId()) .getMaterialMgmtShipmentInOutLineList().get(0), CURRENCY2_ID, price4, price5)); assertProductTransaction(product.getId(), productTransactionAssertList1); // Assert product costing List<MaterialTransaction> transactionList = getProductTransactions(product.getId()); List<ProductCostingAssert> productCostingAssertList1 = new ArrayList<ProductCostingAssert>(); productCostingAssertList1 .add(new ProductCostingAssert(transactionList.get(0), price1, null, price1, quantity1)); productCostingAssertList1.add(new ProductCostingAssert(transactionList.get(1), price5, price6, price4, quantity1.add(quantity1))); assertProductCosting(product.getId(), productCostingAssertList1); // Assert cost adjustment List<CostAdjustment> costAdjustmentList = getCostAdjustment(product.getId()); List<List<CostAdjustmentAssert>> costAdjustmentAssertList = new ArrayList<List<CostAdjustmentAssert>>(); List<CostAdjustmentAssert> costAdjustmentAssertLineList1 = new ArrayList<CostAdjustmentAssert>(); costAdjustmentAssertLineList1.add(new CostAdjustmentAssert(transactionList.get(1), CURRENCY2_ID, "PDC", quantity1.multiply(price5).add(quantity1.multiply(price4).negate()), day5, true)); costAdjustmentAssertList.add(costAdjustmentAssertLineList1); assertCostAdjustment(costAdjustmentList, costAdjustmentAssertList); // Post cost adjustment and assert it postDocument(costAdjustmentList.get(0)); List<DocumentPostAssert> documentPostAssertList1 = new ArrayList<DocumentPostAssert>(); documentPostAssertList1.add(new DocumentPostAssert("99904", amount0, quantity1.multiply(price3).add(quantity1.multiply(price2).negate()), null)); documentPostAssertList1.add(new DocumentPostAssert("35000", quantity1.multiply(price3).add(quantity1.multiply(price2).negate()), amount0, null)); CostAdjustment costAdjustment1 = OBDal.getInstance().get(CostAdjustment.class, costAdjustmentList.get(0).getId()); assertDocumentPost(costAdjustment1, product.getId(), documentPostAssertList1); OBDal.getInstance().commitAndClose(); } catch (Exception e) { System.out.println(e.getMessage()); throw new OBException(e); } finally { // Change organization currency changeOrganizationCurrency(ORGANIZATION_ID, CURRENCY1_ID); OBContext.restorePreviousMode(); } }
From source file:org.openbravo.test.costing.TestCosting.java
@SuppressWarnings("unchecked") private void assertDocumentPost(BaseOBObject document, String productId, List<DocumentPostAssert> documentPostAssertList) { try {/*from w w w . j a va 2s . co m*/ BaseOBObject doc = OBDal.getInstance().get(document.getClass(), document.getId()); if (!doc.get("posted").equals("Y")) { OBDal.getInstance().refresh(doc); Thread.sleep(5000); for (int i = 0; i < 10 && !doc.get("posted").equals("Y"); i++) { postDocument(doc); doc = OBDal.getInstance().get(doc.getClass(), doc.getId()); OBDal.getInstance().refresh(doc); Thread.sleep(1000); } } assertEquals(doc.get("posted"), "Y"); final OBCriteria<Table> criteria1 = OBDal.getInstance().createCriteria(Table.class); criteria1.add(Restrictions.eq(Table.PROPERTY_NAME, doc.getEntityName())); Table table = criteria1.list().get(0); final OBCriteria<AccountingFact> criteria2 = OBDal.getInstance().createCriteria(AccountingFact.class); criteria2.add(Restrictions.eq(AccountingFact.PROPERTY_RECORDID, doc.getId())); criteria2.add(Restrictions.eq(AccountingFact.PROPERTY_TABLE, table)); criteria2.addOrderBy(AccountingFact.PROPERTY_SEQUENCENUMBER, true); String groupId = criteria2.list().get(0).getGroupID(); assertEquals(criteria2.list().size(), documentPostAssertList.size()); int i = 0; for (AccountingFact accountingFact : criteria2.list()) { String lineListProperty = Character.toLowerCase(doc.getEntityName().charAt(0)) + doc.getEntityName().substring(1) + "LineList"; BaseOBObject line = null; if (doc.getEntityName().equals(ReceiptInvoiceMatch.ENTITY_NAME)) { if (i % 2 == 0) { line = ((ReceiptInvoiceMatch) doc).getGoodsShipmentLine(); } else { line = ((ReceiptInvoiceMatch) doc).getInvoiceLine(); } } else if (doc.getEntityName().equals(ProductionTransaction.ENTITY_NAME)) { StringBuffer where = new StringBuffer(); where.append(" as t1 "); where.append("\n left join t1." + ProductionLine.PROPERTY_PRODUCTIONPLAN + " t2"); where.append("\n where t2." + ProductionPlan.PROPERTY_PRODUCTION + " = :productionTransaction"); where.append("\n order by t1." + ProductionLine.PROPERTY_LINENO); OBQuery<ProductionLine> hql = OBDal.getInstance().createQuery(ProductionLine.class, where.toString()); hql.setNamedParameter("productionTransaction", OBDal.getInstance().get(ProductionTransaction.class, doc.getId())); line = hql.list().get(i / 2); } else if (doc.getEntityName().equals(CostAdjustment.ENTITY_NAME)) { final OBCriteria<CostAdjustmentLine> criteria3 = OBDal.getInstance() .createCriteria(CostAdjustmentLine.class); criteria3.add(Restrictions.eq(CostAdjustmentLine.PROPERTY_COSTADJUSTMENT, doc)); criteria3.add(Restrictions.eq(CostAdjustmentLine.PROPERTY_NEEDSPOSTING, true)); criteria3.addOrderBy(CostAdjustmentLine.PROPERTY_LINENO, true); line = criteria3.list().get(i / 2); } else if (productId != null && (productId.equals(LANDEDCOSTTYPE1_ID) || productId.equals(LANDEDCOSTTYPE2_ID) || productId.equals(LANDEDCOSTTYPE3_ID))) { line = ((List<BaseOBObject>) OBDal.getInstance().get(doc.getClass(), doc.getId()) .get(lineListProperty)).get(0); } else if (doc.getEntityName().equals(LandedCost.ENTITY_NAME)) { StringBuffer where = new StringBuffer(); where.append(" as t1 "); where.append("\n join t1." + LCReceiptLineAmt.PROPERTY_LANDEDCOSTRECEIPT + " t2"); where.append("\n join t1." + LCReceiptLineAmt.PROPERTY_LANDEDCOSTCOST + " t3"); where.append("\n join t1." + LCReceiptLineAmt.PROPERTY_GOODSSHIPMENTLINE + " t4"); where.append("\n left join t4." + ShipmentInOutLine.PROPERTY_SHIPMENTRECEIPT + " t5"); where.append("\n where t2." + LCReceipt.PROPERTY_LANDEDCOST + " = :landedCost"); where.append("\n order by t3." + LandedCostCost.PROPERTY_LINENO); where.append("\n , t5." + ShipmentInOut.PROPERTY_DOCUMENTNO); where.append("\n , t4." + ShipmentInOutLine.PROPERTY_LINENO); OBQuery<LCReceiptLineAmt> hql = OBDal.getInstance().createQuery(LCReceiptLineAmt.class, where.toString()); LandedCost landedCost = OBDal.getInstance().get(LandedCost.class, doc.getId()); hql.setNamedParameter("landedCost", landedCost); line = hql.list().get(i / 2); } else if (doc.getEntityName().equals(LandedCostCost.ENTITY_NAME)) { if (((LandedCostCost) doc).getLandedCostMatchedList().size() == 1) { line = ((LandedCostCost) doc).getLandedCostMatchedList().get(0); } else if (!((LandedCostCost) doc).getAmount().setScale(2, BigDecimal.ROUND_HALF_UP).equals( ((LandedCostCost) doc).getMatchingAmount().setScale(2, BigDecimal.ROUND_HALF_UP)) && ((LandedCostCost) doc).isMatchingAdjusted()) { if (i == 0) { line = ((LandedCostCost) doc).getLandedCostMatchedList().get(0); } else { line = ((LandedCostCost) doc).getLandedCostMatchedList().get(1); } } else { line = ((LandedCostCost) doc).getLandedCostMatchedList().get(i / 2); } } else if (doc.getEntityName().equals(Invoice.ENTITY_NAME) && i > 0) { line = ((List<BaseOBObject>) OBDal.getInstance().get(doc.getClass(), doc.getId()) .get(lineListProperty)).get(i - 1); } else { line = ((List<BaseOBObject>) OBDal.getInstance().get(doc.getClass(), doc.getId()) .get(lineListProperty)).get(i / 2); } DocumentPostAssert documentPostAssert = documentPostAssertList.get(i); assertGeneralData(accountingFact); /* Accounting window fields assert */ assertEquals(accountingFact.getTable(), table); assertEquals(accountingFact.getRecordID(), doc.getId()); assertEquals(accountingFact.getAccountingSchema().getName(), "Main US/A/Euro"); assertEquals(accountingFact.getAccount().getSearchKey(), documentPostAssert.getAccount()); assertEquals(accountingFact.getQuantity(), documentPostAssert.getQuantity()); BigDecimal rate; if ((productId != null && productId.equals(LANDEDCOSTTYPE3_ID)) || (doc.getEntityName().equals(Invoice.ENTITY_NAME) && ((Invoice) doc).getCurrency().getId().equals(CURRENCY2_ID)) || (doc.getEntityName().equals(LandedCost.ENTITY_NAME) && ((LCReceiptLineAmt) line).getLandedCostCost().getLandedCostType() .equals(OBDal.getInstance().get(Product.class, LANDEDCOSTTYPE3_ID) .getLandedCostTypeList().get(0))) || (doc.getEntityName().equals(LandedCostCost.ENTITY_NAME) && ((LCMatched) line).getInvoiceLine().getProduct() != null && ((LCMatched) line).getInvoiceLine().getProduct().getId() .equals(LANDEDCOSTTYPE3_ID)) || (!doc.getEntityName().equals(LandedCostCost.ENTITY_NAME) && !doc.getEntityName().equals(LandedCost.ENTITY_NAME) && documentPostAssert.getProductId() != null && !OBDal.getInstance().get(Product.class, documentPostAssert.getProductId()) .getPricingProductPriceList().isEmpty() && OBDal.getInstance().get(Product.class, documentPostAssert.getProductId()) .getPricingProductPriceList().get(0).getPriceListVersion() .equals(OBDal.getInstance().get(Product.class, LANDEDCOSTTYPE3_ID) .getPricingProductPriceList().get(0).getPriceListVersion()))) { if (doc.getEntityName().equals(Invoice.ENTITY_NAME) && ((Invoice) doc).getCurrencyConversionRateDocList().size() != 0) { rate = ((Invoice) doc).getCurrencyConversionRateDocList().get(0).getRate(); } else { Calendar calendar = Calendar.getInstance(); calendar.set(9999, 0, 1); OBCriteria<ConversionRate> criteria = OBDal.getInstance() .createCriteria(ConversionRate.class); criteria.add(Restrictions.eq(ConversionRate.PROPERTY_CLIENT, OBDal.getInstance().get(Client.class, CLIENT_ID))); criteria.add(Restrictions.eq(ConversionRate.PROPERTY_CURRENCY, OBDal.getInstance().get(Currency.class, CURRENCY2_ID))); criteria.add(Restrictions.eq(ConversionRate.PROPERTY_TOCURRENCY, OBDal.getInstance().get(Currency.class, CURRENCY1_ID))); criteria.add(Restrictions.ge(ConversionRate.PROPERTY_VALIDTODATE, calendar.getTime())); rate = criteria.list().get(0).getMultipleRateBy(); } } else { rate = BigDecimal.ONE; } assertEquals(accountingFact.getDebit().setScale(2, BigDecimal.ROUND_HALF_UP), documentPostAssert.getDebit().multiply(rate).setScale(2, doc.getEntityName().equals(LandedCost.ENTITY_NAME) ? BigDecimal.ROUND_HALF_EVEN : BigDecimal.ROUND_HALF_UP)); assertEquals(accountingFact.getCredit().setScale(2, BigDecimal.ROUND_HALF_UP), documentPostAssert.getCredit().multiply(rate).setScale(2, doc.getEntityName().equals(LandedCost.ENTITY_NAME) ? BigDecimal.ROUND_HALF_EVEN : BigDecimal.ROUND_HALF_UP)); if ((productId != null && productId.equals(LANDEDCOSTTYPE3_ID)) || (doc.getEntityName().equals(Invoice.ENTITY_NAME) && ((Invoice) doc).getCurrency().getId().equals(CURRENCY2_ID)) || (doc.getEntityName().equals(LandedCost.ENTITY_NAME) && ((LCReceiptLineAmt) line).getLandedCostCost().getLandedCostType() .equals(OBDal.getInstance().get(Product.class, LANDEDCOSTTYPE3_ID) .getLandedCostTypeList().get(0))) || (doc.getEntityName().equals(LandedCostCost.ENTITY_NAME) && ((LCMatched) line).getInvoiceLine().getProduct() != null && ((LCMatched) line) .getInvoiceLine().getProduct().getId().equals(LANDEDCOSTTYPE3_ID))) { rate = BigDecimal.ONE; } else if ((doc.getEntityName().equals(ShipmentInOut.ENTITY_NAME) || doc.getEntityName().equals(CostAdjustment.ENTITY_NAME)) && OBDal.getInstance().get(Organization.class, ORGANIZATION_ID).getCurrency() != null && OBDal.getInstance().get(Organization.class, ORGANIZATION_ID).getCurrency().getId() .equals(CURRENCY2_ID)) { Calendar calendar = Calendar.getInstance(); calendar.set(9999, 0, 1); OBCriteria<ConversionRate> criteria = OBDal.getInstance().createCriteria(ConversionRate.class); criteria.add(Restrictions.eq(ConversionRate.PROPERTY_CLIENT, OBDal.getInstance().get(Client.class, CLIENT_ID))); criteria.add(Restrictions.eq(ConversionRate.PROPERTY_CURRENCY, OBDal.getInstance().get(Currency.class, CURRENCY1_ID))); criteria.add(Restrictions.eq(ConversionRate.PROPERTY_TOCURRENCY, OBDal.getInstance().get(Currency.class, CURRENCY2_ID))); criteria.add(Restrictions.ge(ConversionRate.PROPERTY_VALIDTODATE, calendar.getTime())); rate = criteria.list().get(0).getMultipleRateBy(); } assertEquals(accountingFact.getForeignCurrencyDebit().setScale(2, BigDecimal.ROUND_HALF_UP), documentPostAssert.getDebit().multiply(rate).setScale(2, doc.getEntityName().equals(LandedCost.ENTITY_NAME) ? BigDecimal.ROUND_HALF_EVEN : BigDecimal.ROUND_HALF_UP)); assertEquals(accountingFact.getForeignCurrencyCredit().setScale(2, BigDecimal.ROUND_HALF_UP), documentPostAssert.getCredit().multiply(rate).setScale(2, doc.getEntityName().equals(LandedCost.ENTITY_NAME) ? BigDecimal.ROUND_HALF_EVEN : BigDecimal.ROUND_HALF_UP)); Calendar calendar1 = Calendar.getInstance(); calendar1.setTime(accountingFact.getAccountingDate()); calendar1.set(Calendar.DAY_OF_MONTH, calendar1.getActualMinimum(Calendar.DAY_OF_MONTH)); Calendar calendar2 = Calendar.getInstance(); calendar2.setTime(accountingFact.getAccountingDate()); calendar2.set(Calendar.DAY_OF_MONTH, calendar2.getActualMaximum(Calendar.DAY_OF_MONTH)); final OBCriteria<Period> criteria3 = OBDal.getInstance().createCriteria(Period.class); criteria3.add(Restrictions.eq(Period.PROPERTY_STARTINGDATE, calendar1.getTime())); criteria3.add(Restrictions.eq(Period.PROPERTY_ENDINGDATE, calendar2.getTime())); assertEquals(accountingFact.getPeriod(), criteria3.list().get(0)); if (doc.getEntityName().equals(CostAdjustment.ENTITY_NAME)) { assertEquals(formatDate(accountingFact.getTransactionDate()), formatDate(today)); assertEquals(formatDate(accountingFact.getAccountingDate()), formatDate(((CostAdjustmentLine) line).getAccountingDate())); if (((CostAdjustmentLine) line).getInventoryTransaction().getGoodsShipmentLine() != null) { assertEquals(accountingFact.getBusinessPartner(), ((CostAdjustmentLine) line).getInventoryTransaction().getGoodsShipmentLine() .getShipmentReceipt().getBusinessPartner()); } else { assertEquals(accountingFact.getBusinessPartner(), null); } } else if (doc.getEntityName().equals(InventoryCount.ENTITY_NAME)) { assertEquals(formatDate(accountingFact.getTransactionDate()), formatDate(((InventoryCount) doc).getMovementDate())); assertEquals(formatDate(accountingFact.getAccountingDate()), formatDate(((InventoryCount) doc).getMovementDate())); assertEquals(accountingFact.getBusinessPartner(), null); } else if (doc.getEntityName().equals(ReceiptInvoiceMatch.ENTITY_NAME)) { assertEquals(formatDate(accountingFact.getTransactionDate()), formatDate(((ReceiptInvoiceMatch) doc).getTransactionDate())); assertEquals(formatDate(accountingFact.getAccountingDate()), formatDate(((ReceiptInvoiceMatch) doc).getTransactionDate())); assertEquals(accountingFact.getBusinessPartner(), ((ReceiptInvoiceMatch) doc).getInvoiceLine().getBusinessPartner()); } else if (doc.getEntityName().equals(InternalMovement.ENTITY_NAME)) { assertEquals(formatDate(accountingFact.getTransactionDate()), formatDate(((InternalMovement) doc).getMovementDate())); assertEquals(formatDate(accountingFact.getAccountingDate()), formatDate(((InternalMovement) doc).getMovementDate())); assertEquals(accountingFact.getBusinessPartner(), null); } else if (doc.getEntityName().equals(InternalConsumption.ENTITY_NAME)) { assertEquals(formatDate(accountingFact.getTransactionDate()), formatDate(((InternalConsumption) doc).getMovementDate())); assertEquals(formatDate(accountingFact.getAccountingDate()), formatDate(((InternalConsumption) doc).getMovementDate())); assertEquals(accountingFact.getBusinessPartner(), null); } else if (doc.getEntityName().equals(ProductionTransaction.ENTITY_NAME)) { assertEquals(formatDate(accountingFact.getTransactionDate()), formatDate(((ProductionTransaction) doc).getMovementDate())); assertEquals(formatDate(accountingFact.getAccountingDate()), formatDate(((ProductionTransaction) doc).getMovementDate())); assertEquals(accountingFact.getBusinessPartner(), null); } else if (doc.getEntityName().equals(LandedCost.ENTITY_NAME)) { assertEquals(formatDate(accountingFact.getTransactionDate()), formatDate(((LandedCost) doc).getReferenceDate())); assertEquals(formatDate(accountingFact.getAccountingDate()), formatDate(((LandedCost) doc).getReferenceDate())); if (i % 2 == 0) { assertEquals(accountingFact.getBusinessPartner(), OBDal.getInstance() .get(ShipmentInOutLine.class, ((LCReceiptLineAmt) line).getGoodsShipmentLine().getId()) .getBusinessPartner()); } else { assertEquals(accountingFact.getBusinessPartner(), null); } } else if (doc.getEntityName().equals(LandedCostCost.ENTITY_NAME)) { assertEquals(formatDate(accountingFact.getTransactionDate()), formatDate(((LandedCostCost) doc).getAccountingDate())); assertEquals(formatDate(accountingFact.getAccountingDate()), formatDate(((LandedCostCost) doc).getAccountingDate())); if (i == 0 || (documentPostAssert.getProductId() != null && OBDal.getInstance() .get(InvoiceLine.class, ((LandedCostCost) doc).getLandedCostMatchedList().get(0) .getInvoiceLine().getId()) .getProduct() != null && documentPostAssert.getProductId() .equals(OBDal.getInstance() .get(InvoiceLine.class, ((LandedCostCost) doc) .getLandedCostMatchedList().get(0).getInvoiceLine().getId()) .getProduct().getId()))) { assertEquals(accountingFact.getBusinessPartner(), OBDal.getInstance().get(InvoiceLine.class, ((LandedCostCost) doc) .getLandedCostMatchedList().get(0).getInvoiceLine().getId()) .getBusinessPartner()); } else { assertEquals(accountingFact.getBusinessPartner(), null); } } else { assertEquals(formatDate(accountingFact.getTransactionDate()), formatDate((Date) doc.get("accountingDate"))); assertEquals(formatDate(accountingFact.getAccountingDate()), formatDate((Date) doc.get("accountingDate"))); assertEquals(accountingFact.getBusinessPartner(), doc.get("businessPartner")); } if ((productId != null && productId.equals(LANDEDCOSTTYPE3_ID)) || (doc.getEntityName().equals(Invoice.ENTITY_NAME) && ((Invoice) doc).getCurrency().getId().equals(CURRENCY2_ID)) || (doc.getEntityName().equals(LandedCost.ENTITY_NAME) && ((LCReceiptLineAmt) line).getLandedCostCost().getLandedCostType() .equals(OBDal.getInstance().get(Product.class, LANDEDCOSTTYPE3_ID) .getLandedCostTypeList().get(0))) || (doc.getEntityName().equals(LandedCostCost.ENTITY_NAME) && ((LCMatched) line).getInvoiceLine().getProduct() != null && ((LCMatched) line).getInvoiceLine().getProduct().getId() .equals(LANDEDCOSTTYPE3_ID)) || (!doc.getEntityName().equals(Invoice.ENTITY_NAME) && !doc.getEntityName().equals(ReceiptInvoiceMatch.ENTITY_NAME) && OBDal.getInstance().get(Organization.class, ORGANIZATION_ID) .getCurrency() != null && OBDal.getInstance().get(Organization.class, ORGANIZATION_ID).getCurrency() .getId().equals(CURRENCY2_ID))) { assertEquals(accountingFact.getCurrency(), OBDal.getInstance().get(Currency.class, CURRENCY2_ID)); } else { assertEquals(accountingFact.getCurrency(), OBDal.getInstance().get(Currency.class, CURRENCY1_ID)); } if (productId != null && productId.equals(LANDEDCOSTTYPE2_ID)) { if (i == 0) { assertEquals(accountingFact.getProduct(), null); assertEquals(accountingFact.getUOM(), null); assertEquals(accountingFact.getTax(), null); } else if (i == 1) { assertEquals(accountingFact.getProduct(), null); assertEquals(accountingFact.getUOM(), null); assertEquals(accountingFact.getLineID(), null); assertEquals(accountingFact.getRecordID2(), null); OBCriteria<TaxRate> criteria = OBDal.getInstance().createCriteria(TaxRate.class); criteria.add(Restrictions.eq(TaxRate.PROPERTY_TAXCATEGORY, OBDal.getInstance().get(Product.class, productId).getTaxCategory())); criteria.add(Restrictions.eq(TaxRate.PROPERTY_ORGANIZATION, OBDal.getInstance().get(Organization.class, ORGANIZATION_ID))); assertEquals(accountingFact.getTax(), criteria.list().get(0)); } else { assertEquals(accountingFact.getProduct().getId(), productId); assertEquals(accountingFact.getUOM(), line.get("uOM")); assertEquals(accountingFact.getLineID(), line.getId()); assertEquals(accountingFact.getRecordID2(), null); assertEquals(accountingFact.getTax(), null); } } else { if (doc.getEntityName().equals(Invoice.ENTITY_NAME) && i == 0) { assertEquals(accountingFact.getProduct(), null); assertEquals(accountingFact.getUOM(), null); assertEquals(accountingFact.getTax(), null); } else { if (productId == null) { assertEquals(accountingFact.getProduct(), documentPostAssert.getProductId() == null ? null : OBDal.getInstance().get(Product.class, documentPostAssert.getProductId())); } else { assertEquals(accountingFact.getProduct().getId(), productId); } if (line.getEntity().getProperty("uOM", false) == null) { assertEquals(accountingFact.getUOM(), null); } else { assertEquals(accountingFact.getUOM(), line.get("uOM")); } if (!doc.getEntityName().equals(LandedCost.ENTITY_NAME)) { assertEquals(accountingFact.getLineID(), line.getId()); } assertEquals(accountingFact.getRecordID2(), null); assertEquals(accountingFact.getTax(), null); } } assertEquals(accountingFact.getProject(), null); assertEquals(accountingFact.getCostcenter(), null); assertEquals(accountingFact.getAsset(), null); assertEquals(accountingFact.getStDimension(), null); assertEquals(accountingFact.getNdDimension(), null); /* Rest of fields assert */ if (doc.getEntityName().equals(ShipmentInOut.ENTITY_NAME)) { assertEquals(accountingFact.getGLCategory().getName(), "Material Management"); } else if (doc.getEntityName().equals(Invoice.ENTITY_NAME)) { assertEquals(accountingFact.getGLCategory().getName(), "AP Invoice"); } else if (doc.getEntityName().equals(CostAdjustment.ENTITY_NAME)) { assertEquals(accountingFact.getGLCategory().getName(), "None"); } else { assertEquals(accountingFact.getGLCategory().getName(), "Standard"); } assertEquals(accountingFact.getPostingType(), "A"); if (doc.getEntityName().equals(ReceiptInvoiceMatch.ENTITY_NAME)) { assertEquals(accountingFact.getStorageBin(), null); } else if (doc.getEntityName().equals(InternalMovement.ENTITY_NAME)) { if (i % 2 == 0) { assertEquals(accountingFact.getStorageBin(), line.get(InternalMovementLine.PROPERTY_STORAGEBIN)); } else { assertEquals(accountingFact.getStorageBin(), line.get(InternalMovementLine.PROPERTY_NEWSTORAGEBIN)); } } else if (line.getEntity().getProperty("storageBin", false) == null) { assertEquals(accountingFact.getStorageBin(), null); } else { assertEquals(accountingFact.getStorageBin(), line.get("storageBin")); } if (doc.getEntityName().equals(InventoryCount.ENTITY_NAME)) { assertEquals(accountingFact.getDocumentType(), null); assertEquals(accountingFact.getDocumentCategory(), "MMI"); } else if (doc.getEntityName().equals(ReceiptInvoiceMatch.ENTITY_NAME)) { assertEquals(accountingFact.getDocumentType(), null); assertEquals(accountingFact.getDocumentCategory(), "MXI"); } else if (doc.getEntityName().equals(InternalMovement.ENTITY_NAME)) { assertEquals(accountingFact.getDocumentType(), null); assertEquals(accountingFact.getDocumentCategory(), "MMM"); } else if (doc.getEntityName().equals(InternalConsumption.ENTITY_NAME)) { assertEquals(accountingFact.getDocumentType(), null); assertEquals(accountingFact.getDocumentCategory(), "MIC"); } else if (doc.getEntityName().equals(ProductionTransaction.ENTITY_NAME)) { assertEquals(accountingFact.getDocumentType(), null); assertEquals(accountingFact.getDocumentCategory(), "MMP"); } else if (doc.getEntityName().equals(LandedCost.ENTITY_NAME)) { assertEquals(accountingFact.getDocumentType(), null); assertEquals(accountingFact.getDocumentCategory(), "LDC"); } else if (doc.getEntityName().equals(LandedCostCost.ENTITY_NAME)) { assertEquals(accountingFact.getDocumentType(), null); assertEquals(accountingFact.getDocumentCategory(), "LCC"); } else { assertEquals(accountingFact.getDocumentType(), doc.get("documentType")); assertEquals(accountingFact.getDocumentCategory(), ((DocumentType) doc.get("documentType")).getDocumentCategory()); } assertEquals(accountingFact.getSalesRegion(), null); assertEquals(accountingFact.getSalesCampaign(), null); assertEquals(accountingFact.getActivity(), null); assertEquals(accountingFact.getGroupID(), groupId); assertEquals(accountingFact.getType(), "N"); assertEquals(accountingFact.getValue(), documentPostAssert.getAccount()); assertEquals(accountingFact.getWithholding(), null); assertFalse(accountingFact.isModify()); assertEquals(accountingFact.getDateBalanced(), null); final OBCriteria<ElementValue> criteria4 = OBDal.getInstance().createCriteria(ElementValue.class); criteria4.add(Restrictions.eq(ElementValue.PROPERTY_SEARCHKEY, documentPostAssert.getAccount())); assertEquals(accountingFact.getAccountingEntryDescription(), criteria4.list().get(0).getDescription()); i++; } } catch (Exception e) { throw new OBException(e); } }