Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Mindee/Parsing/Common/AmountField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,13 @@ public class AmountField : BaseField
/// <example>5.89</example>
[JsonPropertyName("value")]
public double? Value { get; set; }

/// <summary>
/// A pretty summary of the value.
/// </summary>
public override string ToString()
{
return Value?.ToString("0.00");
}
}
}
10 changes: 8 additions & 2 deletions src/Mindee/Parsing/Invoice/InvoiceV3Prediction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,17 @@ public sealed class InvoiceV3Prediction : FinancialPredictionBase
[JsonPropertyName("total_excl")]
public AmountField TotalExcl { get; set; }

/// <summary>
/// The total amount of taxes.
/// </summary>
public double? TotalTaxes => Taxes?.Sum(t => t.Value);

/// <summary>
/// A prettier reprensentation of the current model values.
/// </summary>
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");
Expand All @@ -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();
}
Expand Down
6 changes: 6 additions & 0 deletions src/Mindee/Parsing/Invoice/InvoiceV4Prediction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public sealed class InvoiceV4Prediction : FinancialPredictionBase
[JsonPropertyName("line_items")]
public List<InvoiceLineItem> LineItems { get; set; }

/// <summary>
/// The total amount of taxes.
/// </summary>
public double? TotalTaxes => Taxes?.Sum(t => t.Value);

/// <summary>
/// A prettier reprensentation of the current model values.
/// </summary>
Expand Down Expand Up @@ -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("----------------------");
Expand Down
9 changes: 9 additions & 0 deletions tests/Mindee.UnitTests/Parsing/Invoice/InvoiceV3Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<InvoiceV4Prediction>(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);
Expand Down
20 changes: 9 additions & 11 deletions tests/Mindee.UnitTests/Parsing/Invoice/InvoiceV4Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<InvoiceV4Prediction>(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()
{
Expand Down Expand Up @@ -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<InvoiceV4Prediction>(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);
Expand Down