Beispiel #1
0
        private int RunStockItemImport(AcumaticaStockItemImportContext context, ShopifyVariant variant)
        {
            var matchingShopifySkus = _syncRepository.RetrieveNonMissingVariants(variant.StandardizedSku());

            if (matchingShopifySkus.Count > 1)
            {
                _logService.Log($"Stock Item Import: {variant.LogDescriptor()} has duplicates in Shopify - aborting");
                return(StockItemPutResult.NoAction);
            }

            // Attempt to Auto-match
            //
            if (variant.IsMatched())
            {
                _logService.Log($"Stock Item Import: {variant.LogDescriptor()} already matched - aborting");
                return(StockItemPutResult.NoAction);
            }

            var stockItem = _syncRepository.RetrieveStockItem(variant.StandardizedSku());

            if (stockItem != null)
            {
                if (stockItem.IsMatched())
                {
                    var msg = $"Stock Item Import: {variant.LogDescriptor()} SKU already synchronized";
                    _logService.Log(msg);
                    return(StockItemPutResult.NoAction);
                }
                else
                {
                    var msg = $"Stock Item Import: auto-matched {stockItem.LogDescriptor()} to {variant.LogDescriptor()}";
                    _logService.Log(msg);

                    _syncRepository.InsertItemSync(variant, stockItem, context.IsSyncEnabled);
                    return(StockItemPutResult.Synchronized);
                }
            }

            // Abort any further processing
            if (context.SynchronizeOnly == true)
            {
                return(StockItemPutResult.NoAction);
            }


            // With neither duplicates or Auto-matching having succeeded,
            // ... we'll create a new Stock Item in Acumatica
            //
            StockItemPush(context, variant);
            context.VariantsForNextInventoryReceipt.Add(variant);
            return(StockItemPutResult.CreatedStockItem);
        }
Beispiel #2
0
        private StockItem BuildNewStockItem(string warehouseId, ShopifyVariant variant)
        {
            var settings            = _settingsRepository.RetrieveSettings();
            var defaultItemClass    = settings.AcumaticaDefaultItemClass;
            var defaultPostingClass = settings.AcumaticaDefaultPostingClass;

            var defaultTaxCategory = variant.ShopifyIsTaxable.TaxCategory(settings);
            var shopifyVariant     = _shopifyJsonService.RetrieveVariant(variant.ShopifyVariantId);
            var shopifyProduct     = _shopifyJsonService.RetrieveProduct(variant.ShopifyProduct.ShopifyProductId);

            var newStockItem = new StockItem();

            newStockItem.InventoryID = variant.StandardizedSku().ToValue();
            newStockItem.Description
                = Canonizers.StandardizedStockItemTitle(shopifyProduct, shopifyVariant).ToValue();

            newStockItem.DefaultPrice       = ((double)shopifyVariant.price).ToValue();
            newStockItem.DefaultWarehouseID = warehouseId.ToValue();

            var dimensionWeight = (double)shopifyVariant.grams.ToAcumaticaOunces();

            // newStockItem.WeightUOM = WeightCalc.AcumaticaUnitsOfMeasure.ToValue();
            newStockItem.DimensionWeight = dimensionWeight.ToValue();
            newStockItem.ItemClass       = defaultItemClass.ToValue();
            newStockItem.PostingClass    = defaultPostingClass.ToValue();
            newStockItem.TaxCategory     = defaultTaxCategory.ToValue();

            return(newStockItem);
        }