diff --git a/src/Mindee/Parsing/Common/AmountField.cs b/src/Mindee/Parsing/Common/AmountField.cs index d3f52d5e..720db80a 100644 --- a/src/Mindee/Parsing/Common/AmountField.cs +++ b/src/Mindee/Parsing/Common/AmountField.cs @@ -13,5 +13,13 @@ public class AmountField : BaseField /// 5.89 [JsonPropertyName("value")] public double? Value { get; set; } + + /// + /// A pretty summary of the value. + /// + public override string ToString() + { + return Value?.ToString("0.00"); + } } } diff --git a/src/Mindee/Parsing/Invoice/InvoiceV3Prediction.cs b/src/Mindee/Parsing/Invoice/InvoiceV3Prediction.cs index dfa4ad9b..4e0cb6dc 100644 --- a/src/Mindee/Parsing/Invoice/InvoiceV3Prediction.cs +++ b/src/Mindee/Parsing/Invoice/InvoiceV3Prediction.cs @@ -78,12 +78,17 @@ public sealed class InvoiceV3Prediction : FinancialPredictionBase [JsonPropertyName("total_excl")] public AmountField TotalExcl { get; set; } + /// + /// The total amount of taxes. + /// + public double? TotalTaxes => Taxes?.Sum(t => t.Value); + /// /// A prettier reprensentation of the current model values. /// public override string ToString() { - StringBuilder result = new StringBuilder("-----Invoice data-----\n"); + StringBuilder result = new StringBuilder("----- Invoice V3 -----\n"); result.Append($"Invoice number: {InvoiceNumber.Value}\n"); result.Append($"Total amount including taxes: {TotalIncl.Value}\n"); result.Append($"Total amount excluding taxes: {TotalExcl.Value}\n"); @@ -97,9 +102,10 @@ public override string ToString() result.Append($"Payment details: {string.Join("\n ", PaymentDetails.Select(p => p))}\n"); result.Append($"Company numbers: {string.Join("\n ", CompanyRegistrations.Select(c => c.Value))}\n"); result.Append($"Taxes: {string.Join("\n ", Taxes.Select(t => t))}\n"); + result.Append($"Total taxes: {TotalTaxes}\n"); result.Append($"Locale: {Locale}\n"); - result.Append("----------------------"); + result.Append("----------------------\n"); return result.ToString(); } diff --git a/src/Mindee/Parsing/Invoice/InvoiceV4Prediction.cs b/src/Mindee/Parsing/Invoice/InvoiceV4Prediction.cs index dcef4cab..7435bd09 100644 --- a/src/Mindee/Parsing/Invoice/InvoiceV4Prediction.cs +++ b/src/Mindee/Parsing/Invoice/InvoiceV4Prediction.cs @@ -84,6 +84,11 @@ public sealed class InvoiceV4Prediction : FinancialPredictionBase [JsonPropertyName("line_items")] public List LineItems { get; set; } + /// + /// The total amount of taxes. + /// + public double? TotalTaxes => Taxes?.Sum(t => t.Value); + /// /// A prettier reprensentation of the current model values. /// @@ -111,6 +116,7 @@ public override string ToString() result.Append($"Customer address: {string.Join("; ", CustomerAddress.Value)}\n"); result.Append($"Taxes: {string.Join("\n ", Taxes.Select(t => t))}\n"); result.Append($"Line items: {lineItems}\n"); + result.Append($"Total taxes: {TotalTaxes}\n"); result.Append($"Total amount including taxes: {TotalAmount.Value}\n"); result.Append($"Total amount excluding taxes: {TotalNet.Value}\n"); result.Append("----------------------"); diff --git a/tests/Mindee.UnitTests/Parsing/Invoice/InvoiceV3Test.cs b/tests/Mindee.UnitTests/Parsing/Invoice/InvoiceV3Test.cs index f6d9d2c1..cfc45866 100644 --- a/tests/Mindee.UnitTests/Parsing/Invoice/InvoiceV3Test.cs +++ b/tests/Mindee.UnitTests/Parsing/Invoice/InvoiceV3Test.cs @@ -97,6 +97,15 @@ public async Task Predict_MustSuccessForOcr() Assert.Equal("Payment", invoicePrediction.Ocr.MvisionV1.Pages.First().AllWords.First().Text); } + [Fact] + public async Task Predict_MustSuccessForTotalTaxes() + { + var mindeeAPi = GetMindeeApiForInvoice(); + var invoicePrediction = await mindeeAPi.PredictAsync(ParsingTestBase.GetFakePredictParameter()); + + Assert.Equal(97.98, invoicePrediction.Inference.Pages.First().Prediction.TotalTaxes); + } + private MindeeApi GetMindeeApiForInvoice(string fileName = "Resources/invoice/response_v3/complete.json") { return ParsingTestBase.GetMindeeApi(fileName); diff --git a/tests/Mindee.UnitTests/Parsing/Invoice/InvoiceV4Test.cs b/tests/Mindee.UnitTests/Parsing/Invoice/InvoiceV4Test.cs index 6893864d..7f2c44d4 100644 --- a/tests/Mindee.UnitTests/Parsing/Invoice/InvoiceV4Test.cs +++ b/tests/Mindee.UnitTests/Parsing/Invoice/InvoiceV4Test.cs @@ -6,17 +6,6 @@ namespace Mindee.UnitTests.Parsing.Invoice [Trait("Category", "Invoice V4")] public class InvoiceV4Test { - [Fact(Skip = "Waiting for the summary format update.")] - public async Task Predict_MustSuccess() - { - var mindeeAPi = GetMindeeApiForInvoice(); - var invoicePrediction = await mindeeAPi.PredictAsync(ParsingTestBase.GetFakePredictParameter()); - - var expected = File.ReadAllText("Resources/invoice/response_v4/doc_to_string.txt"); - - Assert.Equal(expected, invoicePrediction.ToString()); - } - [Fact] public async Task Predict_MustSuccessForInvoiceNumber() { @@ -190,6 +179,15 @@ public async Task Predict_MustSuccessForOrientation() Assert.Equal(0, invoicePrediction.Inference.Pages.First().Orientation.Value); } + [Fact] + public async Task Predict_MustSuccessForTotalTaxes() + { + var mindeeAPi = GetMindeeApiForInvoice(); + var invoicePrediction = await mindeeAPi.PredictAsync(ParsingTestBase.GetFakePredictParameter()); + + Assert.Equal(97.98, invoicePrediction.Inference.Pages.First().Prediction.TotalTaxes); + } + private MindeeApi GetMindeeApiForInvoice(string fileName = "Resources/invoice/response_v4/complete.json") { return ParsingTestBase.GetMindeeApi(fileName);