public void ImportAcumaticaStockItems(AcumaticaStockItemImportContext context) { _acumaticaContext.SessionRun(() => { _acumaticaInventorySync.RunImportToAcumatica(context); }); }
public void RunImportToAcumatica(AcumaticaStockItemImportContext context) { foreach (var shopifyProductId in context.ShopifyProductIds) { if (_jobMonitoringService.DetectCurrentJobInterrupt()) { return; } var variants = _syncRepository.RetrieveUnmatchedVariants(shopifyProductId); var variantsForReceipt = new List <ShopifyVariant>(); foreach (var variant in variants) { var result = RunStockItemImport(context, variant); if (result == StockItemPutResult.CreatedStockItem && context.CreateInventoryReceipts) { variantsForReceipt.Add(variant); } } if (context.CreateInventoryReceipts) { RunInventoryReceiptImport( context.WarehouseId, shopifyProductId, variantsForReceipt); } } }
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); }
public void SyncAcumaticaStockItems(List <long> spids, bool automaticEnable) { var context = new AcumaticaStockItemImportContext { ShopifyProductIds = spids, IsSyncEnabled = automaticEnable, CreateInventoryReceipts = false, SynchronizeOnly = true, WarehouseId = null, }; var monitor = _monitoringService.ProvisionMonitor(BackgroundJobType.ImportAcumaticaStockItems); var hangfireJobId = BackgroundJob.Enqueue <JobRunner>( x => x.ImportAcumaticaStockItems(_tenantContext.InstanceId, context, monitor.Id)); _monitoringService.AssignHangfireJob(monitor.Id, hangfireJobId); }
public void ImportAcumaticaStockItems(AcumaticaStockItemImportContext context) { Action action = () => { RefreshInventory(); var state = _stateRepository.RetrieveSystemStateNoTracking(); if (state.InventoryRefreshState != StateCode.Ok) { _executionLogService.Log("Inventory Refresh is broken; aborting ImportAcumaticaStockItems"); return; } _syncManager.ImportAcumaticaStockItems(context); }; Run(action); }
public void StockItemPush(AcumaticaStockItemImportContext context, ShopifyVariant variant) { _logService.Log(LogBuilder.CreateStockItem(variant)); var newStockItem = BuildNewStockItem(context.WarehouseId, variant); var newStockItemJson = newStockItem.SerializeToJson(); // Push to Acumatica API // var result = _distributionClient.AddNewStockItem(newStockItemJson); var item = result.DeserializeFromJson <StockItem>(); // Create Monster record // var newRecord = new AcumaticaStockItem(); newRecord.ItemId = item.InventoryID.value; _acumaticaJsonService.Upsert( AcumaticaJsonType.StockItem, item.InventoryID.value, item.SerializeToJson()); newRecord.AcumaticaDescription = item.Description.value; newRecord.AcumaticaTaxCategory = item.TaxCategory.value; newRecord.IsVariantSynced = false; newRecord.DateCreated = DateTime.UtcNow; newRecord.LastUpdated = DateTime.UtcNow; using (var transaction = _syncRepository.BeginTransaction()) { _inventoryRepository.InsertStockItems(newRecord); _syncRepository.InsertItemSync(variant, newRecord, context.IsSyncEnabled); var log = $"Created Stock Item {item.InventoryID.value} in Acumatica"; _logService.Log(log); transaction.Commit(); } }
public void SyncWithAcumaticaStockItems( Guid instanceId, AcumaticaStockItemImportContext context, long jobMonitorId) { ExecuteJob(instanceId, () => _processDirector.ImportAcumaticaStockItems(context), jobMonitorId); }