Skip to content

Commit

Permalink
[FIX] fdb_unit: Split CC strings that are conjoined
Browse files Browse the repository at this point in the history
  • Loading branch information
lasley committed Aug 22, 2016
1 parent 30cb0fc commit 8c31e2a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
17 changes: 14 additions & 3 deletions connector_carepoint/models/fdb_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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__)

Expand Down Expand Up @@ -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<unit>\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)
Expand Down
12 changes: 12 additions & 0 deletions connector_carepoint/tests/models/test_fdb_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 8c31e2a

Please sign in to comment.