Skip to content

Commit d956766

Browse files
authored
Merge pull request #217 from cloudblue/LITE-28162
LITE-28162 fix export/sync/clone for unit of measure
2 parents 7bacae1 + 813c4a6 commit d956766

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

connect/cli/plugins/product/export.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def _fill_item_row(ws, row_idx, item):
402402
ws.cell(row_idx, 5, value=item['description'])
403403
ws.cell(row_idx, 6, value=item['type'])
404404
ws.cell(row_idx, 7, value=item['precision'])
405-
ws.cell(row_idx, 8, value=item['unit']['id'])
405+
ws.cell(row_idx, 8, value=item['unit']['name'])
406406
period = item.get('period', 'monthly')
407407
if period.startswith('years_'):
408408
period = f'{period.rsplit("_")[-1]} years'

connect/cli/plugins/product/sync/items.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,15 @@
3232

3333
class ItemSynchronizer(ProductSynchronizer):
3434
def __init__(self, client, progress, stats):
35-
self._units = list(client.ns('settings').units.all())
35+
self._units = []
36+
self._shared_units = []
37+
38+
for unit in client.ns('settings').units.all():
39+
if 'owner' in unit:
40+
self._units.append(unit)
41+
else:
42+
self._shared_units.append(unit)
43+
3644
self._mstats = stats['Items']
3745
super().__init__(client, progress)
3846

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

285+
for unit in self._shared_units:
286+
if unit['id'] == data.unit:
287+
return unit['id']
288+
if unit['type'] == data.type and unit['description'] == data.unit:
289+
return unit['id']
290+
277291
created = create_unit(
278292
self._client,
279293
{
-539 Bytes
Binary file not shown.

tests/fixtures/units_response.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,5 +250,13 @@
250250
"description": "Websites",
251251
"type": "reservation",
252252
"cumulative": false
253+
},
254+
{
255+
"id": "CU-000-000",
256+
"unit": "unit",
257+
"description": "Units",
258+
"type": "reservation",
259+
"cumulative": false,
260+
"owner": {"id": "VA-000-000"}
253261
}
254262
]

0 commit comments

Comments
 (0)