public BuildComboItemResult Build(int comboItemUid, decimal quantity) { TasksRunner tasksRunner = new TasksRunner(this.WSAccessKey, this.FileUid); tasksRunner.Tasks.Add(new BuildComboItemTask(comboItemUid, quantity)); TasksResponse response = tasksRunner.Execute(); this.CheckErrors(response.Errors); BuildComboItemResult buildResponse = (BuildComboItemResult)response.Results[0]; return(buildResponse); }
public void BuildComboItemFailsWithNotEnoughtStock() { ComboItemProxy proxy = new ComboItemProxy(); ComboItemDto comboItemDto = this.GetComboItem01(); proxy.Insert(comboItemDto); ComboItemDto comboItem = (ComboItemDto)proxy.GetByUid(comboItemDto.Uid); BuildComboItemResult result = proxy.Build(comboItemDto.Uid, 1000); Assert.AreEqual(1, result.Errors.Count); ErrorInfo error = (ErrorInfo)result.Errors[0]; Assert.AreEqual("InvalidInventoryItemStockOnHandException", error.Type); StringAssert.StartsWith("Unable to complete the requested operation as it will cause negative stock-on-hand for ", error.Message); }
public void BuildComboItem() { ComboItemProxy proxy = new ComboItemProxy(); ComboItemDto comboItemDto = this.GetComboItem01(); proxy.Insert(comboItemDto); ComboItemDto comboItem = (ComboItemDto)proxy.GetByUid(comboItemDto.Uid); // We need to insert stock first using a purchase CrudProxy invoiceProxy = new InvoiceProxy(); InvoiceDto dto = new InvoiceDto(TransactionType.Purchase, InvoiceLayout.Item); dto.Date = DateTime.Today.Date; dto.ContactUid = this.MrSmith.Uid; dto.Summary = "Add stock do we can build ComboItems"; dto.Notes = "From REST"; dto.DueOrExpiryDate = dto.Date.AddMonths(1); dto.Status = InvoiceStatus.Invoice; dto.InvoiceNumber = "I123"; dto.PurchaseOrderNumber = "<Auto Number>"; decimal unitsToBuild = 12.25M; foreach (ComboItemLineItemDto itemInCombo in comboItem.Items) { // "purchase" all the items that are part of this combo item so we have valid stock ItemInvoiceItemDto item = new ItemInvoiceItemDto(); item.Quantity = itemInCombo.Quantity * unitsToBuild; item.InventoryItemUid = itemInCombo.Uid; item.Description = "Purchasing: " + itemInCombo.Code; item.TaxCode = TaxCode.ExpInclGst; item.UnitPriceInclTax = 99.95M; dto.Items.Add(item); } invoiceProxy.Insert(dto); // Download stock info before InventoryItemProxy inventoryItemProxy = new InventoryItemProxy(); InventoryItemDto inventoryItem = (InventoryItemDto)inventoryItemProxy.GetByUid(comboItemDto.Uid); decimal stockOnHand = inventoryItem.StockOnHand; // Build the item! BuildComboItemResult result = proxy.Build(comboItemDto.Uid, unitsToBuild); Assert.AreNotEqual(0, result.Uid); Assert.IsNotNull(result.LastUpdatedUid); inventoryItem = (InventoryItemDto)inventoryItemProxy.GetByUid(comboItemDto.Uid); decimal newStockOnHand = inventoryItem.StockOnHand; Assert.AreEqual(stockOnHand + unitsToBuild, newStockOnHand, "We have one extra item in stock"); // Read Inventory Transfer details InventoryTransferProxy transferProxy = new InventoryTransferProxy(); InventoryTransferDto transfer = (InventoryTransferDto)transferProxy.GetByUid(result.Uid); Assert.AreEqual(comboItem.Items.Count + 1, transfer.Items.Count); // +1 as we have the combo item the first one // confirm first item is the combo with +1 InventoryTransferItemDto comboItemTransfer = (InventoryTransferItemDto)transfer.Items[0]; Assert.AreEqual(comboItemDto.Uid, comboItemTransfer.InventoryItemUid); Assert.AreEqual(unitsToBuild, comboItemTransfer.Quantity); for (int i = 0; i < comboItem.Items.Count; i++) { ComboItemLineItemDto line = comboItem.Items[i]; InventoryTransferItemDto item = (InventoryTransferItemDto)transfer.Items[i + 1]; Assert.AreEqual(line.Uid, item.InventoryItemUid); Assert.AreEqual(line.Quantity * unitsToBuild, -item.Quantity); } }