Exemplo n.º 1
0
        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();
            }
        }