endi.compute package

Subpackages

Submodules

endi.compute.base_line module

class endi.compute.base_line.BaseLineCompute

Bases : object

Common class for basic lines compute

Attributs utilisés pour le calcul self.ht (float) self.tva (float)

property total
property total_ht
property total_tva

endi.compute.expense module

Expense computing tool

class endi.compute.expense.ExpenseCompute

Bases : object

get_lines(category='0')

Return all expense lines (lines and kmlines)

get_lines_by_type(category='0')

Return expense lines grouped by treasury code

get_total(category=None)
property is_void
kmlines = ()
lines = ()
paid()
payments = ()
topay()
property total
property total_ht
property total_km
property total_tva
class endi.compute.expense.ExpenseKmLineCompute

Bases : object

expense_type = None
property total
property total_ht
property total_tva
class endi.compute.expense.ExpenseLineCompute

Bases : object

Expense lines related computation tools

expense_type = None
property total
property total_ht
property total_tva

endi.compute.math_utils module

Math utilities used for computing

class endi.compute.math_utils.NullValue

Bases : object

endi.compute.math_utils.amount(value, precision=2)

Convert a float value as an integer amount to store it in a database :param value: float value to convert :param precision: number of dot translation to make

>>> amount(195.65)
19565
endi.compute.math_utils.compute_floored_ht_from_ttc(ttc: int, tva_rate: int) int

Compute the HT from TTC using the approximative method (multiplication_mode)

endi.compute.math_utils.compute_genuine_ht_from_ttc(ttc: int, tva_rate: int) int

Compute the HT from TTC using the genuine calculation method (division_mode)

endi.compute.math_utils.compute_ht_from_ttc(ttc, tva_rate, float_format=True, division_mode=False)

Compute ht from ttc

This function has two modes :

  • multiplication (default) : use legal coefficients (lower math precision, rounding in favor of TVA) is based on legal basis rather than math precision. https://bofip.impots.gouv.fr/bofip/1380-PGP.html/identifiant=BOI-TVA-LIQ-10-20140919

  • division : use division, better math precision, at risk of less reproductable computation and rounding errors. Use it when you want to try reversing a computation that have already been done the other way (HT→TTC) (may not work 100% of cases though).

Results should be used at line level, not at total level, or inconsistencies may arise.

Eg (pseudo-code):
  • VALID: total_ht = sum([compute_ht_from_ttc(line.ttc) for line in lines])

  • INVALID: total_ht = compute_ht_from_ttc(sum([line.ttc for line in lines]))

Paramètres:
  • ttc (float) – ttc value in float format (by default)

  • tva_rate (integer) – the tva rate value in integer format (tva_rate *

100) :param bool float_format: Is ttc in the float format (real ttc value) :param division_mode: Use the division mode

Renvoie:

the value in integer format or in float format regarding

float_format

endi.compute.math_utils.compute_ht_from_ttc_in_int(ttc: int, tva_rate: int, division_mode: bool = False) int

Compute HT from TTC using the appropriate calculation mode (see below function)

endi.compute.math_utils.compute_tva(ht, tva_rate)

Compute the tva for the given ht

endi.compute.math_utils.compute_tva_from_ttc(ttc: Union[float, int], tva_rate: int, float_format: bool = True) Union[float, int]

This function is based on legal basis rather than math precision https://bofip.impots.gouv.fr/bofip/1380-PGP.html/identifiant=BOI-TVA-LIQ-10-20140919

Results should be used at line level, not at total level, or errors will appear and may cumulate :

Eg (pseudo-code):
  • VALID: total_tva = sum([compute_tva_from_ttc(line.ttc) for line in lines])

  • INVALID: total_tva = compute_tva_from_ttc(sum([line.ttc for line in lines]))

Paramètres:
  • ttc – ttc value in float format (by default)

  • tva_rate – the tva rate value in integer format (tva_rate * 100)

  • float_format – Is ttc in the float format (real ttc value)

Renvoie:

the value in integer format or in float format regarding float_format

endi.compute.math_utils.convert_to_float(value: ~typing.Any, default: ~typing.Any = <endi.compute.math_utils.NullValue object>) float

Try to convert the given value object to a float

>>> convert_to_float("15.25")
15.25
endi.compute.math_utils.convert_to_int(value: ~typing.Any, default: ~typing.Optional[~typing.Any] = <endi.compute.math_utils.NullValue object>) Optional[int]

Convert a value to an integer

Paramètres:
  • value – The value to convert

  • default – if provided will be returned if the conversion fails

Lève:

Usage

>>> convert_to_int("15")
15
>>> convert_to_int("not an int", 15)
15
endi.compute.math_utils.dec_round(dec, precision, round_floor=False)

Return a decimal object rounded to precision

