Skip to content

Commit

Permalink
Merge pull request #217 from cloudblue/LITE-28162
Browse files Browse the repository at this point in the history
LITE-28162 fix export/sync/clone for unit of measure
  • Loading branch information
ffaraone authored Jul 21, 2023
2 parents 7bacae1 + 813c4a6 commit d956766
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion connect/cli/plugins/product/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def _fill_item_row(ws, row_idx, item):
ws.cell(row_idx, 5, value=item['description'])
ws.cell(row_idx, 6, value=item['type'])
ws.cell(row_idx, 7, value=item['precision'])
ws.cell(row_idx, 8, value=item['unit']['id'])
ws.cell(row_idx, 8, value=item['unit']['name'])
period = item.get('period', 'monthly')
if period.startswith('years_'):
period = f'{period.rsplit("_")[-1]} years'
Expand Down
16 changes: 15 additions & 1 deletion connect/cli/plugins/product/sync/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@

class ItemSynchronizer(ProductSynchronizer):
def __init__(self, client, progress, stats):
self._units = list(client.ns('settings').units.all())
self._units = []
self._shared_units = []

for unit in client.ns('settings').units.all():
if 'owner' in unit:
self._units.append(unit)
else:
self._shared_units.append(unit)

self._mstats = stats['Items']
super().__init__(client, progress)

Expand Down Expand Up @@ -274,6 +282,12 @@ def _get_or_create_unit(self, data):
if unit['type'] == data.type and unit['description'] == data.unit:
return unit['id']

for unit in self._shared_units:
if unit['id'] == data.unit:
return unit['id']
if unit['type'] == data.type and unit['description'] == data.unit:
return unit['id']

created = create_unit(
self._client,
{
Expand Down
Binary file modified tests/fixtures/comparation_product.xlsx
Binary file not shown.
8 changes: 8 additions & 0 deletions tests/fixtures/units_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -250,5 +250,13 @@
"description": "Websites",
"type": "reservation",
"cumulative": false
},
{
"id": "CU-000-000",
"unit": "unit",
"description": "Units",
"type": "reservation",
"cumulative": false,
"owner": {"id": "VA-000-000"}
}
]

0 comments on commit d956766

Please sign in to comment.