using System.Linq; using Centron.BusinessLogic; using Centron.BusinessLogic.Logistics.LogisticSettings; using Centron.BusinessLogic.Sales.Receipts.DataAndResults; using Centron.BusinessLogic.WebServices.Sales.Receipts; using Centron.BusinessLogic.WebServices.Sales.Receipts.DataAndResults; using Centron.Data.WebServices.Sales.Receipts; using Centron.Data.WebServices.Sales.Receipts.Offers; using Centron.Interfaces; using Centron.Interfaces.Administration.Environment; using Centron.Interfaces.BL; using Centron.Tests.EndToEnd.Infrastructure; using CentronSoftware.Centron.WebServices.Extensions; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.TicketTests.Ticket122697 { public class Ticket122697Tests : EndToEndTest { public Ticket122697Tests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } const int CustomerI3D = 10006; const int ArticleI3D = 4343; const int WarehouseI3D = 7; //The article 4343 is not available in warehouse 7 public override void Execute() { // An error was shown when creating a offer with an article that is currently not available in the position-warehouse // That's a bit misleading, because offers don't book any articles, so the warehouse shouldn't be checked this.SetupDatabase(); this.ExecuteTestForReceiptKind(CentronObjectKindNumeric.OfferClass); this.ExecuteTestForReceiptKind(CentronObjectKindNumeric.InvoiceClass); } private void ExecuteTestForReceiptKind(CentronObjectKindNumeric receiptKind) { var receipt = this.GetReceipt(CustomerI3D, receiptKind, ArticleI3D, WarehouseI3D); var saveResult = this.SaveReceipt(receipt); this.Verifier.Verify($"SaveResult_{receiptKind}", saveResult); } private void SetupDatabase() { // Deactivate that articles are automatically added to warehouses using var session = new BLSession(); var settings = session.GetBL().GetSettings(); settings.AutoNewSecondstockArticle = false; session.GetBL().UpdateSettings(settings); } private Result SaveReceipt(ReceiptBaseDTO receipt) { using var session = new BLSession(); var saveResult = session.GetBL().SaveReceipt( receipt, this.GetLoggedInUser().User, new SaveReceiptData { IgnoreCallbacks = true }, autoLockIfNewReceipt: false, application: CreatedThroughApplication.CentronNet, receiptTemplateFolderI3D: null); return saveResult; } private ReceiptBaseDTO GetReceipt(int customerI3D, CentronObjectKindNumeric receiptKind, int articleI3D, int warehouseI3D) { using var session = new BLSession(); var newReceiptResult = session.GetBL().CreateNewReceipt( receiptKind, this.GetLoggedInUser(), customerI3D, new CreateReceiptData { IgnoreCallbacks = true }, addressI3D:null, contactPersonI3D:null, insertSalutationAndAgreement:false, ignoreDefaultContract:false, insertCustomerDiscount:false); var newReceipt = newReceiptResult.Data.Receipt; var articleItemsResult = session.GetBL().CreateArticleReceiptItems( newReceipt, isExternalArticle: false, articleI3D, externalArticleKind: null, externalArticleId: null, warehouseI3D, this.GetLoggedInUser()); var items = newReceipt.GetReceiptItems().ToList(); items.AddRange(articleItemsResult.Data.ReceiptItems.ToList()); newReceipt.SetReceiptItems(items); return newReceipt; } } }