http://ajit-axaptacomconnector.blogspot.com/2011/12/create-and-release-product-through-code.html
void createItem(ItemId _itemId,
ItemName _itemName,
EcoResProductType _itemType,
BOMUnitId _BOMUnit,
ItemGroupId _itemGroup,
InventModelGroupId _modelGroup,
EcoResProductDimensionGroupName _dimName,
EcoResProductDimensionGroupName _revision,
ReqGroupId _coverageGroup,
ECOId _ECOId,
EcoResProduct product)
{
//AxInventTable axInventTable = new AxInventTable();
EcoResProduct _product;
EcoResProductMaster _productMaster;
EcoResProductIdentifier _productIdentifier;
EcoResProductTranslation _transaltion,productVariantTranslation;
EcoResProductDimensionGroupProduct _dimProduct;
EcoResProductDimensionGroup _dimGroup;
EcoResProductType EcoResProductType;
EcoResReleaseSession releaseSession;
EcoResReleaseSessionProduct productSession,productSessionVariant;
EcoResConfiguration ecoResConfigurationLocal;
EcoResProductMasterConfiguration productConfig;
EcoResDistinctProduct distinctProduct;
EcoResDistinctProductVariant distinctProductVariant;
EcoResProductVariantConfiguration productVariantConfiguration;
container dimensions;
EcoResProductReleaseSessionBatch productReleaseSessionBatch = new EcoResProductReleaseSessionBatch();
EcoResStorageDimensionGroup storageDimension;
EcoResStorageDimensionGroupProduct storageDimProduct;
EcoResTrackingDimensionGroup trackingDimension;
EcoResTrackingDimensionGroupProduct trackingDimProduct;
EcoResReleaseProductLegalEntity releaseLegalEntity,releaseLegalEntityVariant;
CompanyInfo company;
//EcoResProductNumberBuilderVariant productNumberbuildervariant= new EcoResProductNumberBuilderVariant();
_dimGroup = EcoResProductDimensionGroup::findByDimensionGroupName(BOMParameters::find().IGNDefaultProductGroupId);
storageDimension = EcoResStorageDimensionGroup::findByDimensionGroupName(_dimName);
trackingDimension = EcoResTrackingDimensionGroup::findByDimensionGroupName(BOMParameters::find().IGNDefaultTrackingGroupId);
/*axInventTable.parmItemId(_itemId);
axInventTable.parmItemName(_itemName);
axInventTable.parmItemType(_itemType);
axInventTable.parmBOMUnitId(_BOMUnit);
axInventTable.parmItemGroupId(_itemGroup);
axInventTable.parmModelGroupId(_modelGroup);
axInventTable.parmDimGroupId(_dimGroup);
axInventTable.parmStandardConfigId(_revision);
axInventTable.parmReqGroupId(_coverageGroup);
axInventTable::newInventTable(_inventTable);
axInventTable.save();*/
ttsBegin;
_productMaster.clear();
_productMaster.initValue();
_productMaster.DisplayProductNumber = _itemId;
_productMaster.ProductType = _itemType;
_productMaster.SearchName = _itemName;
_productMaster.VariantConfigurationTechnology = EcoResVariantConfigurationTechnologyType::PredefinedVariants;
_productMaster.insert();
this.addRow("product created",_productMaster);
_productIdentifier.clear();
_productIdentifier.initValue();
_productIdentifier.Product = _productMaster.RecId;
_productIdentifier.ProductNumber = _itemId;
_productIdentifier.insert();
_transaltion.clear();
_transaltion.initValue();
_transaltion.Name = _itemName;
_transaltion.Product = _productMaster.RecId;
_transaltion.LanguageId = 'en-us';
_transaltion.insert();
_dimProduct.clear();
_dimProduct.initValue();
_dimProduct.Product = _productMaster.RecId;
_dimProduct.ProductDimensionGroup = _dimGroup.RecId;
_dimProduct.insert();
storageDimProduct.clear();
storageDimProduct.initValue();
storageDimProduct.Product = _productMaster.RecId;
storageDimProduct.StorageDimensionGroup = storageDimension.RecId;
storageDimProduct.insert();
trackingDimProduct.clear();
trackingDimProduct.initValue();
trackingDimProduct.Product = _productMaster.RecId;
trackingDimProduct.TrackingDimensionGroup = trackingDimension.RecId;
trackingDimProduct.insert();
releaseSession.clear();
releaseSession.initValue();
releaseSession.SystemBlocked = NoYes::No;
releaseSession.insert();
productSession.clear();
productSession.initValue();
productSession.Product = _productMaster.RecId;
productSession.ReleaseSession = releaseSession.RecId;
productSession.insert();
company = CompanyInfo::findDataArea(curext());
releaseLegalEntity.clear();
releaseLegalEntity.initValue();
releaseLegalEntity.LegalEntity = Company.RecId;
releaseLegalEntity.ReleaseSessionProduct = productSession.RecId;
releaseLegalEntity.insert();
ecoResConfigurationLocal = EcoResConfiguration::findByName(_revision);
if (!ecoResConfigurationLocal.RecId)
{
ecoResConfigurationLocal.Name = _revision;
ecoResConfigurationLocal.insert();
}
productConfig.clear();
productConfig.initValue();
productConfig.Description = 'Revision - '+ _revision;
productConfig.ConfigProductMaster = _productMaster.RecId;
productConfig.Configuration = ecoResConfigurationLocal.RecId;
productConfig.ConfigProductDimensionAttribute = 5637144576;
productConfig.insert();
dimensions = [[5637144576,ecoResConfigurationLocal.RecId]];
distinctProductVariant.clear();
distinctProductVariant.initValue();
distinctProductVariant.DisplayProductNumber = EcoResProductNumberBuilderVariant::buildFromProductNumberAndDimensions(_itemId,dimensions);
distinctProductVariant.ProductMaster = _productMaster.RecId;
distinctProductVariant.ProductType = _itemType;
distinctProductVariant.insert();
productVariantConfiguration.clear();
productVariantConfiguration.initValue();
productVariantConfiguration.Configuration = ecoResConfigurationLocal.RecId;
productVariantConfiguration.DistinctProductVariant = distinctProductVariant.RecId;
productVariantConfiguration.ProductDimensionAttribute = 5637144576;
productVariantConfiguration.ECOiD = _ECOId;
productVariantConfiguration.InvStop = NoYes::Yes;
productVariantConfiguration.POStop = NoYes::Yes;
productVariantConfiguration.SOStop = NoYes::Yes;
productVariantConfiguration.insert();
productVariantTranslation.clear();
productVariantTranslation.initValue();
productVariantTranslation.Name = _itemName;
productVariantTranslation.Product = distinctProductVariant.RecId;
productVariantTranslation.LanguageId = 'en-us';
productVariantTranslation.insert();
this.addRow("Revision created",productVariantConfiguration);
productSessionVariant.clear();
productSessionVariant.initValue();
productSessionVariant.Product = distinctProductVariant.RecId;
productSessionVariant.ReleaseSession = releaseSession.RecId;
productSessionVariant.insert();
releaseLegalEntityVariant.clear();
releaseLegalEntityVariant.initValue();
releaseLegalEntityVariant.LegalEntity = Company.RecId;
releaseLegalEntityVariant.ReleaseSessionProduct = productSessionVariant.RecId;
releaseLegalEntityVariant.insert();
ttsCommit;
//EcoResProductReleaseSessionBatch productReleaseSessionBatch = EcoResProductReleaseSessionBatch::construct();
productReleaseSessionBatch.getLast();
productReleaseSessionBatch.parmReleaseSessionRecId(releaseSession.RecId);
productReleaseSessionBatch.initParmDefault();
productReleaseSessionBatch.init();
productReleaseSessionBatch.run();
}
Exelente!!
回复删除