Previous topic

5.17.2. importing — Importing helpers

Next topic

5.18. views — Views

This Page

Languages

Previous versions

1.2
1.1

5.17.3. units — Units

This module defines two constants:

plmapp.utils.units.DEFAULT_UNIT

The default unit of a BOM row: - (each)

plmapp.utils.units.UNITS

All valid units of a BOM row.

exception plmapp.utils.units.UnitConversionError[source]

New in version 1.1.

Exception raised if an error occurs while converting a value from one unit to another one.

plmapp.utils.units.convert_unit(value, original_unit, new_unit)[source]

New in version 1.1.

Converts a value expressed in original_unit to new_unit

Raises :UnitConversionError if the conversion is not possible.

Here is an example :

>>> convert_unit(1, 'm', 'mm')
1000.0
>>> convert_unit(5, 'dm', 'mm')
500.0
>>> convert_unit(5, 'dL', 'm3')
0.00050000000000000001
>>> convert_unit(5, 'dL', 'kg')
------------------------------------------------------------
Traceback (most recent call last):
  File "<ipython console>", line 1, in <module>
  File plmpapp/utils/units.py", line 80, in convert_unit
    def convert_unit(value, original_unit, new_unit):
UnitConversionError: Inconsistent units (dL, kg)