diff --git a/src-test/src/org/openbravo/test/costing/TestCosting.java b/src-test/src/org/openbravo/test/costing/TestCosting.java
--- a/src-test/src/org/openbravo/test/costing/TestCosting.java
+++ b/src-test/src/org/openbravo/test/costing/TestCosting.java
@@ -19,115 +19,17 @@
package org.openbravo.test.costing;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import java.util.List;
-import java.lang.reflect.Method;
-import java.math.BigDecimal;
-import java.sql.Connection;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.lang.time.DateUtils;
-import org.codehaus.jettison.json.JSONObject;
import org.hibernate.Query;
-import org.hibernate.criterion.Restrictions;
-import org.junit.AfterClass;
-import org.junit.Before;
+import org.hibernate.dialect.function.StandardSQLFunction;
+import org.hibernate.type.DateType;
+import org.hibernate.type.StringType;
import org.junit.Test;
-import org.openbravo.base.exception.OBException;
-import org.openbravo.base.provider.OBProvider;
-import org.openbravo.base.secureApp.VariablesSecureApp;
-import org.openbravo.base.structure.BaseOBObject;
import org.openbravo.base.weld.test.WeldBaseTest;
-import org.openbravo.costing.CancelCostAdjustment;
-import org.openbravo.costing.CostingBackground;
-import org.openbravo.costing.CostingRuleProcess;
-import org.openbravo.costing.InventoryAmountUpdateProcess;
-import org.openbravo.costing.LCCostMatchFromInvoiceHandler;
-import org.openbravo.costing.LCMatchingCancelHandler;
-import org.openbravo.costing.LCMatchingProcessHandler;
-import org.openbravo.costing.LandedCostProcessHandler;
-import org.openbravo.costing.ManualCostAdjustmentProcessHandler;
-import org.openbravo.costing.PriceDifferenceBackground;
-import org.openbravo.costing.ReactivateLandedCost;
-import org.openbravo.dal.core.DalUtil;
-import org.openbravo.dal.core.OBContext;
-import org.openbravo.dal.service.OBCriteria;
import org.openbravo.dal.service.OBDal;
-import org.openbravo.dal.service.OBQuery;
-import org.openbravo.database.ConnectionProvider;
-import org.openbravo.erpCommon.ad_forms.AcctServer;
-import org.openbravo.erpCommon.ad_process.VerifyBOM;
-import org.openbravo.model.ad.access.User;
-import org.openbravo.model.ad.datamodel.Table;
-import org.openbravo.model.ad.process.ProcessInstance;
-import org.openbravo.model.ad.system.Client;
-import org.openbravo.model.ad.ui.Process;
-import org.openbravo.model.ad.utility.Sequence;
-import org.openbravo.model.common.businesspartner.BusinessPartner;
-import org.openbravo.model.common.currency.ConversionRate;
-import org.openbravo.model.common.currency.ConversionRateDoc;
-import org.openbravo.model.common.currency.Currency;
-import org.openbravo.model.common.enterprise.DocumentType;
-import org.openbravo.model.common.enterprise.Locator;
-import org.openbravo.model.common.enterprise.Organization;
-import org.openbravo.model.common.enterprise.Warehouse;
-import org.openbravo.model.common.invoice.Invoice;
-import org.openbravo.model.common.invoice.InvoiceLine;
-import org.openbravo.model.common.order.Order;
-import org.openbravo.model.common.order.OrderLine;
-import org.openbravo.model.common.plm.AttributeSetInstance;
-import org.openbravo.model.common.plm.Product;
-import org.openbravo.model.common.plm.ProductAccounts;
-import org.openbravo.model.common.plm.ProductBOM;
-import org.openbravo.model.common.uom.UOM;
-import org.openbravo.model.financialmgmt.accounting.AccountingFact;
-import org.openbravo.model.financialmgmt.accounting.coa.AcctSchema;
-import org.openbravo.model.financialmgmt.accounting.coa.AcctSchemaTable;
-import org.openbravo.model.financialmgmt.accounting.coa.ElementValue;
-import org.openbravo.model.financialmgmt.calendar.Period;
-import org.openbravo.model.financialmgmt.gl.GLItem;
-import org.openbravo.model.financialmgmt.tax.TaxRate;
-import org.openbravo.model.materialmgmt.cost.CostAdjustment;
-import org.openbravo.model.materialmgmt.cost.CostAdjustmentLine;
-import org.openbravo.model.materialmgmt.cost.Costing;
-import org.openbravo.model.materialmgmt.cost.CostingAlgorithm;
-import org.openbravo.model.materialmgmt.cost.CostingRule;
-import org.openbravo.model.materialmgmt.cost.InventoryAmountUpdate;
-import org.openbravo.model.materialmgmt.cost.InventoryAmountUpdateLine;
-import org.openbravo.model.materialmgmt.cost.LCDistributionAlgorithm;
-import org.openbravo.model.materialmgmt.cost.LCMatched;
-import org.openbravo.model.materialmgmt.cost.LCReceipt;
-import org.openbravo.model.materialmgmt.cost.LCReceiptLineAmt;
-import org.openbravo.model.materialmgmt.cost.LandedCost;
-import org.openbravo.model.materialmgmt.cost.LandedCostCost;
import org.openbravo.model.materialmgmt.cost.TransactionCost;
-import org.openbravo.model.materialmgmt.transaction.InternalConsumption;
-import org.openbravo.model.materialmgmt.transaction.InternalConsumptionLine;
-import org.openbravo.model.materialmgmt.transaction.InternalMovement;
-import org.openbravo.model.materialmgmt.transaction.InternalMovementLine;
-import org.openbravo.model.materialmgmt.transaction.InventoryCount;
import org.openbravo.model.materialmgmt.transaction.MaterialTransaction;
-import org.openbravo.model.materialmgmt.transaction.ProductionLine;
-import org.openbravo.model.materialmgmt.transaction.ProductionPlan;
-import org.openbravo.model.materialmgmt.transaction.ProductionTransaction;
-import org.openbravo.model.materialmgmt.transaction.ShipmentInOut;
-import org.openbravo.model.materialmgmt.transaction.ShipmentInOutLine;
-import org.openbravo.model.pricing.pricelist.PriceList;
-import org.openbravo.model.pricing.pricelist.PriceListVersion;
-import org.openbravo.model.pricing.pricelist.ProductPrice;
-import org.openbravo.model.procurement.ReceiptInvoiceMatch;
-import org.openbravo.scheduling.ProcessBundle;
-import org.openbravo.service.db.CallStoredProcedure;
-import org.openbravo.service.db.DalConnectionProvider;
/**
* Test cases to verify Cost Adjustment Project
@@ -137,13846 +39,57 @@
public class TestCosting extends WeldBaseTest {
- // User System
- private static String USERADMIN_ID = "0";
- // User Openbravo
- private static String USER_ID = "100";
- // Client QA Testing
- private static String CLIENT_ID = "4028E6C72959682B01295A070852010D";
- // Organization Spain
- private static String ORGANIZATION_ID = "357947E87C284935AD1D783CF6F099A1";
- // Role QA Testing Admin
- private static String ROLE_ID = "4028E6C72959682B01295A071429011E";
- // Warehouse with name: Spain warehouse
- private static String WAREHOUSE1_ID = "4028E6C72959682B01295ECFEF4502A0";
- // Warehouse with name: Spain East warehouse
- private static String WAREHOUSE2_ID = "4D7B97565A024DB7B4C61650FA2B9560";
-
- // Document Sequence with name: DocumentNo_M_InOut
- private static String SHIPMENTIN_SEQUENCE_ID = "910E14E8BA4A419B92DF9973ACDB8A8F";
- // Document Sequence with name: DocumentNo_C_Invoice
- private static String INVOICEIN_SEQUENCE_ID = "766DC632FDCE485B88F7535CF2A3422E";
- // Document Sequence with name: DocumentNo_M_Movement
- private static String MOVEMENT_SEQUENCE_ID = "07FD646511E14BADB5C1BB5CF2FCAC57";
- // Storage Bin with name: L01
- private static String LOCATOR1_ID = "193476BDD14E4A11B651B4E3E8D767C8";
- // Storage Bin with name: L02
- private static String LOCATOR2_ID = "1A11102F318D4720957B52C8719A34F2";
- // Storage Bin with name: L03
- private static String LOCATOR3_ID = "FB4D5926A1B443E68CC2DB2BBAE3315D";
- // Storage Bin with name: M01
- private static String LOCATOR4_ID = "96DEDCC179504711A81497DE68900F49";
- // UOM with name: Unit
- private static String UOM_ID = "100";
- // Document sequence with name: DocumentNo_M_Production
- private static String PRODUCTION_DOCUMENTSEQUENCE_ID = "617CDE87DFC24C2FBFF278F7B8D22B82";
- // Document type with name: RFC Order
- private static String RFCORDER_DOCUMENTTYPE_ID = "C789FE062AA8480BAD91543A0C6B41AB";
- // Document type with name: RFC Receipt
- private static String RFCRECEIPT_DOCUMENTTYPE_ID = "4683C39FF3B242CD8A5B5825550C4472";
- // Document type with name: Landed Cost
- private static String LANDEDCOST_DOCUMENTTYPE_ID = "38E131FE95F949CA97C95A9B03B3D6A8";
- // Document type with name: Landed Cost Cost
- private static String LANDEDCOSTCOST_DOCUMENTTYPE_ID = "F66B960D26C64215B1F4A09C3417FB16";
- // Landed Cost Distribution Algorithm with name: Distribution by Amount
- private static String LANDEDCOSTCOST_ALGORITHM_ID = "CF9B55BD159B474A9F79849C48715540";
- // Process with name: Validate Costing Rule
- private static String VALIDATECOSTINGRULE_PROCESS_ID = "A269DCA4DE114E438695B66E166999B4";
- // Process with name: Verify BOM
- private static String VERIFYBOM_PROCESS_ID = "136";
- // Process with name: Create/Process Production
- private static String PROCESSPRODUCTION_PROCESS_ID = "137";
- // Process request with name: Process Movements
- private static String PROCESSMOVEMENT_PROCESS_ID = "122";
- // Process request with name: Process Internal Consumption
- private static String PROCESSCONSUMPTION_PROCESS_ID = "800131";
- // G/L Item with name: Fees
- private static String LANDEDCOSTTYPE1_ID = "1DA4C24347EA4494BBA4466FF23ECAA5";
- // Product with name: Transportation Cost
- private static String LANDEDCOSTTYPE2_ID = "5557E7C0FD064FD7A1CCB8C0E824DEE6";
- // Product with name: USD Cost
- private static String LANDEDCOSTTYPE3_ID = "CB473A64934B4D1583008D52DD0FBC49";
- // Business partner with name: Vendor USA
- private static String BUSINESSPARTNER_ID = "C8AD0EAF3052415BB1E15EFDEFBFD4AF";
- // Costing Algorithm with name: Average Algorithm
- private static String COSTINGALGORITHM_ID = "B069080A0AE149A79CF1FA0E24F16AB6";
- // General Ledger Configuration with name: Main US/A/Euro
- private static String GENERALLEDGER_ID = "9A68A0F8D72D4580B3EC3CAA00A5E1F0";
- // Table with name: MaterialMgmtInternalConsumption
- private static String TABLE1_ID = "800168";
- // Table with name: MaterialMgmtInternalMovement
- private static String TABLE2_ID = "323";
- // Table with name: MaterialMgmtInventoryCount
- private static String TABLE3_ID = "321";
- // Table with name: MaterialMgmtShipmentInOut
- private static String TABLE4_ID = "319";
- // Table with name: MaterialMgmtProductionTransaction
- private static String TABLE5_ID = "325";
- // Table with name: ProcurementReceiptInvoiceMatch
- private static String TABLE6_ID = "472";
-
- // Product with name: costing Product 1
- private static String PRODUCT_ID = "A8B10A097DBD4BF5865BA3C844A2299C";
- // Purchase Order with documentNo: 800010
- private static String ORDERIN_ID = "2C9CEDC0761A41DCB276A5124F8AAA90";
- // Sales Order with documentNo: 50012
- private static String ORDEROUT_ID = "8B53B7E6CF3B4D8D9BCF3A49EED6FCB4";
- // Purchase Invoice with documentNo: 10000017
- private static String INVOICEIN_ID = "9D0F6E57E59247F6AB6D063951811F51";
- // Goods Receipt with documentNo: 10000012
- private static String MOVEMENTIN_ID = "0450583047434254835B2B36B2E5B018";
- // Goods Shipment with documentNo: 500014
- private static String MOVEMENTOUT_ID = "2BCCC64DA82A48C3976B4D007315C2C9";
-
- private static boolean runBefore = true;
-
/********************************************** Automated tests **********************************************/
- @Before
- public void setInitialConfiguration() {
- // FIXME: Change setInitialConfiguration to @BeforeClass and remove runBefore flag
- // once https://issues.openbravo.com/view.php?id=36326 is fixed
- if (runBefore) {
- try {
+ @Test
+ public void test() throws Exception {
+ OBDal.getInstance().registerSQLFunction("get_uuid",
+ new StandardSQLFunction("get_uuid", new StringType()));
+ OBDal.getInstance().registerSQLFunction("now", new StandardSQLFunction("now", new DateType()));
- // Set System context
- OBContext.setOBContext(USERADMIN_ID);
- OBContext.setAdminMode(true);
+ StringBuffer select = new StringBuffer();
+ select.append(" select get_uuid()");
+ select.append(", t." + MaterialTransaction.PROPERTY_ACTIVE);
+ select.append(", t." + MaterialTransaction.PROPERTY_CLIENT);
+ select.append(", t." + MaterialTransaction.PROPERTY_ORGANIZATION);
+ select.append(", now()");
+ select.append(", t." + MaterialTransaction.PROPERTY_CREATEDBY);
+ select.append(", now()");
+ select.append(", t." + MaterialTransaction.PROPERTY_UPDATEDBY);
+ select.append(", t");
+ select.append(", t." + MaterialTransaction.PROPERTY_TRANSACTIONCOST);
+ select.append(", t." + MaterialTransaction.PROPERTY_TRANSACTIONPROCESSDATE);
+ select.append(", t." + MaterialTransaction.PROPERTY_CURRENCY);
+ select.append(", t." + MaterialTransaction.PROPERTY_MOVEMENTDATE);
+ select.append(" from " + MaterialTransaction.ENTITY_NAME + " as t");
+ select.append(" where t." + MaterialTransaction.PROPERTY_TRANSACTIONCOST + " is not null");
+ Query querySelect = OBDal.getInstance().getSession().createQuery(select.toString());
+ querySelect.setMaxResults(1);
+ @SuppressWarnings("rawtypes")
+ List list = querySelect.list();
+ System.out.println("Select: " + list.size());
- // Set EUR currency costing precision
- Currency currrencyEur = OBDal.getInstance().get(Currency.class, EURO_ID);
- currrencyEur.setCostingPrecision(4L);
- OBDal.getInstance().save(currrencyEur);
-
- // Set USD currency costing precision
- Currency currrencyUsd = OBDal.getInstance().get(Currency.class, DOLLAR_ID);
- currrencyUsd.setCostingPrecision(4L);
- OBDal.getInstance().save(currrencyUsd);
-
- OBDal.getInstance().flush();
-
- // Set QA context
- OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
-
- // Set Spain organization currency
- Organization organization = OBDal.getInstance().get(Organization.class, ORGANIZATION_ID);
- organization.setCurrency(OBDal.getInstance().get(Currency.class, EURO_ID));
- OBDal.getInstance().save(organization);
-
- // Set allow negatives in General Ledger
- AcctSchema acctSchema = OBDal.getInstance().get(AcctSchema.class, GENERALLEDGER_ID);
- acctSchema.setAllowNegative(false);
- OBDal.getInstance().save(acctSchema);
-
- // Active tables in General Ledger Configuration
- List
tableList = new ArrayList();
- tableList.add(OBDal.getInstance().get(Table.class, TABLE1_ID));
- tableList.add(OBDal.getInstance().get(Table.class, TABLE2_ID));
- tableList.add(OBDal.getInstance().get(Table.class, TABLE3_ID));
- tableList.add(OBDal.getInstance().get(Table.class, TABLE4_ID));
- tableList.add(OBDal.getInstance().get(Table.class, TABLE5_ID));
- tableList.add(OBDal.getInstance().get(Table.class, TABLE6_ID));
- final OBCriteria criteria1 = OBDal.getInstance().createCriteria(
- AcctSchemaTable.class);
- criteria1.add(Restrictions.eq(AcctSchemaTable.PROPERTY_ACCOUNTINGSCHEMA, acctSchema));
- criteria1.add(Restrictions.in(AcctSchemaTable.PROPERTY_TABLE, tableList));
- criteria1.setFilterOnActive(false);
- criteria1.setFilterOnReadableClients(false);
- criteria1.setFilterOnReadableOrganization(false);
- for (AcctSchemaTable acctSchemaTable : criteria1.list()) {
- acctSchemaTable.setActive(true);
- OBDal.getInstance().save(acctSchemaTable);
- }
-
- OBDal.getInstance().flush();
-
- // Create costing rule
- CostingRule costingRule = OBProvider.getInstance().get(CostingRule.class);
- setGeneralData(costingRule);
- costingRule.setCostingAlgorithm(OBDal.getInstance().get(CostingAlgorithm.class,
- COSTINGALGORITHM_ID));
- costingRule.setWarehouseDimension(true);
- costingRule.setBackdatedTransactionsFixed(true);
- costingRule.setValidated(false);
- costingRule.setStartingDate(null);
- costingRule.setEndingDate(null);
- OBDal.getInstance().save(costingRule);
- OBDal.getInstance().flush();
- OBDal.getInstance().refresh(costingRule);
- runCostingBackground();
- validateCostingRule(costingRule.getId());
-
- OBDal.getInstance().commitAndClose();
- } catch (Exception e) {
- System.out.println(e.getMessage());
- throw new OBException(e);
- }
-
- finally {
- OBContext.restorePreviousMode();
- runBefore = false;
- }
- }
- }
-
- @AfterClass
- public static void setFinalConfiguration() {
- try {
-
- // Set System context
- OBContext.setOBContext(USERADMIN_ID);
- OBContext.setAdminMode(true);
-
- // Set EUR currency costing precision
- Currency currrencyEur = OBDal.getInstance().get(Currency.class, EURO_ID);
- currrencyEur.setCostingPrecision(2L);
- OBDal.getInstance().save(currrencyEur);
-
- // Set USD currency costing precision
- Currency currrencyUsd = OBDal.getInstance().get(Currency.class, DOLLAR_ID);
- currrencyUsd.setCostingPrecision(2L);
- OBDal.getInstance().save(currrencyUsd);
-
- OBDal.getInstance().flush();
-
- // Set QA context
- OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
-
- // Set Spain organization currency
- Organization organization = OBDal.getInstance().get(Organization.class, ORGANIZATION_ID);
- organization.setCurrency(null);
- OBDal.getInstance().save(organization);
-
- // Set allow negatives in General Ledger
- AcctSchema acctSchema = OBDal.getInstance().get(AcctSchema.class, GENERALLEDGER_ID);
- acctSchema.setAllowNegative(true);
- OBDal.getInstance().save(acctSchema);
-
- // Active tables in General Ledger Configuration
- List tableList = new ArrayList();
- tableList.add(OBDal.getInstance().get(Table.class, TABLE1_ID));
- tableList.add(OBDal.getInstance().get(Table.class, TABLE2_ID));
- tableList.add(OBDal.getInstance().get(Table.class, TABLE3_ID));
- tableList.add(OBDal.getInstance().get(Table.class, TABLE4_ID));
- tableList.add(OBDal.getInstance().get(Table.class, TABLE5_ID));
- tableList.add(OBDal.getInstance().get(Table.class, TABLE6_ID));
- final OBCriteria criteria = OBDal.getInstance().createCriteria(
- AcctSchemaTable.class);
- criteria.add(Restrictions.eq(AcctSchemaTable.PROPERTY_ACCOUNTINGSCHEMA, acctSchema));
- criteria.add(Restrictions.in(AcctSchemaTable.PROPERTY_TABLE, tableList));
- for (AcctSchemaTable acctSchemaTable : criteria.list()) {
- acctSchemaTable.setActive(false);
- OBDal.getInstance().save(acctSchemaTable);
- }
-
- OBDal.getInstance().flush();
- OBDal.getInstance().commitAndClose();
- } catch (Exception e) {
- System.out.println(e.getMessage());
- throw new OBException(e);
- }
-
- finally {
- OBContext.restorePreviousMode();
- }
- }
-
- @Test
- public void testCostingAAA() 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("50.00");
- final BigDecimal price2 = new BigDecimal("70.00");
- final BigDecimal price3 = new BigDecimal("80.00");
- final BigDecimal price4 = new BigDecimal("62.00");
- final BigDecimal price5 = new BigDecimal("68.00");
- final BigDecimal quantity1 = new BigDecimal("100");
- final BigDecimal quantity2 = new BigDecimal("150");
-
- try {
-
- OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
- OBContext.setAdminMode(true);
-
- // Create a new product for the test
- Product product = createProduct("testCostingAAA", 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);
-
- // Create purchase order and book it
- Order purchaseOrder2 = createPurchaseOrder(product, price2, quantity2, day3);
-
- // Create goods receipt, run costing background, post it and assert it
- ShipmentInOut goodsReceipt2 = createGoodsReceipt(purchaseOrder2, price2, quantity2, day4);
-
- // Create purchase invoice, post it and assert it
- createPurchaseInvoice(goodsReceipt2, price3, quantity2, day5);
-
- // Run price correction background
- runPriceBackground();
-
- // Assert product transactions
- List productTransactionAssertList = new ArrayList();
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsReceipt1.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price1, price1));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsReceipt2.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price2, price3));
- assertProductTransaction(product.getId(), productTransactionAssertList);
-
- // Assert product costing
- List transactionList = getProductTransactions(product.getId());
- List productCostingAssertList = new ArrayList();
- productCostingAssertList.add(new ProductCostingAssert(transactionList.get(0), price1, null,
- price1, quantity1));
- productCostingAssertList.add(new ProductCostingAssert(transactionList.get(1), price3, price4,
- price5, quantity1.add(quantity2)));
- assertProductCosting(product.getId(), productCostingAssertList);
-
- // Assert cost adjustment
- List costAdjustmentList = getCostAdjustment(product.getId());
- List> costAdjustmentAssertList = new ArrayList>();
- List costAdjustmentAssertLineList = new ArrayList();
- costAdjustmentAssertLineList.add(new CostAdjustmentAssert(transactionList.get(1), "PDC",
- quantity2.multiply(price3).add(quantity2.multiply(price2).negate()), day5, true));
- costAdjustmentAssertList.add(costAdjustmentAssertLineList);
- assertCostAdjustment(costAdjustmentList, costAdjustmentAssertList);
-
- // Post cost adjustment and assert it
- postDocument(costAdjustmentList.get(0));
- List documentPostAssertList = new ArrayList();
- documentPostAssertList.add(new DocumentPostAssert("99904", BigDecimal.ZERO, quantity2
- .multiply(price3).add(quantity2.multiply(price2).negate()), null));
- documentPostAssertList.add(new DocumentPostAssert("35000", quantity2.multiply(price3).add(
- quantity2.multiply(price2).negate()), BigDecimal.ZERO, null));
- CostAdjustment costAdjustment = OBDal.getInstance().get(CostAdjustment.class,
- costAdjustmentList.get(0).getId());
- assertDocumentPost(costAdjustment, product.getId(), documentPostAssertList);
-
- OBDal.getInstance().commitAndClose();
-
- } catch (Exception e) {
- System.out.println(e.getMessage());
- throw new OBException(e);
- }
-
- finally {
- OBContext.restorePreviousMode();
- }
- }
-
- @Test
- public void testCostingCC() throws Exception {
-
- final int day0 = 0;
- final int day1 = 5;
- final int day2 = 10;
- final int day3 = 15;
- final BigDecimal price1 = new BigDecimal("15.00");
- final BigDecimal price2 = new BigDecimal("25.00");
- final BigDecimal quantity1 = new BigDecimal("180");
- final BigDecimal quantity2 = new BigDecimal("80");
-
- try {
-
- OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
- OBContext.setAdminMode(true);
-
- // Create a new product for the test
- Product product = createProduct("testCostingCC", 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 purchase invoice, post it and assert it
- Invoice purchaseInvoice = createPurchaseInvoice(goodsReceipt, price1, quantity1, day2);
-
- // Create goods shipment, run costing background, post it and assert it
- ShipmentInOut goodsShipment = createGoodsShipment(product, price1, quantity2, day3);
-
- // Update purchase order line product price
- updatePurchaseOrder(purchaseOrder, price2);
-
- // Update purchase invoice line product price
- updatePurchaseInvoice(purchaseInvoice, price2);
-
- // Run price correction background
- runPriceBackground();
-
- // Assert product transactions
- List productTransactionAssertList = new ArrayList();
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsReceipt.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price1, price2));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsShipment.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price1, price2));
- assertProductTransaction(product.getId(), productTransactionAssertList);
-
- // Assert product costing
- List transactionList = getProductTransactions(product.getId());
- List productCostingAssertList = new ArrayList();
- productCostingAssertList.add(new ProductCostingAssert(transactionList.get(0), price2, price1,
- price2, quantity1));
- assertProductCosting(product.getId(), productCostingAssertList);
-
- // Assert cost adjustment
- List costAdjustmentList = getCostAdjustment(product.getId());
- List> costAdjustmentAssertList = new ArrayList>();
- List costAdjustmentAssertLineList = new ArrayList();
- costAdjustmentAssertLineList.add(new CostAdjustmentAssert(transactionList.get(0), "PDC",
- quantity1.multiply(price2).add(quantity1.multiply(price1).negate()), day2, true));
- costAdjustmentAssertLineList.add(new CostAdjustmentAssert(transactionList.get(1), "PDC",
- quantity2.multiply(price2).add(quantity2.multiply(price1).negate()), day3, false));
- costAdjustmentAssertList.add(costAdjustmentAssertLineList);
- assertCostAdjustment(costAdjustmentList, costAdjustmentAssertList);
-
- // Post cost adjustment and assert it
- postDocument(costAdjustmentList.get(0));
- List documentPostAssertList = new ArrayList();
- documentPostAssertList.add(new DocumentPostAssert("99904", BigDecimal.ZERO, quantity1
- .multiply(price2).add(quantity1.multiply(price1).negate()), null));
- documentPostAssertList.add(new DocumentPostAssert("35000", quantity1.multiply(price2).add(
- quantity1.multiply(price1).negate()), BigDecimal.ZERO, null));
- documentPostAssertList.add(new DocumentPostAssert("99900", quantity2.multiply(price2).add(
- quantity2.multiply(price1).negate()), BigDecimal.ZERO, null));
- documentPostAssertList.add(new DocumentPostAssert("35000", BigDecimal.ZERO, quantity2
- .multiply(price2).add(quantity2.multiply(price1).negate()), null));
- CostAdjustment costAdjustment = OBDal.getInstance().get(CostAdjustment.class,
- costAdjustmentList.get(0).getId());
- assertDocumentPost(costAdjustment, product.getId(), documentPostAssertList);
-
- OBDal.getInstance().commitAndClose();
-
- } catch (Exception e) {
- System.out.println(e.getMessage());
- throw new OBException(e);
- }
-
- finally {
- OBContext.restorePreviousMode();
- }
- }
-
- @Test
- public void testCostingC1() throws Exception {
-
- final int day0 = 0;
- final int day1 = 5;
- final int day2 = 10;
- final int day3 = 15;
- final BigDecimal price1 = new BigDecimal("15.00");
- final BigDecimal price2 = new BigDecimal("25.00");
- final BigDecimal quantity1 = new BigDecimal("180");
- final BigDecimal quantity2 = new BigDecimal("80");
-
- try {
-
- OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
- OBContext.setAdminMode(true);
-
- // Create a new product for the test
- Product product = createProduct("testCostingC1", 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 goodsShipment = createGoodsShipment(product, price1, quantity2, day2);
-
- // Update purchase order line product price
- updatePurchaseOrder(purchaseOrder, price2);
-
- // Create purchase invoice, post it and assert it
- createPurchaseInvoice(goodsReceipt, price2, quantity1, day3);
-
- // Run price correction background
- runPriceBackground();
-
- // Assert product transactions
- List productTransactionAssertList = new ArrayList();
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsReceipt.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price1, price2));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsShipment.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price1, price2));
- assertProductTransaction(product.getId(), productTransactionAssertList);
-
- // Assert product costing
- List transactionList = getProductTransactions(product.getId());
- List productCostingAssertList = new ArrayList();
- productCostingAssertList.add(new ProductCostingAssert(transactionList.get(0), price2, price1,
- price2, quantity1));
- assertProductCosting(product.getId(), productCostingAssertList);
-
- // Assert cost adjustment
- List costAdjustmentList = getCostAdjustment(product.getId());
- List> costAdjustmentAssertList = new ArrayList>();
- List costAdjustmentAssertLineList = new ArrayList();
- costAdjustmentAssertLineList.add(new CostAdjustmentAssert(transactionList.get(0), "PDC",
- quantity1.multiply(price2).add(quantity1.multiply(price1).negate()), day3, true));
- costAdjustmentAssertLineList.add(new CostAdjustmentAssert(transactionList.get(1), "PDC",
- quantity2.multiply(price2).add(quantity2.multiply(price1).negate()), day3, false));
- costAdjustmentAssertList.add(costAdjustmentAssertLineList);
- assertCostAdjustment(costAdjustmentList, costAdjustmentAssertList);
-
- // Post cost adjustment and assert it
- postDocument(costAdjustmentList.get(0));
- List documentPostAssertList = new ArrayList();
- documentPostAssertList.add(new DocumentPostAssert("99904", BigDecimal.ZERO, quantity1
- .multiply(price2).add(quantity1.multiply(price1).negate()), null));
- documentPostAssertList.add(new DocumentPostAssert("35000", quantity1.multiply(price2).add(
- quantity1.multiply(price1).negate()), BigDecimal.ZERO, null));
- documentPostAssertList.add(new DocumentPostAssert("99900", quantity2.multiply(price2).add(
- quantity2.multiply(price1).negate()), BigDecimal.ZERO, null));
- documentPostAssertList.add(new DocumentPostAssert("35000", BigDecimal.ZERO, quantity2
- .multiply(price2).add(quantity2.multiply(price1).negate()), null));
- CostAdjustment costAdjustment = OBDal.getInstance().get(CostAdjustment.class,
- costAdjustmentList.get(0).getId());
- assertDocumentPost(costAdjustment, product.getId(), documentPostAssertList);
-
- OBDal.getInstance().commitAndClose();
-
- } catch (Exception e) {
- System.out.println(e.getMessage());
- throw new OBException(e);
- }
-
- finally {
- OBContext.restorePreviousMode();
- }
- }
-
- @Test
- public void testCostingDDD() throws Exception {
-
- final int day0 = 0;
- final int day1 = 5;
- final int day2 = 10;
- final int day3 = 15;
- final BigDecimal price1 = new BigDecimal("25.00");
- final BigDecimal price2 = new BigDecimal("20.00");
- final BigDecimal price3 = new BigDecimal("24.3103");
- final BigDecimal quantity1 = new BigDecimal("580");
- final BigDecimal quantity2 = new BigDecimal("80");
- final BigDecimal quantity3 = new BigDecimal("500");
-
- try {
-
- OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
- OBContext.setAdminMode(true);
-
- // Create a new product for the test
- Product product = createProduct("testCostingDDD", price1);
-
- // Create purchase order and book it
- Order purchaseOrder = createPurchaseOrder(product, price1, quantity1, day0);
-
- // Create purchase invoice, post it and assert it
- Invoice purchaseInvoice = createPurchaseInvoice(purchaseOrder, price1, quantity1, day1);
-
- // Create goods receipt, run costing background, post it and assert it
- ShipmentInOut goodsReceipt1 = createGoodsReceipt(purchaseInvoice, price1, quantity2, day2);
-
- // Update purchase invoice line product price
- updatePurchaseInvoice(purchaseInvoice, price2);
-
- // Run price correction background
- runPriceBackground();
-
- // Create goods receipt, run costing background, post it and assert it
- ShipmentInOut goodsReceipt2 = createGoodsReceipt(purchaseInvoice, price1, quantity3, day3);
-
- // Run price correction background
- runPriceBackground();
-
- // Assert product transactions
- List productTransactionAssertList = new ArrayList();
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsReceipt1.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price1, price2));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsReceipt2.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price1, price2));
- assertProductTransaction(product.getId(), productTransactionAssertList);
-
- // Assert product costing
- List transactionList = getProductTransactions(product.getId());
- List productCostingAssertList = new ArrayList();
- productCostingAssertList.add(new ProductCostingAssert(transactionList.get(0), price2, price1,
- price2, quantity2));
- productCostingAssertList.add(new ProductCostingAssert(transactionList.get(1), price2, price3,
- price2, quantity1));
- assertProductCosting(product.getId(), productCostingAssertList);
-
- // Assert cost adjustment
- List costAdjustmentList = getCostAdjustment(product.getId());
- List> costAdjustmentAssertList = new ArrayList>();
- List costAdjustmentAssertLineList1 = new ArrayList();
- costAdjustmentAssertLineList1.add(new CostAdjustmentAssert(transactionList.get(0), "PDC",
- quantity2.multiply(price2).add(quantity2.multiply(price1).negate()), day1, true));
- costAdjustmentAssertList.add(costAdjustmentAssertLineList1);
- List costAdjustmentAssertLineList2 = new ArrayList();
- costAdjustmentAssertLineList2.add(new CostAdjustmentAssert(transactionList.get(1), "PDC",
- quantity3.multiply(price2).add(quantity3.multiply(price1).negate()), day1, true));
- costAdjustmentAssertList.add(costAdjustmentAssertLineList2);
- assertCostAdjustment(costAdjustmentList, costAdjustmentAssertList);
-
- // Post cost adjustment 1 and assert it
- postDocument(costAdjustmentList.get(0));
- List documentPostAssertList1 = new ArrayList();
- documentPostAssertList1.add(new DocumentPostAssert("99904", quantity2.multiply(price1).add(
- quantity2.multiply(price2).negate()), BigDecimal.ZERO, null));
- documentPostAssertList1.add(new DocumentPostAssert("35000", BigDecimal.ZERO, quantity2
- .multiply(price1).add(quantity2.multiply(price2).negate()), null));
- CostAdjustment costAdjustment1 = OBDal.getInstance().get(CostAdjustment.class,
- costAdjustmentList.get(0).getId());
- assertDocumentPost(costAdjustment1, product.getId(), documentPostAssertList1);
-
- // Post cost adjustment 2 and assert it
- postDocument(costAdjustmentList.get(1));
- List documentPostAssertList2 = new ArrayList();
- documentPostAssertList2.add(new DocumentPostAssert("99904", quantity3.multiply(price1).add(
- quantity3.multiply(price2).negate()), BigDecimal.ZERO, null));
- documentPostAssertList2.add(new DocumentPostAssert("35000", BigDecimal.ZERO, quantity3
- .multiply(price1).add(quantity3.multiply(price2).negate()), null));
- CostAdjustment costAdjustment2 = OBDal.getInstance().get(CostAdjustment.class,
- costAdjustmentList.get(1).getId());
- assertDocumentPost(costAdjustment2, product.getId(), documentPostAssertList2);
-
- OBDal.getInstance().commitAndClose();
-
- } catch (Exception e) {
- System.out.println(e.getMessage());
- throw new OBException(e);
- }
-
- finally {
- OBContext.restorePreviousMode();
- }
- }
-
- @Test
- public void testCostingV911() throws Exception {
-
- final int day0 = 0;
- final int day1 = 5;
- final int day2 = 10;
- final int day3 = 15;
- final BigDecimal price1 = new BigDecimal("15.00");
- final BigDecimal price2 = new BigDecimal("25.00");
- final BigDecimal price3 = new BigDecimal("35.00");
- final BigDecimal quantity1 = new BigDecimal("500");
- final BigDecimal quantity2 = new BigDecimal("400");
- final BigDecimal quantity3 = new BigDecimal("200");
- final BigDecimal quantity4 = new BigDecimal("300");
- final String costType = "AVA";
-
- try {
-
- OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
- OBContext.setAdminMode(true);
-
- // Create a new product for the test
- Product product = createProduct("testCostingV911", price1, price2, costType);
-
- // Create purchase invoice, post it and assert it
- Invoice purchaseInvoice = createPurchaseInvoice(product, price1, quantity1, day0);
-
- // Create goods shipment, run costing background, post it and assert it
- ShipmentInOut goodsShipment = createGoodsShipment(product, price2, quantity2, day1);
-
- // Add sleep to avoid assert errors
- Thread.sleep(1000);
-
- // Create goods receipt, run costing background, post it and assert it
- ShipmentInOut goodsReceipt1 = createGoodsReceipt(purchaseInvoice, price2, quantity3, day2);
-
- // Add sleep to avoid assert errors
- Thread.sleep(1000);
-
- // Create goods receipt, run costing background, post it and assert it
- ShipmentInOut goodsReceipt2 = createGoodsReceipt(purchaseInvoice, price1, quantity4, day3);
-
- // Assert product transactions
- List productTransactionAssertList = new ArrayList();
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsShipment.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price2, price2));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsReceipt1.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price2, price3, price1));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsReceipt2.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price1, price1));
- assertProductTransaction(product.getId(), productTransactionAssertList);
-
- // Assert product costing
- List transactionList = getProductTransactions(product.getId());
- List productCostingAssertList = new ArrayList();
- productCostingAssertList.add(new ProductCostingAssert(null, null, null, price2, null,
- costType));
- productCostingAssertList.add(new ProductCostingAssert(transactionList.get(1), price1, price2,
- price1, quantity2.negate().add(quantity3)));
- productCostingAssertList.add(new ProductCostingAssert(transactionList.get(2), price1, null,
- price1, quantity2.negate().add(quantity3).add(quantity4)));
- assertProductCosting(product.getId(), productCostingAssertList);
-
- // Assert cost adjustment
- List costAdjustmentList = getCostAdjustment(product.getId());
- List> costAdjustmentAssertList = new ArrayList>();
- List costAdjustmentAssertLineList1 = new ArrayList();
- costAdjustmentAssertLineList1.add(new CostAdjustmentAssert(transactionList.get(1), "PDC",
- quantity3.multiply(price1).add(quantity3.multiply(price2).negate()), day0, true));
- costAdjustmentAssertLineList1.add(new CostAdjustmentAssert(transactionList.get(1), "NSC",
- quantity3.multiply(price3).add(quantity3.multiply(price1).negate()), day2, false, false));
- costAdjustmentAssertList.add(costAdjustmentAssertLineList1);
- List costAdjustmentAssertLineList2 = new ArrayList();
- costAdjustmentAssertLineList2.add(new CostAdjustmentAssert(transactionList.get(2), "NSC",
- BigDecimal.ZERO, day3, true, false));
- costAdjustmentAssertList.add(costAdjustmentAssertLineList2);
- assertCostAdjustment(costAdjustmentList, costAdjustmentAssertList);
-
- // Post cost adjustment 1 and assert it
- postDocument(costAdjustmentList.get(0));
- List documentPostAssertList1 = new ArrayList();
- documentPostAssertList1.add(new DocumentPostAssert("99904", quantity3.multiply(price2).add(
- quantity3.multiply(price1).negate()), BigDecimal.ZERO, null));
- documentPostAssertList1.add(new DocumentPostAssert("35000", BigDecimal.ZERO, quantity3
- .multiply(price2).add(quantity3.multiply(price1).negate()), null));
- documentPostAssertList1.add(new DocumentPostAssert("61000", BigDecimal.ZERO, quantity3
- .multiply(price3).add(quantity3.multiply(price1).negate()), null));
- documentPostAssertList1.add(new DocumentPostAssert("35000", quantity3.multiply(price3).add(
- quantity3.multiply(price1).negate()), BigDecimal.ZERO, 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();
- }
- }
-
- @Test
- public void testCostingV10() 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 int day7 = 35;
- final int day8 = 40;
- final int day9 = 45;
- final BigDecimal price1 = new BigDecimal("8.00");
- final BigDecimal price2 = new BigDecimal("9.00");
- final BigDecimal price3 = new BigDecimal("8.5493");
- final BigDecimal price4 = new BigDecimal("10.00");
- final BigDecimal price5 = new BigDecimal("8.6610");
- final BigDecimal price6 = new BigDecimal("9.3390");
- final BigDecimal price7 = new BigDecimal("9.4507");
- final BigDecimal price8 = new BigDecimal("9.0186");
- final BigDecimal quantity1 = new BigDecimal("1000");
- final BigDecimal quantity2 = new BigDecimal("150");
- final BigDecimal quantity3 = new BigDecimal("250");
- final BigDecimal quantity4 = new BigDecimal("10");
- final BigDecimal quantity5 = new BigDecimal("200");
- final BigDecimal quantity6 = new BigDecimal("120");
- final BigDecimal quantity7 = new BigDecimal("50");
- final BigDecimal quantity8 = new BigDecimal("280");
-
- try {
-
- OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
- OBContext.setAdminMode(true);
-
- // Create a new product for the test
- Product product = createProduct("testCostingV10", 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 goodsReceipt1 = createGoodsReceipt(purchaseOrder, price1, quantity2, day1);
-
- // Add sleep to avoid assert errors
- Thread.sleep(1000);
-
- // Create goods receipt, run costing background, post it and assert it
- ShipmentInOut goodsReceipt2 = createGoodsReceipt(purchaseOrder, price1, quantity3, day2);
-
- // Add sleep to avoid assert errors
- Thread.sleep(1000);
-
- // Create goods shipment, run costing background, post it and assert it
- ShipmentInOut goodsShipment1 = createGoodsShipment(product, price1, quantity4, day3);
-
- // Create purchase invoice, post it and assert it
- List goodsReceiptList1 = new ArrayList();
- goodsReceiptList1.add(goodsReceipt1);
- goodsReceiptList1.add(goodsReceipt2);
- List priceList1 = new ArrayList();
- priceList1.add(price2);
- priceList1.add(price2);
- createPurchaseInvoice(goodsReceiptList1, priceList1, quantity2.add(quantity3), day4);
-
- // Run price correction background
- runPriceBackground();
-
- // Add sleep to avoid assert errors
- Thread.sleep(1000);
-
- // Create goods receipt, run costing background, post it and assert it
- ShipmentInOut goodsReceipt3 = createGoodsReceipt(purchaseOrder, price1, quantity5, day5);
-
- // Add sleep to avoid assert errors
- Thread.sleep(1000);
-
- // Create goods receipt, run costing background, post it and assert it
- ShipmentInOut goodsReceipt4 = createGoodsReceipt(purchaseOrder, price1, quantity6, day6);
-
- // Add sleep to avoid assert errors
- Thread.sleep(1000);
-
- // Create goods shipment, run costing background, post it and assert it
- ShipmentInOut goodsShipment2 = createGoodsShipment(product, price3, quantity7, day7);
-
- // Create purchase invoice, post it and assert it
- List goodsReceiptList2 = new ArrayList();
- goodsReceiptList2.add(goodsReceipt3);
- goodsReceiptList2.add(goodsReceipt4);
- List priceList2 = new ArrayList();
- priceList2.add(price4);
- priceList2.add(price4);
- createPurchaseInvoice(goodsReceiptList2, priceList2, quantity5.add(quantity6), day8);
-
- // Run price correction background
- runPriceBackground();
-
- // Create goods receipt, run costing background, post it and assert it
- ShipmentInOut goodsReceipt5 = createGoodsReceipt(purchaseOrder, price1, quantity8, day9);
-
- // Run price correction background
- runPriceBackground();
-
- // Assert product transactions
- List productTransactionAssertList = new ArrayList();
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsReceipt1.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price1, price2));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsReceipt2.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price1, price2));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsShipment1.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price1, price2));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsReceipt3.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price1, price4));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsReceipt4.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price1, price4));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsShipment2.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price3, price7));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsReceipt5.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price1, price1));
- assertProductTransaction(product.getId(), productTransactionAssertList);
-
- // Assert product costing
- List transactionList = getProductTransactions(product.getId());
- List productCostingAssertList = new ArrayList();
- productCostingAssertList.add(new ProductCostingAssert(transactionList.get(0), price2, price1,
- price2, quantity2));
- productCostingAssertList.add(new ProductCostingAssert(transactionList.get(1), price2, price1,
- price2, quantity2.add(quantity3)));
- productCostingAssertList.add(new ProductCostingAssert(transactionList.get(3), price4, price5,
- price6, quantity2.add(quantity3).add((quantity4).negate()).add(quantity5)));
- productCostingAssertList
- .add(new ProductCostingAssert(transactionList.get(4), price4, price3, price7, quantity2
- .add(quantity3).add((quantity4).negate()).add(quantity5).add(quantity6)));
- productCostingAssertList.add(new ProductCostingAssert(transactionList.get(6), price1, null,
- price8, quantity2.add(quantity3).add((quantity4).negate()).add(quantity5).add(quantity6)
- .add((quantity7).negate()).add(quantity8)));
- assertProductCosting(product.getId(), productCostingAssertList);
-
- // Assert cost adjustment
- List costAdjustmentList = getCostAdjustment(product.getId());
- List> costAdjustmentAssertList = new ArrayList>();
- List costAdjustmentAssertLineList1 = new ArrayList();
- costAdjustmentAssertLineList1.add(new CostAdjustmentAssert(transactionList.get(0), "PDC",
- quantity2.multiply(price2).add(quantity2.multiply(price1).negate()), day4, true));
- costAdjustmentAssertLineList1.add(new CostAdjustmentAssert(transactionList.get(1), "PDC",
- quantity3.multiply(price2).add(quantity3.multiply(price1).negate()), day4, true));
- costAdjustmentAssertLineList1.add(new CostAdjustmentAssert(transactionList.get(2), "PDC",
- quantity4.multiply(price2).add(quantity4.multiply(price1).negate()), day4, false));
- costAdjustmentAssertList.add(costAdjustmentAssertLineList1);
- List costAdjustmentAssertLineList2 = new ArrayList();
- costAdjustmentAssertLineList2.add(new CostAdjustmentAssert(transactionList.get(3), "PDC",
- quantity5.multiply(price4).add(quantity5.multiply(price1).negate()), day8, true));
- costAdjustmentAssertLineList2.add(new CostAdjustmentAssert(transactionList.get(4), "PDC",
- quantity6.multiply(price4).add(quantity6.multiply(price1).negate()), day8, true));
- costAdjustmentAssertLineList2.add(new CostAdjustmentAssert(transactionList.get(5), "PDC",
- quantity7.multiply(price7).add(quantity7.multiply(price3).negate()), day8, false));
- costAdjustmentAssertList.add(costAdjustmentAssertLineList2);
- assertCostAdjustment(costAdjustmentList, costAdjustmentAssertList);
-
- // Post cost adjustment 1 and assert it
- postDocument(costAdjustmentList.get(0));
- List documentPostAssertList1 = new ArrayList();
- documentPostAssertList1.add(new DocumentPostAssert("99904", BigDecimal.ZERO, quantity2
- .multiply(price2).add(quantity2.multiply(price1).negate()), null));
- documentPostAssertList1.add(new DocumentPostAssert("35000", quantity2.multiply(price2).add(
- quantity2.multiply(price1).negate()), BigDecimal.ZERO, null));
- documentPostAssertList1.add(new DocumentPostAssert("99904", BigDecimal.ZERO, quantity3
- .multiply(price2).add(quantity3.multiply(price1).negate()), null));
- documentPostAssertList1.add(new DocumentPostAssert("35000", quantity3.multiply(price2).add(
- quantity3.multiply(price1).negate()), BigDecimal.ZERO, null));
- documentPostAssertList1.add(new DocumentPostAssert("99900", quantity4.multiply(price2).add(
- quantity4.multiply(price1).negate()), BigDecimal.ZERO, null));
- documentPostAssertList1.add(new DocumentPostAssert("35000", BigDecimal.ZERO, quantity4
- .multiply(price2).add(quantity4.multiply(price1).negate()), null));
- CostAdjustment costAdjustment1 = OBDal.getInstance().get(CostAdjustment.class,
- costAdjustmentList.get(0).getId());
- assertDocumentPost(costAdjustment1, product.getId(), documentPostAssertList1);
-
- // Post cost adjustment 2 and assert it
- postDocument(costAdjustmentList.get(1));
- List documentPostAssertList2 = new ArrayList();
- documentPostAssertList2.add(new DocumentPostAssert("99904", BigDecimal.ZERO, quantity5
- .multiply(price4).add(quantity5.multiply(price1).negate()), null));
- documentPostAssertList2.add(new DocumentPostAssert("35000", quantity5.multiply(price4).add(
- quantity5.multiply(price1).negate()), BigDecimal.ZERO, null));
- documentPostAssertList2.add(new DocumentPostAssert("99904", BigDecimal.ZERO, quantity6
- .multiply(price4).add(quantity6.multiply(price1).negate()), null));
- documentPostAssertList2.add(new DocumentPostAssert("35000", quantity6.multiply(price4).add(
- quantity6.multiply(price1).negate()), BigDecimal.ZERO, null));
- documentPostAssertList2.add(new DocumentPostAssert("99900", quantity7.multiply(price7).add(
- quantity7.multiply(price3).negate()), BigDecimal.ZERO, null));
- documentPostAssertList2.add(new DocumentPostAssert("35000", BigDecimal.ZERO, quantity7
- .multiply(price7).add(quantity7.multiply(price3).negate()), null));
- CostAdjustment costAdjustment2 = OBDal.getInstance().get(CostAdjustment.class,
- costAdjustmentList.get(1).getId());
- assertDocumentPost(costAdjustment2, product.getId(), documentPostAssertList2);
-
- OBDal.getInstance().commitAndClose();
-
- } catch (Exception e) {
- System.out.println(e.getMessage());
- throw new OBException(e);
- }
-
- finally {
- OBContext.restorePreviousMode();
- }
- }
-
- @Test
- public void testCostingBD3() 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 int day7 = 35;
- final BigDecimal price1 = new BigDecimal("120.00");
- final BigDecimal price2 = new BigDecimal("135.00");
- final BigDecimal price3 = new BigDecimal("127.50");
- final BigDecimal price4 = new BigDecimal("128.0357");
- final BigDecimal price5 = new BigDecimal("132.50");
- final BigDecimal price6 = new BigDecimal("135.00");
- final BigDecimal price7 = new BigDecimal("133.00");
- final BigDecimal quantity1 = new BigDecimal("75");
- final BigDecimal quantity2 = new BigDecimal("10");
- final BigDecimal quantity3 = new BigDecimal("50");
- final BigDecimal quantity4 = new BigDecimal("25");
- final BigDecimal quantity5 = new BigDecimal("15");
-
- try {
-
- OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
- OBContext.setAdminMode(true);
-
- // Create a new product for the test
- Product product = createProduct("testCostingBD3", price1);
-
- // Create purchase order and book it
- Order purchaseOrder1 = createPurchaseOrder(product, price1, quantity1, day0);
-
- // Create purchase order and book it
- Order purchaseOrder2 = createPurchaseOrder(product, price2, quantity1, day1);
-
- // Create goods receipt, run costing background, post it and assert it
- ShipmentInOut goodsReceipt1 = createGoodsReceipt(purchaseOrder2, price2, quantity1, day6);
-
- // Create goods receipt, run costing background, post it and assert it
- ShipmentInOut goodsReceipt2 = createGoodsReceipt(purchaseOrder1, price1, quantity1, day2);
-
- // Create goods shipment, run costing background, post it and assert it
- ShipmentInOut goodsShipment1 = createGoodsShipment(product, price3, quantity2, day3);
-
- // Create goods shipment, run costing background, post it and assert it
- ShipmentInOut goodsShipment2 = createGoodsShipment(product, price4, quantity3, day4);
-
- // Create goods shipment, run costing background, post it and assert it
- ShipmentInOut goodsShipment3 = createGoodsShipment(product, price5, quantity4, day5);
-
- // Create goods shipment, run costing background, post it and assert it
- ShipmentInOut goodsShipment4 = createGoodsShipment(product, price6, quantity5, day7);
-
- // Run price correction background
- runPriceBackground();
-
- // Assert product transactions
- List productTransactionAssertList = new ArrayList();
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsReceipt2.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price1, price1));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsShipment1.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price3, price1));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsShipment2.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price4, price1));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsShipment3.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price5, price1));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsReceipt1.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price2, price7, price2));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsShipment4.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price6, price6));
- assertProductTransaction(product.getId(), productTransactionAssertList);
-
- // Assert product costing
- List transactionList = getProductTransactions(product.getId());
- List productCostingAssertList = new ArrayList();
- productCostingAssertList.add(new ProductCostingAssert(transactionList.get(0), price1, price3,
- price1, quantity1));
- productCostingAssertList.add(new ProductCostingAssert(transactionList.get(4), price2, price2,
- price2, quantity1.subtract(quantity2)));
- assertProductCosting(product.getId(), productCostingAssertList);
-
- // Assert cost adjustment
- List costAdjustmentList = getCostAdjustment(product.getId());
- List> costAdjustmentAssertList = new ArrayList>();
- List costAdjustmentAssertLineList1 = new ArrayList();
- costAdjustmentAssertLineList1.add(new CostAdjustmentAssert(transactionList.get(0), "BDT",
- BigDecimal.ZERO, day2, true));
- costAdjustmentAssertList.add(costAdjustmentAssertLineList1);
- List costAdjustmentAssertLineList2 = new ArrayList();
- costAdjustmentAssertLineList2.add(new CostAdjustmentAssert(transactionList.get(1), "BDT",
- quantity2.multiply(price1).add(quantity2.multiply(price3).negate()), day3, true));
- costAdjustmentAssertList.add(costAdjustmentAssertLineList2);
- List costAdjustmentAssertLineList3 = new ArrayList();
- costAdjustmentAssertLineList3.add(new CostAdjustmentAssert(transactionList.get(2), "BDT",
- quantity3.multiply(price1).add(quantity3.multiply(price4).negate()), day4, true));
- costAdjustmentAssertList.add(costAdjustmentAssertLineList3);
- List costAdjustmentAssertLineList4 = new ArrayList();
- costAdjustmentAssertLineList4.add(new CostAdjustmentAssert(transactionList.get(3), "BDT",
- quantity4.multiply(price1).add(quantity4.multiply(price5).negate()), day5, true));
- costAdjustmentAssertLineList4.add(new CostAdjustmentAssert(transactionList.get(4), "NSC",
- quantity1.multiply(price7).add(quantity1.multiply(price2).negate()), day6, false, false));
- costAdjustmentAssertList.add(costAdjustmentAssertLineList4);
- assertCostAdjustment(costAdjustmentList, costAdjustmentAssertList);
-
- // Post cost adjustment 1 and assert it
- postDocument(costAdjustmentList.get(1));
- List documentPostAssertList1 = new ArrayList();
- documentPostAssertList1.add(new DocumentPostAssert("99900", BigDecimal.ZERO, quantity2
- .multiply(price3).add(quantity2.multiply(price1).negate()), null));
- documentPostAssertList1.add(new DocumentPostAssert("35000", quantity2.multiply(price3).add(
- quantity2.multiply(price1).negate()), BigDecimal.ZERO, null));
- CostAdjustment costAdjustment1 = OBDal.getInstance().get(CostAdjustment.class,
- costAdjustmentList.get(1).getId());
- assertDocumentPost(costAdjustment1, product.getId(), documentPostAssertList1);
-
- // Post cost adjustment 2 and assert it
- postDocument(costAdjustmentList.get(2));
- List documentPostAssertList2 = new ArrayList();
- documentPostAssertList2.add(new DocumentPostAssert("99900", BigDecimal.ZERO, quantity3
- .multiply(price4).add(quantity3.multiply(price1).negate()), null));
- documentPostAssertList2.add(new DocumentPostAssert("35000", quantity3.multiply(price4).add(
- quantity3.multiply(price1).negate()), BigDecimal.ZERO, null));
- CostAdjustment costAdjustment2 = OBDal.getInstance().get(CostAdjustment.class,
- costAdjustmentList.get(2).getId());
- assertDocumentPost(costAdjustment2, product.getId(), documentPostAssertList2);
-
- // Post cost adjustment 3 and assert it
- postDocument(costAdjustmentList.get(3));
- List documentPostAssertList3 = new ArrayList();
- documentPostAssertList3.add(new DocumentPostAssert("99900", BigDecimal.ZERO, quantity4
- .multiply(price5).add(quantity4.multiply(price1).negate()), null));
- documentPostAssertList3.add(new DocumentPostAssert("35000", quantity4.multiply(price5).add(
- quantity4.multiply(price1).negate()), BigDecimal.ZERO, null));
- documentPostAssertList3.add(new DocumentPostAssert("61000", quantity1.multiply(price2).add(
- quantity1.multiply(price7).negate()), BigDecimal.ZERO, null));
- documentPostAssertList3.add(new DocumentPostAssert("35000", BigDecimal.ZERO, quantity1
- .multiply(price2).add(quantity1.multiply(price7).negate()), null));
- CostAdjustment costAdjustment3 = OBDal.getInstance().get(CostAdjustment.class,
- costAdjustmentList.get(3).getId());
- assertDocumentPost(costAdjustment3, product.getId(), documentPostAssertList3);
-
- OBDal.getInstance().commitAndClose();
-
- } catch (Exception e) {
- System.out.println(e.getMessage());
- throw new OBException(e);
- }
-
- finally {
- OBContext.restorePreviousMode();
- }
- }
-
- @Test
- public void testCostingE1() throws Exception {
-
- final int day0 = 0;
- final int day1 = 5;
- final int day2 = 10;
- final int day3 = 15;
- final int day4 = 20;
- final BigDecimal price1 = new BigDecimal("111.00");
- final BigDecimal price2 = new BigDecimal("110.00");
- final BigDecimal quantity1 = new BigDecimal("250");
- final BigDecimal quantity2 = new BigDecimal("150");
-
- try {
-
- OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
- OBContext.setAdminMode(true);
-
- // Create a new product for the test
- Product product = createProduct("testCostingE1", 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);
-
- // Add sleep to avoid assert errors
- Thread.sleep(1000);
-
- // Create inventory amount update and run costing background
- InventoryAmountUpdate inventoryAmountUpdate = createInventoryAmountUpdate(product, price1,
- price2, quantity1, day2);
-
- // Create goods shipment, run costing background, post it and assert it
- ShipmentInOut goodsShipment = createGoodsShipment(product, price2, quantity2, day4);
-
- // Create purchase invoice, post it and assert it
- createPurchaseInvoice(goodsReceipt, price1, quantity1, day3);
-
- // Run price correction background
- runPriceBackground();
-
- // Assert product transactions
- List productTransactionAssertList = new ArrayList();
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsReceipt.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price1, price1));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(InventoryAmountUpdate.class, inventoryAmountUpdate.getId())
- .getInventoryAmountUpdateLineList().get(0), price1, price1));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(InventoryAmountUpdate.class, inventoryAmountUpdate.getId())
- .getInventoryAmountUpdateLineList().get(0), price2, price2, true));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsShipment.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price2, price2));
- assertProductTransaction(product.getId(), productTransactionAssertList);
-
- // Assert product costing
- List transactionList = getProductTransactions(product.getId());
- List productCostingAssertList = new ArrayList();
- productCostingAssertList.add(new ProductCostingAssert(transactionList.get(0), price1, null,
- price1, quantity1));
- productCostingAssertList.add(new ProductCostingAssert(transactionList.get(2), price2, null,
- price2, quantity1));
- assertProductCosting(product.getId(), productCostingAssertList);
-
- // Assert cost adjustment
- assertEquals(getCostAdjustment(product.getId()), null);
-
- OBDal.getInstance().commitAndClose();
-
- } catch (Exception e) {
- System.out.println(e.getMessage());
- throw new OBException(e);
- }
-
- finally {
- OBContext.restorePreviousMode();
- }
- }
-
- @Test
- public void testCostingF2() throws Exception {
-
- final int day0 = 0;
- final int day1 = 5;
- final int day2 = 10;
- final int day3 = 15;
- final int day4 = 20;
- final BigDecimal price1 = new BigDecimal("1230.00");
- final BigDecimal price2 = new BigDecimal("1200.00");
- final BigDecimal price3 = new BigDecimal("1500.00");
- final BigDecimal price4 = new BigDecimal("1174.50");
- final BigDecimal quantity1 = new BigDecimal("185");
- final BigDecimal quantity2 = new BigDecimal("85");
-
- try {
-
- OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
- OBContext.setAdminMode(true);
-
- // Create a new product for the test
- Product product = createProduct("testCostingF2", 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);
-
- // Add sleep to avoid assert errors
- Thread.sleep(1000);
-
- // Create goods shipment, run costing background, post it and assert it
- ShipmentInOut goodsShipment = createGoodsShipment(product, price1, quantity2, day4);
-
- // Add sleep to avoid assert errors
- Thread.sleep(1000);
-
- // Create inventory amount update and run costing background
- InventoryAmountUpdate inventoryAmountUpdate = createInventoryAmountUpdate(product, price1,
- price2, quantity1, day2);
-
- // Create purchase invoice, post it and assert it
- createPurchaseInvoice(goodsReceipt, price3, quantity1, day3);
-
- // Run price correction background
- runPriceBackground();
-
- // Assert product transactions
- List productTransactionAssertList = new ArrayList();
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsReceipt.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price1, price3));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(InventoryAmountUpdate.class, inventoryAmountUpdate.getId())
- .getInventoryAmountUpdateLineList().get(0), price1, price3));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(InventoryAmountUpdate.class, inventoryAmountUpdate.getId())
- .getInventoryAmountUpdateLineList().get(0), price2, price2, true));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsShipment.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price1, price2));
- assertProductTransaction(product.getId(), productTransactionAssertList);
-
- // Assert product costing
- List transactionList = getProductTransactions(product.getId());
- List productCostingAssertList = new ArrayList();
- productCostingAssertList.add(new ProductCostingAssert(transactionList.get(0), price3, price1,
- price3, quantity1));
- productCostingAssertList.add(new ProductCostingAssert(transactionList.get(2), price2, price4,
- price2, quantity1));
- assertProductCosting(product.getId(), productCostingAssertList);
-
- // Assert cost adjustment
- List costAdjustmentList = getCostAdjustment(product.getId());
- List> costAdjustmentAssertList = new ArrayList>();
- List costAdjustmentAssertLineList1 = new ArrayList();
- costAdjustmentAssertLineList1.add(new CostAdjustmentAssert(transactionList.get(1), "BDT",
- BigDecimal.ZERO, day2, true));
- costAdjustmentAssertList.add(costAdjustmentAssertLineList1);
- List costAdjustmentAssertLineList2 = new ArrayList();
- costAdjustmentAssertLineList2.add(new CostAdjustmentAssert(transactionList.get(2), "BDT",
- BigDecimal.ZERO, day2, true));
- costAdjustmentAssertLineList2.add(new CostAdjustmentAssert(transactionList.get(3), "PDC",
- quantity2.multiply(price2).add(quantity2.multiply(price1).negate()), day4, false));
- costAdjustmentAssertList.add(costAdjustmentAssertLineList2);
- List costAdjustmentAssertLineList3 = new ArrayList();
- costAdjustmentAssertLineList3.add(new CostAdjustmentAssert(transactionList.get(0), "PDC",
- quantity1.multiply(price3).add(quantity1.multiply(price1).negate()), day3, true));
- costAdjustmentAssertLineList3.add(new CostAdjustmentAssert(transactionList.get(1), "PDC",
- quantity1.multiply(price3).add(quantity1.multiply(price1).negate()), day3, false));
- costAdjustmentAssertList.add(costAdjustmentAssertLineList3);
- assertCostAdjustment(costAdjustmentList, costAdjustmentAssertList);
-
- // Post cost adjustment 2 and assert it
- postDocument(costAdjustmentList.get(1));
- List documentPostAssertList1 = new ArrayList();
- documentPostAssertList1.add(new DocumentPostAssert("99900", BigDecimal.ZERO, quantity2
- .multiply(price1).add(quantity2.multiply(price2).negate()), null));
- documentPostAssertList1.add(new DocumentPostAssert("35000", quantity2.multiply(price1).add(
- quantity2.multiply(price2).negate()), BigDecimal.ZERO, null));
- CostAdjustment costAdjustment1 = OBDal.getInstance().get(CostAdjustment.class,
- costAdjustmentList.get(1).getId());
- assertDocumentPost(costAdjustment1, product.getId(), documentPostAssertList1);
-
- // Post cost adjustment 3 and assert it
- postDocument(costAdjustmentList.get(2));
- List documentPostAssertList2 = new ArrayList();
- documentPostAssertList2.add(new DocumentPostAssert("99904", BigDecimal.ZERO, quantity1
- .multiply(price3).add(quantity1.multiply(price1).negate()), null));
- documentPostAssertList2.add(new DocumentPostAssert("35000", quantity1.multiply(price3).add(
- quantity1.multiply(price1).negate()), BigDecimal.ZERO, null));
- documentPostAssertList2.add(new DocumentPostAssert("61000", BigDecimal.ZERO, quantity1
- .multiply(price3).add(quantity1.multiply(price1).negate()), null));
- documentPostAssertList2.add(new DocumentPostAssert("35000", quantity1.multiply(price3).add(
- quantity1.multiply(price1).negate()), BigDecimal.ZERO, null));
- CostAdjustment costAdjustment2 = OBDal.getInstance().get(CostAdjustment.class,
- costAdjustmentList.get(2).getId());
- assertDocumentPost(costAdjustment2, product.getId(), documentPostAssertList2);
-
- OBDal.getInstance().commitAndClose();
-
- } catch (Exception e) {
- System.out.println(e.getMessage());
- throw new OBException(e);
- }
-
- finally {
- OBContext.restorePreviousMode();
- }
- }
-
- @Test
- public void testCostingGG() 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("15.00");
- final BigDecimal price2 = new BigDecimal("12.00");
- final BigDecimal price3 = new BigDecimal("13.50");
- final BigDecimal quantity1 = new BigDecimal("100");
- final BigDecimal quantity2 = new BigDecimal("200");
-
- try {
-
- OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
- OBContext.setAdminMode(true);
-
- // Create a new product for the test
- Product product = createProduct("testCostingGG", price1);
-
- // Create purchase order and book it
- Order purchaseOrder1 = createPurchaseOrder(product, price1, quantity1, day0);
-
- // Create purchase order and book it
- Order purchaseOrder2 = createPurchaseOrder(product, price2, quantity1, day1);
-
- // Create goods receipt, run costing background, post it and assert it
- ShipmentInOut goodsReceipt1 = createGoodsReceipt(purchaseOrder1, price1, quantity1, day2);
-
- // Create goods receipt, run costing background, post it and assert it
- ShipmentInOut goodsReceipt2 = createGoodsReceipt(purchaseOrder2, price2, quantity1, day3);
-
- // Create purchase invoice, post it and assert it
- List goodsReceiptList = new ArrayList();
- goodsReceiptList.add(goodsReceipt1);
- goodsReceiptList.add(goodsReceipt2);
- List priceList = new ArrayList();
- priceList.add(price1);
- priceList.add(price2);
- createPurchaseInvoice(goodsReceiptList, priceList, quantity2, day5);
-
- // Update transaction total cost amount
- manualCostAdjustment(getProductTransactions(product.getId()).get(1),
- quantity1.multiply(price1), false, day4);
-
- // Assert product transactions
- List productTransactionAssertList = new ArrayList();
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsReceipt1.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price1, price1, true, false));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsReceipt2.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price2, price1, true, true));
- assertProductTransaction(product.getId(), productTransactionAssertList);
-
- // Assert product costing
- List transactionList = getProductTransactions(product.getId());
- List productCostingAssertList = new ArrayList();
- productCostingAssertList.add(new ProductCostingAssert(transactionList.get(0), price1, null,
- price1, quantity1));
- productCostingAssertList.add(new ProductCostingAssert(transactionList.get(1), price1, price3,
- price1, quantity2));
- assertProductCosting(product.getId(), productCostingAssertList);
-
- // Assert cost adjustment
- List costAdjustmentList = getCostAdjustment(product.getId());
- List> costAdjustmentAssertList = new ArrayList>();
- List costAdjustmentAssertLineList = new ArrayList();
- costAdjustmentAssertLineList.add(new CostAdjustmentAssert(transactionList.get(1), "MCC",
- quantity1.multiply(price1).add(quantity1.multiply(price2).negate()), day4, true));
- costAdjustmentAssertList.add(costAdjustmentAssertLineList);
- assertCostAdjustment(costAdjustmentList, costAdjustmentAssertList);
-
- // Post cost adjustment 1 and assert it
- postDocument(costAdjustmentList.get(0));
- List documentPostAssertList = new ArrayList();
- documentPostAssertList.add(new DocumentPostAssert("61000", BigDecimal.ZERO, quantity1
- .multiply(price1).add(quantity1.multiply(price2).negate()), null));
- documentPostAssertList.add(new DocumentPostAssert("35000", quantity1.multiply(price1).add(
- quantity1.multiply(price2).negate()), BigDecimal.ZERO, null));
- CostAdjustment costAdjustment = OBDal.getInstance().get(CostAdjustment.class,
- costAdjustmentList.get(0).getId());
- assertDocumentPost(costAdjustment, product.getId(), documentPostAssertList);
-
- OBDal.getInstance().commitAndClose();
-
- } catch (Exception e) {
- System.out.println(e.getMessage());
- throw new OBException(e);
- }
-
- finally {
- OBContext.restorePreviousMode();
- }
- }
-
- @Test
- public void testCostingH1() 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("105.00");
- final BigDecimal price2 = new BigDecimal("105.50");
- final BigDecimal price3 = new BigDecimal("105.25");
- final BigDecimal price4 = new BigDecimal("106.00");
- final BigDecimal quantity1 = new BigDecimal("100");
- final BigDecimal quantity2 = new BigDecimal("200");
- final BigDecimal quantity3 = new BigDecimal("150");
-
- try {
-
- OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
- OBContext.setAdminMode(true);
-
- // Create a new product for the test
- Product product = createProduct("testCostingH1", price1);
-
- // Create purchase order and book it
- Order purchaseOrder1 = createPurchaseOrder(product, price1, quantity1, day0);
-
- // Create purchase order and book it
- Order purchaseOrder2 = createPurchaseOrder(product, price2, quantity1, day1);
-
- // Create goods receipt, run costing background, post it and assert it
- ShipmentInOut goodsReceipt1 = createGoodsReceipt(purchaseOrder1, price1, quantity1, day2);
-
- // Create goods receipt, run costing background, post it and assert it
- ShipmentInOut goodsReceipt2 = createGoodsReceipt(purchaseOrder2, price2, quantity1, day3);
-
- // Create purchase invoice, post it and assert it
- List goodsReceiptList = new ArrayList();
- goodsReceiptList.add(goodsReceipt1);
- goodsReceiptList.add(goodsReceipt2);
- List priceList = new ArrayList();
- priceList.add(price1);
- priceList.add(price2);
- createPurchaseInvoice(goodsReceiptList, priceList, quantity2, day4);
-
- // Create goods shipment, run costing background, post it and assert it
- ShipmentInOut goodsShipment = createGoodsShipment(product, price3, quantity3, day6);
-
- // Update transaction total cost amount
- manualCostAdjustment(getProductTransactions(product.getId()).get(1),
- quantity1.multiply(price4), false, day5);
-
- // Assert product transactions
- List productTransactionAssertList = new ArrayList();
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsReceipt1.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price1, price1, true, false));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsReceipt2.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price2, price4, true, true));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsShipment.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price3, price2));
- assertProductTransaction(product.getId(), productTransactionAssertList);
-
- // Assert product costing
- List transactionList = getProductTransactions(product.getId());
- List productCostingAssertList = new ArrayList();
- productCostingAssertList.add(new ProductCostingAssert(transactionList.get(0), price1, null,
- price1, quantity1));
- productCostingAssertList.add(new ProductCostingAssert(transactionList.get(1), price4, price3,
- price2, quantity2));
- assertProductCosting(product.getId(), productCostingAssertList);
-
- // Assert cost adjustment
- List costAdjustmentList = getCostAdjustment(product.getId());
- List> costAdjustmentAssertList = new ArrayList>();
- List costAdjustmentAssertLineList = new ArrayList();
- costAdjustmentAssertLineList.add(new CostAdjustmentAssert(transactionList.get(1), "MCC",
- quantity1.multiply(price4).add(quantity1.multiply(price2).negate()), day5, true));
- costAdjustmentAssertLineList.add(new CostAdjustmentAssert(transactionList.get(2), "MCC",
- quantity3.multiply(price2).add(quantity3.multiply(price3).negate()), day6, false));
- costAdjustmentAssertList.add(costAdjustmentAssertLineList);
- assertCostAdjustment(costAdjustmentList, costAdjustmentAssertList);
-
- // Post cost adjustment 1 and assert it
- postDocument(costAdjustmentList.get(0));
- List documentPostAssertList = new ArrayList();
- documentPostAssertList.add(new DocumentPostAssert("61000", BigDecimal.ZERO, quantity1
- .multiply(price4).add(quantity1.multiply(price2).negate()), null));
- documentPostAssertList.add(new DocumentPostAssert("35000", quantity1.multiply(price4).add(
- quantity1.multiply(price2).negate()), BigDecimal.ZERO, null));
- documentPostAssertList.add(new DocumentPostAssert("99900", quantity3.multiply(price2).add(
- quantity3.multiply(price3).negate()), BigDecimal.ZERO, null));
- documentPostAssertList.add(new DocumentPostAssert("35000", BigDecimal.ZERO, quantity3
- .multiply(price2).add(quantity3.multiply(price3).negate()), null));
- CostAdjustment costAdjustment = OBDal.getInstance().get(CostAdjustment.class,
- costAdjustmentList.get(0).getId());
- assertDocumentPost(costAdjustment, product.getId(), documentPostAssertList);
-
- OBDal.getInstance().commitAndClose();
-
- } catch (Exception e) {
- System.out.println(e.getMessage());
- throw new OBException(e);
- }
-
- finally {
- OBContext.restorePreviousMode();
- }
- }
-
- @Test
- public void testCostingII() throws Exception {
-
- final int day0 = 0;
- final int day1 = 5;
- final int day2 = 10;
- final int year = 1;
- final BigDecimal price1 = new BigDecimal("95.00");
- final BigDecimal price2 = new BigDecimal("100.00");
- final BigDecimal quantity1 = new BigDecimal("1500");
- final BigDecimal quantity2 = new BigDecimal("100");
- final String costType = "STA";
-
- try {
-
- OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
- OBContext.setAdminMode(true);
-
- // Create a new product for the test
- Product product = createProduct("testCostingII", price1, price2, costType, year);
-
- // Create goods receipt, run costing background, post it and assert it
- ShipmentInOut goodsReceipt = createGoodsReceipt(product, price2, quantity1, day0);
-
- // Create goods shipment, run costing background, post it and assert it
- ShipmentInOut goodsShipment = createGoodsShipment(product, price2, quantity2, day2);
-
- // Create purchase invoice, post it and assert it
- createPurchaseInvoice(goodsReceipt, price1, quantity1, day1);
-
- // Run price correction background
- runPriceBackground();
-
- // Assert product transactions
- List productTransactionAssertList = new ArrayList();
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsReceipt.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price2, price1));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsShipment.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price2, price1));
- assertProductTransaction(product.getId(), productTransactionAssertList);
-
- // Assert product costing
- List transactionList = getProductTransactions(product.getId());
- List productCostingAssertList = new ArrayList();
- productCostingAssertList.add(new ProductCostingAssert(null, null, null, price2, null,
- costType, year));
- productCostingAssertList.add(new ProductCostingAssert(transactionList.get(0), price1, price2,
- price1, quantity1));
- assertProductCosting(product.getId(), productCostingAssertList);
-
- // Assert cost adjustment
- List costAdjustmentList = getCostAdjustment(product.getId());
- List> costAdjustmentAssertList = new ArrayList>();
- List costAdjustmentAssertLineList = new ArrayList();
- costAdjustmentAssertLineList.add(new CostAdjustmentAssert(transactionList.get(0), "PDC",
- quantity1.multiply(price1).add(quantity1.multiply(price2).negate()), day1, true));
- costAdjustmentAssertLineList.add(new CostAdjustmentAssert(transactionList.get(1), "PDC",
- quantity2.multiply(price1).add(quantity2.multiply(price2).negate()), day2, false));
- costAdjustmentAssertList.add(costAdjustmentAssertLineList);
- assertCostAdjustment(costAdjustmentList, costAdjustmentAssertList);
-
- // Post cost adjustment and assert it
- postDocument(costAdjustmentList.get(0));
- List documentPostAssertList = new ArrayList();
- documentPostAssertList.add(new DocumentPostAssert("99904", quantity1.multiply(price2).add(
- quantity1.multiply(price1).negate()), BigDecimal.ZERO, null));
- documentPostAssertList.add(new DocumentPostAssert("35000", BigDecimal.ZERO, quantity1
- .multiply(price2).add(quantity1.multiply(price1).negate()), null));
- documentPostAssertList.add(new DocumentPostAssert("99900", BigDecimal.ZERO, quantity2
- .multiply(price2).add(quantity2.multiply(price1).negate()), null));
- documentPostAssertList.add(new DocumentPostAssert("35000", quantity2.multiply(price2).add(
- quantity2.multiply(price1).negate()), BigDecimal.ZERO, null));
- CostAdjustment costAdjustment = OBDal.getInstance().get(CostAdjustment.class,
- costAdjustmentList.get(0).getId());
- assertDocumentPost(costAdjustment, product.getId(), documentPostAssertList);
-
- OBDal.getInstance().commitAndClose();
-
- } catch (Exception e) {
- System.out.println(e.getMessage());
- throw new OBException(e);
- }
-
- finally {
- OBContext.restorePreviousMode();
- }
- }
-
- @Test
- public void testCostingJJ() throws Exception {
-
- final int day0 = 0;
- final int day1 = 5;
- final int day2 = 10;
- final int year = -1;
- final BigDecimal price1 = new BigDecimal("95.00");
- final BigDecimal price2 = new BigDecimal("100.00");
- final BigDecimal price3 = new BigDecimal("195.00");
- final BigDecimal quantity1 = new BigDecimal("1500");
- final BigDecimal quantity2 = new BigDecimal("500");
- final String costType = "STA";
-
- try {
-
- OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
- OBContext.setAdminMode(true);
-
- // Create a new product for the test
- Product product = createProduct("testCostingJJ", price1, price2, costType, year);
-
- // Create goods receipt, run costing background, post it and assert it
- ShipmentInOut goodsReceipt = createGoodsReceipt(product, price1, quantity1, day0);
-
- // Create goods shipment, run costing background, post it and assert it
- ShipmentInOut goodsShipment = createGoodsShipment(product, price1, quantity2, day2);
-
- // Create purchase invoice, post it and assert it
- createPurchaseInvoice(goodsReceipt, price3, quantity1, day1);
-
- // Run price correction background
- runPriceBackground();
-
- // Assert product transactions
- List productTransactionAssertList = new ArrayList();
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsReceipt.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price1, price3));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsShipment.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price1, price3));
- assertProductTransaction(product.getId(), productTransactionAssertList);
-
- // Assert product costing
- List transactionList = getProductTransactions(product.getId());
- List productCostingAssertList = new ArrayList();
- productCostingAssertList.add(new ProductCostingAssert(null, null, null, price2, null,
- costType, year));
- productCostingAssertList.add(new ProductCostingAssert(transactionList.get(0), price3, price1,
- price3, quantity1));
- assertProductCosting(product.getId(), productCostingAssertList);
-
- // Assert cost adjustment
- List costAdjustmentList = getCostAdjustment(product.getId());
- List> costAdjustmentAssertList = new ArrayList>();
- List costAdjustmentAssertLineList = new ArrayList();
- costAdjustmentAssertLineList.add(new CostAdjustmentAssert(transactionList.get(0), "PDC",
- quantity1.multiply(price3).add(quantity1.multiply(price1).negate()), day1, true));
- costAdjustmentAssertLineList.add(new CostAdjustmentAssert(transactionList.get(1), "PDC",
- quantity2.multiply(price3).add(quantity2.multiply(price1).negate()), day2, false));
- costAdjustmentAssertList.add(costAdjustmentAssertLineList);
- assertCostAdjustment(costAdjustmentList, costAdjustmentAssertList);
-
- // Post cost adjustment and assert it
- postDocument(costAdjustmentList.get(0));
- List documentPostAssertList = new ArrayList();
- documentPostAssertList.add(new DocumentPostAssert("99904", BigDecimal.ZERO, quantity1
- .multiply(price3).add(quantity1.multiply(price1).negate()), null));
- documentPostAssertList.add(new DocumentPostAssert("35000", quantity1.multiply(price3).add(
- quantity1.multiply(price1).negate()), BigDecimal.ZERO, null));
- documentPostAssertList.add(new DocumentPostAssert("99900", quantity2.multiply(price3).add(
- quantity2.multiply(price1).negate()), BigDecimal.ZERO, null));
- documentPostAssertList.add(new DocumentPostAssert("35000", BigDecimal.ZERO, quantity2
- .multiply(price3).add(quantity2.multiply(price1).negate()), null));
- CostAdjustment costAdjustment = OBDal.getInstance().get(CostAdjustment.class,
- costAdjustmentList.get(0).getId());
- assertDocumentPost(costAdjustment, product.getId(), documentPostAssertList);
-
- OBDal.getInstance().commitAndClose();
-
- } catch (Exception e) {
- System.out.println(e.getMessage());
- throw new OBException(e);
- }
-
- finally {
- OBContext.restorePreviousMode();
- }
- }
-
- @Test
- public void testCostingJJJ() throws Exception {
-
- final int day0 = 0;
- final int day1 = 5;
- final int day2 = 10;
- final int day3 = 15;
- final int year = -1;
- final BigDecimal price1 = new BigDecimal("95.00");
- final BigDecimal price2 = new BigDecimal("100.00");
- final BigDecimal price3 = new BigDecimal("195.00");
- final BigDecimal quantity1 = new BigDecimal("1500");
- final BigDecimal quantity2 = new BigDecimal("500");
- final BigDecimal quantity3 = new BigDecimal("50");
- final String costType = "STA";
-
- try {
-
- OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
- OBContext.setAdminMode(true);
-
- // Create a new product for the test
- Product product = createProduct("testCostingJJJ", price1, price2, costType, year);
-
- // Create goods receipt, run costing background, post it and assert it
- ShipmentInOut goodsReceipt = createGoodsReceipt(product, price1, quantity1, day0);
-
- // Create goods shipment, run costing background, post it and assert it
- ShipmentInOut goodsShipment1 = createGoodsShipment(product, price1, quantity2, day1);
-
- // Create purchase invoice, post it and assert it
- createPurchaseInvoice(goodsReceipt, price3, quantity1, day2);
-
- // Run price correction background
- runPriceBackground();
-
- // Create goods shipment, run costing background, post it and assert it
- ShipmentInOut goodsShipment2 = createGoodsShipment(product, price3, quantity3, day3);
-
- // Run price correction background
- runPriceBackground();
-
- // Assert product transactions
- List productTransactionAssertList = new ArrayList();
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsReceipt.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price1, price3));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsShipment1.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price1, price3));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsShipment2.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price3, price3));
- assertProductTransaction(product.getId(), productTransactionAssertList);
-
- // Assert product costing
- List transactionList = getProductTransactions(product.getId());
- List productCostingAssertList = new ArrayList();
- productCostingAssertList.add(new ProductCostingAssert(null, null, null, price2, null,
- costType, year));
- productCostingAssertList.add(new ProductCostingAssert(transactionList.get(0), price3, price1,
- price3, quantity1));
- assertProductCosting(product.getId(), productCostingAssertList);
-
- // Assert cost adjustment
- List costAdjustmentList = getCostAdjustment(product.getId());
- List> costAdjustmentAssertList = new ArrayList>();
- List costAdjustmentAssertLineList = new ArrayList();
- costAdjustmentAssertLineList.add(new CostAdjustmentAssert(transactionList.get(0), "PDC",
- quantity1.multiply(price3).add(quantity1.multiply(price1).negate()), day2, true));
- costAdjustmentAssertLineList.add(new CostAdjustmentAssert(transactionList.get(1), "PDC",
- quantity2.multiply(price3).add(quantity2.multiply(price1).negate()), day2, false));
- costAdjustmentAssertList.add(costAdjustmentAssertLineList);
- assertCostAdjustment(costAdjustmentList, costAdjustmentAssertList);
-
- // Post cost adjustment and assert it
- postDocument(costAdjustmentList.get(0));
- List documentPostAssertList = new ArrayList();
- documentPostAssertList.add(new DocumentPostAssert("99904", BigDecimal.ZERO, quantity1
- .multiply(price3).add(quantity1.multiply(price1).negate()), null));
- documentPostAssertList.add(new DocumentPostAssert("35000", quantity1.multiply(price3).add(
- quantity1.multiply(price1).negate()), BigDecimal.ZERO, null));
- documentPostAssertList.add(new DocumentPostAssert("99900", quantity2.multiply(price3).add(
- quantity2.multiply(price1).negate()), BigDecimal.ZERO, null));
- documentPostAssertList.add(new DocumentPostAssert("35000", BigDecimal.ZERO, quantity2
- .multiply(price3).add(quantity2.multiply(price1).negate()), null));
- CostAdjustment costAdjustment = OBDal.getInstance().get(CostAdjustment.class,
- costAdjustmentList.get(0).getId());
- assertDocumentPost(costAdjustment, product.getId(), documentPostAssertList);
-
- OBDal.getInstance().commitAndClose();
-
- } catch (Exception e) {
- System.out.println(e.getMessage());
- throw new OBException(e);
- }
-
- finally {
- OBContext.restorePreviousMode();
- }
- }
-
- @Test
- public void testCostingK2() throws Exception {
-
- final int day0 = 0;
- final int day1 = 5;
- final int day2 = 10;
- final int year = 1;
- final BigDecimal price1 = new BigDecimal("95.00");
- final BigDecimal price2 = new BigDecimal("100.00");
- final BigDecimal price3 = new BigDecimal("80.00");
- final BigDecimal quantity1 = new BigDecimal("100");
- final BigDecimal quantity2 = new BigDecimal("90");
- final BigDecimal quantity3 = new BigDecimal("45");
- final String costType = "STA";
-
- try {
-
- OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
- OBContext.setAdminMode(true);
-
- // Create a new product for the test
- Product product = createProduct("testCostingK2", price1, price2, costType, year);
-
- // Create purchase order and book it
- createPurchaseOrder(product, price3, quantity1, day0);
-
- // Create goods receipt, run costing background, post it and assert it
- ShipmentInOut goodsReceipt = createGoodsReceipt(product, price3, quantity2, day1);
-
- // Create goods shipment, run costing background, post it and assert it
- ShipmentInOut goodsShipment = createGoodsShipment(product, price3, quantity3, day2);
-
- // Create purchase invoice, post it and assert it
- createPurchaseInvoice(goodsReceipt, price1, quantity2, day2);
-
- // Run price correction background
- runPriceBackground();
-
- // Assert product transactions
- List productTransactionAssertList1 = new ArrayList();
- productTransactionAssertList1.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsReceipt.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price3, price1));
- productTransactionAssertList1.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsShipment.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price3, price1));
- assertProductTransaction(product.getId(), productTransactionAssertList1);
-
- // Assert product costing
- List transactionList1 = getProductTransactions(product.getId());
- List productCostingAssertList1 = new ArrayList();
- productCostingAssertList1.add(new ProductCostingAssert(null, null, null, price2, null,
- costType, year));
- productCostingAssertList1.add(new ProductCostingAssert(transactionList1.get(0), price1,
- price3, price1, quantity2));
- assertProductCosting(product.getId(), productCostingAssertList1);
-
- // Assert cost adjustment
- List costAdjustmentList1 = getCostAdjustment(product.getId());
- List> costAdjustmentAssertList1 = new ArrayList>();
- List costAdjustmentAssertLineList1 = new ArrayList();
- costAdjustmentAssertLineList1.add(new CostAdjustmentAssert(transactionList1.get(0), "PDC",
- quantity2.multiply(price1).add(quantity2.multiply(price3).negate()), day2, true));
- costAdjustmentAssertLineList1.add(new CostAdjustmentAssert(transactionList1.get(1), "PDC",
- quantity3.multiply(price1).add(quantity3.multiply(price3).negate()), day2, false));
- costAdjustmentAssertList1.add(costAdjustmentAssertLineList1);
- assertCostAdjustment(costAdjustmentList1, costAdjustmentAssertList1);
-
- // Post cost adjustment and assert it
- postDocument(costAdjustmentList1.get(0));
- List documentPostAssertList1 = new ArrayList();
- documentPostAssertList1.add(new DocumentPostAssert("99904", BigDecimal.ZERO, quantity2
- .multiply(price1).add(quantity2.multiply(price3).negate()), null));
- documentPostAssertList1.add(new DocumentPostAssert("35000", quantity2.multiply(price1).add(
- quantity2.multiply(price3).negate()), BigDecimal.ZERO, null));
- documentPostAssertList1.add(new DocumentPostAssert("99900", quantity3.multiply(price1).add(
- quantity3.multiply(price3).negate()), BigDecimal.ZERO, null));
- documentPostAssertList1.add(new DocumentPostAssert("35000", BigDecimal.ZERO, quantity3
- .multiply(price1).add(quantity3.multiply(price3).negate()), null));
- CostAdjustment costAdjustment = OBDal.getInstance().get(CostAdjustment.class,
- costAdjustmentList1.get(0).getId());
- assertDocumentPost(costAdjustment, product.getId(), documentPostAssertList1);
-
- // Cancel Cost Adjustment
- cancelCostAdjustment(costAdjustment);
-
- // Assert product transactions
- List productTransactionAssertList2 = new ArrayList();
- productTransactionAssertList2.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsReceipt.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price3, price3));
- productTransactionAssertList2.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsShipment.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price3, price3));
- assertProductTransaction(product.getId(), productTransactionAssertList2);
-
- // Assert product costing
- List transactionList2 = getProductTransactions(product.getId());
- List productCostingAssertList2 = new ArrayList();
- productCostingAssertList2.add(new ProductCostingAssert(null, null, null, price2, null,
- costType, year));
- productCostingAssertList2.add(new ProductCostingAssert(transactionList2.get(0), price3,
- price3, price3, quantity2));
- assertProductCosting(product.getId(), productCostingAssertList2);
-
- // Assert cost adjustment
- List costAdjustmentList2 = getCostAdjustment(product.getId());
- List> costAdjustmentAssertList2 = new ArrayList>();
- List costAdjustmentAssertLineList21 = new ArrayList();
- costAdjustmentAssertLineList21.add(new CostAdjustmentAssert(transactionList2.get(0), "PDC",
- quantity2.multiply(price1).add(quantity2.multiply(price3).negate()), day2, true, "VO"));
- costAdjustmentAssertLineList21.add(new CostAdjustmentAssert(transactionList2.get(1), "PDC",
- quantity3.multiply(price1).add(quantity3.multiply(price3).negate()), day2, false, "VO"));
- costAdjustmentAssertList2.add(costAdjustmentAssertLineList21);
- List costAdjustmentAssertLineList22 = new ArrayList();
- costAdjustmentAssertLineList22.add(new CostAdjustmentAssert(transactionList2.get(0), "PDC",
- quantity2.multiply(price3).add(quantity2.multiply(price1).negate()), day2, true, "VO"));
- costAdjustmentAssertLineList22.add(new CostAdjustmentAssert(transactionList2.get(1), "PDC",
- quantity3.multiply(price3).add(quantity3.multiply(price1).negate()), day2, false, "VO"));
- costAdjustmentAssertList2.add(costAdjustmentAssertLineList22);
- assertCostAdjustment(costAdjustmentList2, costAdjustmentAssertList2);
-
- // Post cost adjustment 1 and assert it
- List documentPostAssertList21 = new ArrayList();
- documentPostAssertList21.add(new DocumentPostAssert("99904", BigDecimal.ZERO, quantity2
- .multiply(price1).add(quantity2.multiply(price3).negate()), null));
- documentPostAssertList21.add(new DocumentPostAssert("35000", quantity2.multiply(price1).add(
- quantity2.multiply(price3).negate()), BigDecimal.ZERO, null));
- documentPostAssertList21.add(new DocumentPostAssert("99900", quantity3.multiply(price1).add(
- quantity3.multiply(price3).negate()), BigDecimal.ZERO, null));
- documentPostAssertList21.add(new DocumentPostAssert("35000", BigDecimal.ZERO, quantity3
- .multiply(price1).add(quantity3.multiply(price3).negate()), null));
- CostAdjustment costAdjustment21 = OBDal.getInstance().get(CostAdjustment.class,
- costAdjustmentList2.get(0).getId());
- assertDocumentPost(costAdjustment21, product.getId(), documentPostAssertList21);
-
- // Post cost adjustment 2 and assert it
- postDocument(costAdjustmentList2.get(1));
- List documentPostAssertList22 = new ArrayList();
- documentPostAssertList22.add(new DocumentPostAssert("99904", quantity2.multiply(price1).add(
- quantity2.multiply(price3).negate()), BigDecimal.ZERO, null));
- documentPostAssertList22.add(new DocumentPostAssert("35000", BigDecimal.ZERO, quantity2
- .multiply(price1).add(quantity2.multiply(price3).negate()), null));
- documentPostAssertList22.add(new DocumentPostAssert("99900", BigDecimal.ZERO, quantity3
- .multiply(price1).add(quantity3.multiply(price3).negate()), null));
- documentPostAssertList22.add(new DocumentPostAssert("35000", quantity3.multiply(price1).add(
- quantity3.multiply(price3).negate()), BigDecimal.ZERO, null));
- CostAdjustment costAdjustment22 = OBDal.getInstance().get(CostAdjustment.class,
- costAdjustmentList2.get(1).getId());
- assertDocumentPost(costAdjustment22, product.getId(), documentPostAssertList22);
-
- OBDal.getInstance().commitAndClose();
-
- } catch (Exception e) {
- System.out.println(e.getMessage());
- throw new OBException(e);
- }
-
- finally {
- OBContext.restorePreviousMode();
- }
- }
-
- @Test
- public void testCostingN0() throws Exception {
-
- final int day0 = 0;
- final int day1 = 5;
- final int day2 = 10;
- final int day3 = 15;
- final int day4 = 20;
- final BigDecimal price1 = new BigDecimal("10.00");
- final BigDecimal price2 = new BigDecimal("20.00");
- final BigDecimal price3 = new BigDecimal("30.00");
- final BigDecimal price4 = new BigDecimal("15.00");
- final BigDecimal quantity1 = new BigDecimal("100");
- final BigDecimal quantity2 = new BigDecimal("5");
- final BigDecimal quantity3 = new BigDecimal("10");
-
- try {
-
- OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
- OBContext.setAdminMode(true);
-
- // Create a new product for the test
- Product product = createProduct("testCostingN0", 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 goods shipment, run costing background, post it and assert it
- ShipmentInOut goodsShipment1 = createGoodsShipment(product, price1, quantity1, day2);
-
- // Create goods shipment, run costing background, post it and assert it
- ShipmentInOut goodsShipment2 = createGoodsShipment(product, price1, quantity2, day3);
-
- // Create purchase order and book it
- Order purchaseOrder2 = createPurchaseOrder(product, price2, quantity3, day4);
-
- // Create goods receipt, run costing background, post it and assert it
- ShipmentInOut goodsReceipt2 = createGoodsReceipt(purchaseOrder2, price2, quantity3, day4);
-
- // Assert product transactions
- List productTransactionAssertList = new ArrayList();
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsReceipt1.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price1, price1));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsShipment1.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price1, price1));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsShipment2.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price1, price1));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsReceipt2.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price2, price4, price2));
- assertProductTransaction(product.getId(), productTransactionAssertList);
-
- // Assert product costing
- List transactionList = getProductTransactions(product.getId());
- List productCostingAssertList = new ArrayList();
- productCostingAssertList.add(new ProductCostingAssert(transactionList.get(0), price1, null,
- price1, quantity1));
- productCostingAssertList.add(new ProductCostingAssert(transactionList.get(3), price2, price3,
- price2, quantity2));
- assertProductCosting(product.getId(), productCostingAssertList);
-
- // Assert cost adjustment
- List costAdjustmentList = getCostAdjustment(product.getId());
- List> costAdjustmentAssertList = new ArrayList>();
- List costAdjustmentAssertLineList = new ArrayList();
- costAdjustmentAssertLineList.add(new CostAdjustmentAssert(transactionList.get(3), "NSC",
- quantity3.multiply(price4).add(quantity3.multiply(price2).negate()), day4, true, false));
- costAdjustmentAssertList.add(costAdjustmentAssertLineList);
- assertCostAdjustment(costAdjustmentList, costAdjustmentAssertList);
-
- // Post cost adjustment and assert it
- postDocument(costAdjustmentList.get(0));
- List documentPostAssertList1 = new ArrayList();
- documentPostAssertList1.add(new DocumentPostAssert("61000", quantity3.multiply(price2).add(
- quantity3.multiply(price4).negate()), BigDecimal.ZERO, null));
- documentPostAssertList1.add(new DocumentPostAssert("35000", BigDecimal.ZERO, quantity3
- .multiply(price2).add(quantity3.multiply(price4).negate()), null));
- CostAdjustment costAdjustment = OBDal.getInstance().get(CostAdjustment.class,
- costAdjustmentList.get(0).getId());
- assertDocumentPost(costAdjustment, product.getId(), documentPostAssertList1);
-
- OBDal.getInstance().commitAndClose();
-
- } catch (Exception e) {
- System.out.println(e.getMessage());
- throw new OBException(e);
- }
-
- finally {
- OBContext.restorePreviousMode();
- }
- }
-
- @Test
- public void testCostingN1() throws Exception {
-
- final int day0 = 0;
- final int day1 = 5;
- final int year = 1;
- final BigDecimal price1 = new BigDecimal("20.00");
- final BigDecimal price2 = new BigDecimal("15.00");
- final BigDecimal price3 = new BigDecimal("10.00");
- final BigDecimal price4 = new BigDecimal("17.50");
- final BigDecimal quantity1 = new BigDecimal("100");
- final BigDecimal quantity2 = new BigDecimal("200");
- final String costType = "AVA";
-
- try {
-
- OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
- OBContext.setAdminMode(true);
-
- // Create a new product for the test
- Product product = createProduct("testCostingN0", price1, price1, costType, year);
-
- // Create goods shipment, run costing background, post it and assert it
- ShipmentInOut goodsShipment = createGoodsShipment(product, price1, quantity1, day0);
-
- // Create purchase order and book it
- Order purchaseOrder = createPurchaseOrder(product, price2, quantity2, day1);
-
- // Create goods receipt, run costing background, post it and assert it
- ShipmentInOut goodsReceipt = createGoodsReceipt(purchaseOrder, price2, quantity2, day1);
-
- // Assert product transactions
- List productTransactionAssertList = new ArrayList();
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsShipment.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price1, price1));
- productTransactionAssertList.add(new ProductTransactionAssert(OBDal.getInstance()
- .get(ShipmentInOut.class, goodsReceipt.getId()).getMaterialMgmtShipmentInOutLineList()
- .get(0), price2, price4, price2));
- assertProductTransaction(product.getId(), productTransactionAssertList);
-
- // Assert product costing
- List transactionList = getProductTransactions(product.getId());
- List productCostingAssertList = new ArrayList