Skip to content

Commit e97f63f

Browse files
🔖 ✨ v1.1.1 - added total tax reconstruction rule for better coverage
1 parent 64388aa commit e97f63f

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Mindee python SDK
22

3+
## v1.1.1 (2020-01-31)
4+
5+
### Chg
6+
7+
* Updated total tax reconstruction for invoice
8+
39
## v1.1.0 (2020-12-02)
410

511
### Chg

mindee/documents/invoice.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,10 @@ def _reconstruct(self):
188188
"""
189189
Call fields reconstruction methods
190190
"""
191-
self.__reconstruct_total_tax()
191+
self.__reconstruct_total_tax_from_tax_lines()
192192
self.__reconstruct_total_excl_from_tcc_and_taxes()
193193
self.__reconstruct_total_incl_from_taxes_plus_excl()
194+
self.__reconstruct_total_tax_from_incl_and_excl()
194195

195196
def _checklist(self):
196197
"""
@@ -337,7 +338,7 @@ def __reconstruct_total_excl_from_tcc_and_taxes(self):
337338
}
338339
self.total_excl = Amount(total_excl, value_key="value", reconstructed=True)
339340

340-
def __reconstruct_total_tax(self):
341+
def __reconstruct_total_tax_from_tax_lines(self):
341342
"""
342343
Set self.total_tax with Amount object
343344
The total_tax Amount value is the sum of all self.taxes value
@@ -351,6 +352,25 @@ def __reconstruct_total_tax(self):
351352
if total_tax["value"] > 0:
352353
self.total_tax = Amount(total_tax, value_key="value", reconstructed=True)
353354

355+
def __reconstruct_total_tax_from_incl_and_excl(self):
356+
"""
357+
Set self.total_tax with Amount object
358+
Check if the total tax was already set
359+
If not, set thta total tax amount to the diff of incl and excl
360+
"""
361+
if self.total_tax.value is not None or\
362+
self.total_excl.value is None or\
363+
self.total_incl.value is None:
364+
pass
365+
else:
366+
367+
total_tax = {
368+
"value": self.total_incl.value - self.total_excl.value,
369+
"probability": self.total_incl.probability * self.total_excl.probability
370+
}
371+
if total_tax["value"] >= 0:
372+
self.total_tax = Amount(total_tax, value_key="value", reconstructed=True)
373+
354374
@staticmethod
355375
def compute_accuracy(invoice, ground_truth):
356376
"""

0 commit comments

Comments
 (0)