From 2ea0b513ccbce7c8ba5e8174da786f4bec0fe5f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Krupi=C5=84ski?= Date: Mon, 7 Oct 2024 11:55:32 +0200 Subject: [PATCH] Missing EPrint action in Invoice Connector (#301) * Added missing EPrint action to InvoiceConnector * EPrint returns Invoices not PDF * Fix Invoice Print tests Added/updated tests had errors --------- Co-authored-by: adamelfstrom <105274564+adamelfstrom@users.noreply.github.com> --- .../ConnectorTests/InvoiceTests.cs | 48 +++++++++++++++++-- FortnoxSDK/Action.cs | 2 +- FortnoxSDK/Connectors/InvoiceConnector.cs | 5 ++ FortnoxSDK/Interfaces/IInvoiceConnector.cs | 1 + 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/FortnoxSDK.Tests/ConnectorTests/InvoiceTests.cs b/FortnoxSDK.Tests/ConnectorTests/InvoiceTests.cs index 7a340411..3d97e6cd 100644 --- a/FortnoxSDK.Tests/ConnectorTests/InvoiceTests.cs +++ b/FortnoxSDK.Tests/ConnectorTests/InvoiceTests.cs @@ -185,13 +185,55 @@ public async Task Test_DueDate() #endregion Delete arranged resources } + [TestMethod] + [Ignore("Fails with error 'Kan inte skicka dokument om inte företaget är registrerat'")] + public async Task Test_EPrint() + { + #region Arrange + var cc = FortnoxClient.CustomerConnector; + var ac = FortnoxClient.ArticleConnector; + var tmpCustomer = await cc.CreateAsync(new Customer() { Name = "TmpCustomer", CountryCode = "SE", City = "Testopolis", Email = "test@test.test" }); + var tmpArticle = await ac.CreateAsync(new Article() { Description = "TmpArticle", Type = ArticleType.Stock, PurchasePrice = 100 }); + #endregion Arrange + + var connector = FortnoxClient.InvoiceConnector; + + var newInvoice = new Invoice() + { + CustomerNumber = tmpCustomer.CustomerNumber, + InvoiceDate = new DateTime(2019, 1, 20), //"2019-01-20", + DueDate = new DateTime(2019, 2, 20), //"2019-02-20", + InvoiceType = InvoiceType.CashInvoice, + PaymentWay = PaymentWay.Cash, + Comments = "TestInvoice", + InvoiceRows = new List() + { + new InvoiceRow(){ ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 10, Price = 100}, + new InvoiceRow(){ ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 20, Price = 100}, + new InvoiceRow(){ ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 15, Price = 100} + } + }; + + var createdInvoice = await connector.CreateAsync(newInvoice); + + var printedInvoice = await connector.EPrintAsync(createdInvoice.DocumentNumber); + Assert.AreEqual(printedInvoice.DocumentNumber, createdInvoice.DocumentNumber); + + await connector.CancelAsync(createdInvoice.DocumentNumber); + + #region Delete arranged resources + await FortnoxClient.CustomerConnector.DeleteAsync(tmpCustomer.CustomerNumber); + // await FortnoxClient.ArticleConnector.DeleteAsync(tmpArticle.ArticleNumber); + #endregion Delete arranged resources + } + [TestMethod] public async Task Test_Print() { #region Arrange var cc = FortnoxClient.CustomerConnector; var ac = FortnoxClient.ArticleConnector; - var tmpCustomer = await cc.CreateAsync(new Customer() { Name = "TmpCustomer", CountryCode = "SE", City = "Testopolis" }); + var tmpCustomer = await cc.CreateAsync(new Customer() { Name = "TmpCustomer", CountryCode = "SE", City = "Testopolis", Email = "test@test.test" }); var tmpArticle = await ac.CreateAsync(new Article() { Description = "TmpArticle", Type = ArticleType.Stock, PurchasePrice = 100 }); #endregion Arrange @@ -222,7 +264,7 @@ public async Task Test_Print() #region Delete arranged resources await FortnoxClient.CustomerConnector.DeleteAsync(tmpCustomer.CustomerNumber); - //FortnoxClient.ArticleConnector.Delete(tmpArticle.ArticleNumber); + //await FortnoxClient.ArticleConnector.DeleteAsync(tmpArticle.ArticleNumber); #endregion Delete arranged resources } @@ -261,7 +303,7 @@ public async Task Test_Email() #region Delete arranged resources await FortnoxClient.CustomerConnector.DeleteAsync(tmpCustomer.CustomerNumber); - //FortnoxClient.ArticleConnector.Delete(tmpArticle.ArticleNumber); + //await FortnoxClient.ArticleConnector.DeleteAsync(tmpArticle.ArticleNumber); #endregion Delete arranged resources } diff --git a/FortnoxSDK/Action.cs b/FortnoxSDK/Action.cs index f6f0f3bb..18f09b57 100644 --- a/FortnoxSDK/Action.cs +++ b/FortnoxSDK/Action.cs @@ -66,7 +66,6 @@ public static bool IsDownloadAction(this Action action) case Action.Print: case Action.PrintReminder: case Action.Preview: - case Action.EPrint: return true; default: return false; @@ -81,6 +80,7 @@ public static HttpMethod GetMethod(this Action action) return HttpMethod.Put; case Action.Email: case Action.EInvoice: + case Action.EPrint: return HttpMethod.Get; default: return HttpMethod.Put; diff --git a/FortnoxSDK/Connectors/InvoiceConnector.cs b/FortnoxSDK/Connectors/InvoiceConnector.cs index e9e4765d..ff57a0a9 100644 --- a/FortnoxSDK/Connectors/InvoiceConnector.cs +++ b/FortnoxSDK/Connectors/InvoiceConnector.cs @@ -58,6 +58,11 @@ public async Task EInvoiceAsync(long? id) return await DoActionAsync(id.ToString(), Action.EInvoice).ConfigureAwait(false); } + public async Task EPrintAsync(long? id) + { + return await DoActionAsync(id.ToString(), Action.EPrint).ConfigureAwait(false); + } + public async Task PrintAsync(long? id) { return await DoDownloadActionAsync(id.ToString(), Action.Print).ConfigureAwait(false); diff --git a/FortnoxSDK/Interfaces/IInvoiceConnector.cs b/FortnoxSDK/Interfaces/IInvoiceConnector.cs index e54db166..5ab2368a 100644 --- a/FortnoxSDK/Interfaces/IInvoiceConnector.cs +++ b/FortnoxSDK/Interfaces/IInvoiceConnector.cs @@ -18,6 +18,7 @@ public interface IInvoiceConnector : IEntityConnector Task CreditInvoiceAsync(long? id); Task EmailAsync(long? id); Task EInvoiceAsync(long? id); + Task EPrintAsync(long? id); Task PrintAsync(long? id); Task PrintReminderAsync(long? id); Task ExternalPrintAsync(long? id);