@@ -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