Paramètres:
  • precision (int) – the number of decimals we want after the comma

  • round_floor (bool) – Should the data be floor rounded ?

endi.compute.math_utils.floor(value, round_floor=False)

floor a float value :param value: float value to be rounded :param bool round_floor: Should the data be floor rounded ? :return: an integer

>>> floor(296.9999999)
297
endi.compute.math_utils.floor_to_precision(value: Union[int, float, Decimal], round_floor=False, precision=2, dialect_precision=5) int
floor a value in its int representation:
>>> floor_to_precision(296999)
297000
>>> floor_to_precision(296999, round_floor=True)
296000

amounts are of the form : value * 10 ** dialect_precision it allows to store dialect_precision numbers after comma for intermediary amounts for totals we want precision numbers

Paramètres:
  • value (int) – The value to floor

  • round_floor (bool) – Should be rounded down ?

  • precision (int) – How much significant numbers we want ?

  • dialect_precision (int) – The number of zeros that are concerning the

floatting part of our value

endi.compute.math_utils.integer_to_amount(value, precision=2, default=<endi.compute.math_utils.NullValue object>) float

Convert an integer value to a float with precision numbers after comma

endi.compute.math_utils.percent(part, total, default=<endi.compute.math_utils.NullValue object>) float

Return the percentage of total represented by part if default is provided, the ZeroDivisionError is handled

endi.compute.math_utils.percentage(value, _percent) int

Return the value of the « percent » percent of the original « value » Truncate the result.

>>> percentage(100.1, 50)
50
endi.compute.math_utils.round(float_, precision, round_floor=False)

Return a float object rounded to precision :param float float_: the object to round :param int precision: the number of decimals we want after the comma :param bool round_floor: Should the data be floor rounded ?

endi.compute.math_utils.str_to_float(value: ~typing.Any, default: ~typing.Any = <endi.compute.math_utils.NullValue object>) float

Convert a string to a float cleaning all non numeric information

>>> str_to_float("15dede,25")
15.25
endi.compute.math_utils.str_to_int(value: ~typing.Any, default=<endi.compute.math_utils.NullValue object>) Optional[int]

convert a string to an integer cleaning all non numeric information

Usage

>>> str_to_int("abc12,56")
1256
endi.compute.math_utils.translate_integer_precision(value, from_precision=5, to_precision=2)

Translate an integer value from precision 5 to precision 2

e.g>>> translate_integer_precision(150111)

… 150

endi.compute.parser module

Numeric expression parser

parser = NumericParser() parser.eval(« 2 * 15 / 22 »)

class endi.compute.parser.NumericStringFloatReducer

Bases : object

Reduce a parsed numeric string to a float value

By doing the math!

Expects input in the format of NumericStringParser output.

Eg: transforms [« 1.2 », « + », « 1 »] to 2.2

Does not support brace vars (eg: [« 1.2 » + « {fubar}])

functions = {'abs': <built-in function abs>, 'round': <built-in function round>, 'trunc': <function NumericStringFloatReducer.<lambda>>}
operators = {'*': <built-in function mul>, '+': <built-in function add>, '-': <built-in function sub>, '/': <built-in function truediv>}
classmethod reduce(stack: List[str]) float
Paramètres:

stack – example : [« 1.2 », « + », « 1 »]

Renvoie:

the result of the computation

class endi.compute.parser.NumericStringParser

Bases : object

Parse a string containing numeric expression

The string can contain brace vars, like in :

{fu bar} + {zu}

parse(num_string, parse_all=True)
push_first(strg, loc, toks)
push_u_minus(strg, loc, toks)

endi.compute.supplier_invoice module

class endi.compute.supplier_invoice.SupplierInvoiceCompute

Bases : object

Handles numbers as decimal stored as int with 2 decimals.

lines : SupplierOrderLine[] cae_percentage: int

cae_paid() int
cae_topay() int
property cae_total: int
get_lines_by_type()

Return supplier invoice lines grouped by treasury code

property orders_cae_total: int
property orders_total: int
property orders_total_ht: int
property orders_total_tva: int
property orders_worker_total: int
paid() int
topay() int
property total: int
property total_ht: int
property total_tva: int
worker_paid() int
worker_topay() int
property worker_total: int
class endi.compute.supplier_invoice.SupplierInvoiceLineCompute

Bases : BaseLineCompute

property cae_total: int
property worker_total: int

endi.compute.supplier_order module

class endi.compute.supplier_order.SupplierOrderCompute

Bases : object

Handles numbers as decimal stored as int with 2 decimals.

Attributs utilisés pour le calcul:

lines : SupplierOrderLine[] cae_percentage: int

property cae_total: int
property total: int
property total_ht: int
property total_tva: int
property worker_total: int
class endi.compute.supplier_order.SupplierOrderLineCompute

Bases : BaseLineCompute

Module contents