Skip to content

Commit

Permalink
LITE-28162 fix export/sync/clone for unit of measure
Browse files Browse the repository at this point in the history
  • Loading branch information
Francesco Faraone committed Jul 21, 2023
1 parent 7bacae1 commit fafccd0
Show file tree
Hide file tree
Showing 4 changed files with 25 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
17 changes: 16 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 Expand Up @@ -306,6 +320,7 @@ def _get_item_payload(self, data):
'period': self._get_billing_period(data),
'ui': {'visibility': True},
}
print(payload)
if data.type == 'reservation':
payload.update(commitment)

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 fafccd0

Please sign in to comment.