Tuesday, 14 July 2015

Import Product Variant with Master item with excel through Job

Import  Product Variant with Master item with excel through Job:

//This code is Wrriten by @@ Hashal Kambale@@




Static void HK_ProductImport(Args _args)
{

EcoResProductIdentifier ecoResProductIdentifier;

EcoResDistinctProductVariant ecoResDistinctProductVariant;

EcoResProductVariantConfiguration ecoResProductVariantConfiguration;

EcoResProductVariantColor ecoResProductVariantColor;

//

EcoResProductVariantSize ecoResProductVariantSize;
//

EcoResProductMaster ecoResProductMaster;

InventTable inventTable;

InventTableModule inventTableModule;

InventItemSetupSupplyType inventItemSetupSupplyType;

EcoResSize ecoResSize;

EcoResStorageDimensionGroupProduct ecoResStorageDimensionGroupProduct;

EcoResTrackingDimensionGroupProduct ecoResTrackingDimensionGroupProduct;

EcoResStorageDimensionGroupItem ecoResStorageDimensionGroupItem;

EcoResTrackingDimensionGroupItem ecoResTrackingDimensionGroupItem;

InventModelGroupItem inventModelGroupItem;

InventItemGroupItem inventItemGroupItem;

InventDim inventDim;

InventDimCombination inventDimCombination;

inventTable inventTable_loc;

;

ecoRessize = EcoRessize::findByName(

"55");


if (!ecoRessize)

{

ecoRessize.clear();

ecoRessize.initValue();

ecoRessize.Name =

"55";


if(ecoRessize.Name)

ecoRessize.insert();

}

ecoResProductMaster = EcoResProductMaster::find(

52565464405);

ecoResDistinctProductVariant.clear();

ecoResDistinctProductVariant.initValue();

ecoResDistinctProductVariant.DisplayProductNumber = EcoResProductNumberBuilderVariant::buildFromProductNumberAndDimensions(

ecoResProductMaster.productNumber(),

EcoResProductVariantDimValue::getDimensionValuesContainer(

"","55","",""));

ecoResDistinctProductVariant.SearchName = ecoResProductMaster.SearchName;

ecoResDistinctProductVariant.ProductType = ecoResProductMaster.ProductType;

ecoResDistinctProductVariant.ProductMaster = ecoResProductMaster.RecId;

ecoResDistinctProductVariant.insert();

ecoResProductVariantsize.clear();

ecoResProductVariantsize.initValue();

ecoResProductVariantsize.initFromDistinctProductVariant(ecoResDistinctProductVariant);

ecoResProductVariantsize.ProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(

fieldNum(InventDim, InventSizeId));

ecoResProductVariantsize.Size = ecoRessize.RecId;


if(ecoRessize.Name)

ecoResProductVariantsize.insert();

EcoResProductTranslation::createOrUpdateTranslation(ecoResDistinctProductVariant.RecId,

"CLO1200065", "Size 6 DUNLOP PUROFORT WELLINGTON-164050","en-us");

inventTable.clear();

inventTable.initValue();

inventTable.initFromEcoResProduct(ecoResProductMaster);

ecoResProductIdentifier = EcoResProductIdentifier::findByProduct(ecoResProductMaster.RecId);

inventTable.ItemId = ecoResProductIdentifier.ProductNumber;

inventTable.NameAlias = ecoResProductMaster.SearchName;

inventTable.PmfProductType = PmfProductType::None;


if (inventTable.validateWrite())

{

inventTable.insert();


//Inventory model group

inventModelGroupItem.clear();

inventModelGroupItem.initValue();

inventModelGroupItem.ItemDataAreaId = inventTable.dataAreaId;

inventModelGroupItem.ItemId = inventTable.ItemId;

inventModelGroupItem.ModelGroupId =

"FIFO";

inventModelGroupItem.ModelGroupDataAreaId =
curext();

inventModelGroupItem.insert();


//Item group


//inventItemGroupItem.clear();


//inventItemGroupItem.initValue();


//inventItemGroupItem.ItemDataAreaId = inventTable.dataAreaId;


//inventItemGroupItem.ItemId = inventTable.ItemId;


//inventItemGroupItem.ItemGroupId =


//inventItemGroupItem.ItemGroupDataAreaId = curext();


//inventItemGroupItem.insert();


//Extended product details - Inventory

inventTableModule.clear();

inventTableModule.initValue();

inventTableModule.ItemId = inventTable.ItemId;

inventTableModule.ModuleType = ModuleInventPurchSales::Invent;

inventTableModule.insert();


//Extended product details - Purchase

inventTableModule.clear();

inventTableModule.initValue();

inventTableModule.ItemId = inventTable.ItemId;

inventTableModule.ModuleType = ModuleInventPurchSales::Purch;

inventTableModule.insert();


//Extended product details - Sales

inventTableModule.clear();

inventTableModule.initValue();

inventTableModule.ItemId = inventTable.ItemId;

inventTableModule.ModuleType = ModuleInventPurchSales::Sales;

inventTableModule.UnitId =

'ea';

inventTableModule.insert();


//Warehouse items

InventItemLocation::createDefault(inventTable.ItemId);


//Supply type setup

inventItemSetupSupplyType.clear();

inventItemSetupSupplyType.initValue();

inventItemSetupSupplyType.ItemId = inventTable.ItemId;

inventItemSetupSupplyType.ItemDataAreaId = inventTable.DataAreaId;

inventItemSetupSupplyType.insert();


//Product storage dimension group

ecoResStorageDimensionGroupProduct = EcoResStorageDimensionGroupProduct::findByProduct(ecoResProductMaster.RecId);


if(ecoResStorageDimensionGroupProduct.RecId)

{

ecoResStorageDimensionGroupItem.clear();

ecoResStorageDimensionGroupItem.initValue();

ecoResStorageDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId;

ecoResStorageDimensionGroupItem.ItemId = inventTable.ItemId;

ecoResStorageDimensionGroupItem.StorageDimensionGroup = ecoResStorageDimensionGroupProduct.StorageDimensionGroup;

ecoResStorageDimensionGroupItem.insert();

}


//Product tracking dimension group

ecoResTrackingDimensionGroupProduct = EcoResTrackingDimensionGroupProduct::findByProduct(ecoResProductMaster.RecId);


if (ecoResTrackingDimensionGroupProduct.RecId)

{

ecoResTrackingDimensionGroupItem.clear();

ecoResTrackingDimensionGroupItem.initValue();

ecoResTrackingDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId;

ecoResTrackingDimensionGroupItem.ItemId = inventTable.ItemId;

ecoResTrackingDimensionGroupItem.TrackingDimensionGroup = ecoResTrackingDimensionGroupProduct.TrackingDimensionGroup;

ecoResTrackingDimensionGroupItem.insert();

}

}

inventDim.clear();

inventDim.ConfigId =

"";

inventDim.InventSizeId = ecoResSize.Name;

inventDim.InventColorId =

"";

inventDim = InventDim::findOrCreate(inventDim);


//Released product variant

inventDimCombination.clear();

inventDimCombination.initValue();

inventDimCombination.DistinctProductVariant = ecoResDistinctProductVariant.RecId;

inventDimCombination.ItemId = inventTable.ItemId;

inventDimCombination.InventDimId = inventDim.InventDimId;

inventDimCombination.insert();

info(

"Product variant imported sucessfully");

}

 

 

 

 

No comments:

Post a Comment