Skip to content

Commit 0674aab

Browse files
authored
✨ update Invoice to v4.5 (#153)
1 parent f5ff3c8 commit 0674aab

5 files changed

Lines changed: 78 additions & 60 deletions

File tree

docs/code_samples/invoices_v4.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class SimpleMindeeClient {
1515
MindeeClient mindeeClient = new MindeeClient(apiKey);
1616

1717
// Load a file from disk
18-
LocalInputSource inputSource = new LocalInputSource(new File(filePath));
18+
LocalInputSource inputSource = new LocalInputSource(filePath);
1919

2020
// Parse the file
2121
PredictResponse<InvoiceV4> response = mindeeClient.parse(

src/main/java/com/mindee/product/invoice/InvoiceV4Document.java

Lines changed: 65 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
import com.mindee.parsing.standard.LocaleField;
1313
import com.mindee.parsing.standard.PaymentDetailsField;
1414
import com.mindee.parsing.standard.StringField;
15-
import com.mindee.parsing.standard.TaxField;
15+
import com.mindee.parsing.standard.Taxes;
1616
import com.mindee.parsing.standard.TaxesDeserializer;
17+
import java.util.ArrayList;
1718
import java.util.List;
1819
import lombok.EqualsAndHashCode;
1920
import lombok.Getter;
@@ -27,83 +28,98 @@
2728
public class InvoiceV4Document extends Prediction {
2829

2930
/**
30-
* Locale information.
31+
* The customer's address used for billing.
3132
*/
32-
@JsonProperty("locale")
33-
private LocaleField localeField;
33+
@JsonProperty("billing_address")
34+
private StringField billingAddress;
3435
/**
35-
* The type of the parsed document (see official documentation for the list).
36+
* The address of the customer.
3637
*/
37-
@JsonProperty("document_type")
38-
private ClassificationField documentType;
38+
@JsonProperty("customer_address")
39+
private StringField customerAddress;
3940
/**
40-
* The creation date of the invoice.
41+
* List of company registrations associated to the customer.
4142
*/
42-
@JsonProperty("date")
43-
private DateField invoiceDateField;
43+
@JsonProperty("customer_company_registrations")
44+
private List<CompanyRegistrationField> customerCompanyRegistrations = new ArrayList<>();
4445
/**
45-
* The invoice number.
46+
* The name of the customer or client.
4647
*/
47-
@JsonProperty("invoice_number")
48-
private StringField invoiceNumber;
48+
@JsonProperty("customer_name")
49+
private StringField customerName;
4950
/**
50-
* List of Reference numbers including PO number.
51+
* The date the purchase was made.
5152
*/
52-
@JsonProperty("reference_numbers")
53-
private List<StringField> referenceNumbers;
53+
@JsonProperty("date")
54+
private DateField invoiceDateField;
55+
/**
56+
* One of: 'INVOICE', 'CREDIT NOTE'.
57+
*/
58+
@JsonProperty("document_type")
59+
private ClassificationField documentType;
5460
/**
55-
* The due date of the invoice.
61+
* The date on which the payment is due.
5662
*/
5763
@JsonProperty("due_date")
5864
private DateField dueDateField;
5965
/**
60-
* The supplier name.
66+
* The invoice number or identifier.
6167
*/
62-
@JsonProperty("supplier_name")
63-
private StringField supplierName;
68+
@JsonProperty("invoice_number")
69+
private StringField invoiceNumber;
6470
/**
65-
* The supplier payment information's.
71+
* List of line item details.
6672
*/
67-
@JsonProperty("supplier_payment_details")
68-
private List<PaymentDetailsField> supplierPaymentDetails;
73+
@JsonProperty("line_items")
74+
private List<InvoiceV4LineItem> lineItems = new ArrayList<>();
6975
/**
70-
* The supplier company regitration information.
76+
* The locale detected on the document.
7177
*/
72-
@JsonProperty("supplier_company_registrations")
73-
private List<CompanyRegistrationField> supplierCompanyRegistrations;
78+
@JsonProperty("locale")
79+
private LocaleField localeField;
7480
/**
75-
* The supplier address.
81+
* List of Reference numbers, including PO number.
82+
*/
83+
@JsonProperty("reference_numbers")
84+
private List<StringField> referenceNumbers = new ArrayList<>();
85+
/**
86+
* Customer's delivery address.
87+
*/
88+
@JsonProperty("shipping_address")
89+
private StringField shippingAddress;
90+
/**
91+
* The address of the supplier or merchant.
7692
*/
7793
@JsonProperty("supplier_address")
7894
private StringField supplierAddress;
7995
/**
80-
* The name of the customer.
96+
* List of company registrations associated to the supplier.
8197
*/
82-
@JsonProperty("customer_name")
83-
private StringField customerName;
98+
@JsonProperty("supplier_company_registrations")
99+
private List<CompanyRegistrationField> supplierCompanyRegistrations = new ArrayList<>();
84100
/**
85-
* The company registration information for the customer.
101+
* The name of the supplier or merchant.
86102
*/
87-
@JsonProperty("customer_company_registrations")
88-
private List<CompanyRegistrationField> customerCompanyRegistrations;
103+
@JsonProperty("supplier_name")
104+
private StringField supplierName;
89105
/**
90-
* The address of the customer.
106+
* List of payment details associated to the supplier.
91107
*/
92-
@JsonProperty("customer_address")
93-
private StringField customerAddress;
108+
@JsonProperty("supplier_payment_details")
109+
private List<PaymentDetailsField> supplierPaymentDetails = new ArrayList<>();
94110
/**
95-
* The list of the taxes.
111+
* List of tax line details.
96112
*/
97113
@JsonProperty("taxes")
98114
@JsonDeserialize(using = TaxesDeserializer.class)
99-
private List<TaxField> taxes;
115+
private Taxes taxes;
100116
/**
101-
* The total amount with tax included.
117+
* The total amount paid: includes taxes, tips, fees, and other charges.
102118
*/
103119
@JsonProperty("total_amount")
104120
private AmountField totalAmount;
105121
/**
106-
* The total amount without the tax value.
122+
* The net amount paid: does not include taxes, fees, and discounts.
107123
*/
108124
@JsonProperty("total_net")
109125
private AmountField totalNet;
@@ -112,12 +128,8 @@ public class InvoiceV4Document extends Prediction {
112128
*/
113129
@JsonProperty("total_tax")
114130
private AmountField totalTax;
115-
/**
116-
* Line items details.
117-
*/
118-
@JsonProperty("line_items")
119-
private List<InvoiceV4LineItem> lineItems;
120131

132+
@Override
121133
public boolean isEmpty() {
122134
return (
123135
this.localeField == null
@@ -136,6 +148,8 @@ public boolean isEmpty() {
136148
&& this.customerName == null
137149
&& (this.customerCompanyRegistrations == null || this.customerCompanyRegistrations.isEmpty())
138150
&& this.customerAddress == null
151+
&& this.shippingAddress == null
152+
&& this.billingAddress == null
139153
&& this.documentType == null
140154
&& (this.lineItems == null || this.lineItems.isEmpty())
141155
);
@@ -208,6 +222,12 @@ public String toString() {
208222
outStr.append(
209223
String.format(":Customer Address: %s%n", this.getCustomerAddress())
210224
);
225+
outStr.append(
226+
String.format(":Shipping Address: %s%n", this.getShippingAddress())
227+
);
228+
outStr.append(
229+
String.format(":Billing Address: %s%n", this.getBillingAddress())
230+
);
211231
outStr.append(
212232
String.format(":Document Type: %s%n", this.getDocumentType())
213233
);

src/main/java/com/mindee/product/invoice/InvoiceV4LineItem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private Map<String, String> printableValues() {
8686
descriptionSummary = descriptionSummary.substring(0, 33) + "...";
8787
}
8888
printable.put("description", descriptionSummary);
89-
printable.put("productCode", SummaryHelper.formatString(this.productCode));
89+
printable.put("productCode", SummaryHelper.formatForDisplay(this.productCode, null));
9090
printable.put(
9191
"quantity",
9292
SummaryHelper.formatAmount(this.quantity)

src/test/java/com/mindee/product/invoice/InvoiceV4Test.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
import com.fasterxml.jackson.databind.ObjectMapper;
55
import com.mindee.parsing.common.Document;
66
import com.mindee.parsing.common.PredictResponse;
7+
import com.mindee.parsing.standard.ClassificationField;
8+
import com.mindee.product.ProductTestHelper;
79
import org.junit.jupiter.api.Assertions;
810
import org.junit.jupiter.api.Test;
911
import java.io.File;
1012
import java.io.IOException;
11-
import java.nio.file.Files;
12-
import java.nio.file.Paths;
13-
import java.util.List;
1413

1514
/**
1615
* Unit tests for InvoiceV4.
@@ -42,30 +41,29 @@ void whenEmptyDeserialized_mustHaveValidProperties() throws IOException {
4241
Assertions.assertNull(docPrediction.getDueDateField().getValue());
4342
Assertions.assertNull(docPrediction.getTotalNet().getValue());
4443
Assertions.assertNull(docPrediction.getTotalAmount().getValue());
44+
Assertions.assertNull(docPrediction.getTotalTax().getValue());
4545
Assertions.assertTrue(docPrediction.getTaxes().isEmpty());
4646
Assertions.assertTrue(docPrediction.getSupplierPaymentDetails().isEmpty());
4747
Assertions.assertNull(docPrediction.getSupplierName().getValue());
48-
Assertions.assertNull(docPrediction.getTotalTax().getValue());
4948
Assertions.assertTrue(docPrediction.getSupplierCompanyRegistrations().isEmpty());
5049
Assertions.assertNull(docPrediction.getSupplierAddress().getValue());
5150
Assertions.assertNull(docPrediction.getCustomerName().getValue());
5251
Assertions.assertTrue(docPrediction.getCustomerCompanyRegistrations().isEmpty());
5352
Assertions.assertNull(docPrediction.getCustomerAddress().getValue());
54-
Assertions.assertNotNull(docPrediction.getDocumentType().getValue());
53+
Assertions.assertNull(docPrediction.getShippingAddress().getValue());
54+
Assertions.assertNull(docPrediction.getBillingAddress().getValue());
55+
Assertions.assertInstanceOf(ClassificationField.class, docPrediction.getDocumentType());
5556
Assertions.assertTrue(docPrediction.getLineItems().isEmpty());
5657
}
5758

5859
@Test
5960
void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException {
6061
PredictResponse<InvoiceV4> response = getPrediction("complete");
6162
Document<InvoiceV4> doc = response.getDocument();
62-
String[] actualLines = doc.toString().split(System.lineSeparator());
63-
List<String> expectedLines = Files.readAllLines(
64-
Paths.get("src/test/resources/products/invoices/response_v4/summary_full.rst")
63+
ProductTestHelper.assertStringEqualsFile(
64+
doc.toString(),
65+
"src/test/resources/products/invoices/response_v4/summary_full.rst"
6566
);
66-
String expectedSummary = String.join(String.format("%n"), expectedLines);
67-
String actualSummary = String.join(String.format("%n"), actualLines);
68-
69-
Assertions.assertEquals(expectedSummary, actualSummary);
7067
}
68+
7169
}

0 commit comments

Comments
 (0)