diff --git a/connector_carepoint/models/fdb_unit.py b/connector_carepoint/models/fdb_unit.py index 66cfff6..5279d0e 100644 --- a/connector_carepoint/models/fdb_unit.py +++ b/connector_carepoint/models/fdb_unit.py @@ -3,7 +3,10 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). import logging +import re + from os import path + from openerp import models, fields from openerp.addons.connector.unit.mapper import (mapping, only_create, @@ -17,8 +20,11 @@ CarepointImporter, ) -from pint import LazyRegistry -from pint.util import infer_base_unit +try: + from pint import LazyRegistry + from pint.util import infer_base_unit +except ImportError: + pass _logger = logging.getLogger(__name__) @@ -99,7 +105,12 @@ def _uom_category_id(self, unit_root_str): @only_create def uom_id(self, record): - unit_base = ureg(record['str60'].strip()) + str60 = record['str60'].strip() + match = re.search(r'(?P\d+)cc', str60, re.IGNORECASE) + if match: + str60 = '%s cc' % match.group('unit') + + unit_base = ureg(str60) unit_base_str = str(unit_base.u) unit_root = infer_base_unit(unit_base) unit_root_str = str(unit_root) diff --git a/connector_carepoint/tests/models/test_fdb_unit.py b/connector_carepoint/tests/models/test_fdb_unit.py index aefd905..0c4ae66 100644 --- a/connector_carepoint/tests/models/test_fdb_unit.py +++ b/connector_carepoint/tests/models/test_fdb_unit.py @@ -108,6 +108,18 @@ def test_uom_id_ureg(self): self.record['str60'].strip() ) + def test_uom_id_ureg_cc(self): + """ It should have identified and split the CC for ureg parse """ + record = self.record + record['str60'] = '1cc' + with self.mock_pint() as mk: + mk['ureg'].side_effect = EndTestException + with self.assertRaises(EndTestException): + self.unit.uom_id(record) + mk['ureg'].assert_called_once_with( + '1 cc' + ) + def test_uom_id_infer_base_unit(self): """ It should attempt to infer base of unit """ with self.mock_pint() as mk: