Skip to content

Commit 92164e8

Browse files
authored
Merge pull request #211 from cloudblue/LITE-27699-add-six-year-commitment-connect-cli
LITE-27699 Add 6 years label
2 parents 29569d3 + ac2e46d commit 92164e8

File tree

4 files changed

+46
-33
lines changed

4 files changed

+46
-33
lines changed

connect/cli/plugins/product/constants.py

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

2121

2222
PRECISIONS = ('integer', 'decimal(1)', 'decimal(2)', 'decimal(4)', 'decimal(8)')
23-
COMMITMENT = ('-', '1 year', '2 years', '3 years', '4 years', '5 years')
23+
COMMITMENT = ('-', '1 year', '2 years', '3 years', '4 years', '5 years', '6 years')
2424
BILLING_PERIOD = (
2525
'onetime',
2626
'monthly',
@@ -29,8 +29,22 @@
2929
'3 years',
3030
'4 years',
3131
'5 years',
32+
'6 years',
3233
)
3334

35+
36+
ALLOWED_COMMITMENTS = {
37+
'monthly': COMMITMENT,
38+
'yearly': COMMITMENT,
39+
'2 years': ('-', '4 years', '6 years'),
40+
'3 years': ('-', '6 years'),
41+
'4 years': ('-',),
42+
'5 years': ('-',),
43+
'6 years': ('-',),
44+
'onetime': ('-',),
45+
}
46+
47+
3448
CAPABILITIES = (
3549
'Pay-as-you-go support and schema',
3650
'Pay-as-you-go dynamic items support',

connect/cli/plugins/product/export.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@
2020

2121
from connect.cli.core.http import format_http_status, handle_http_error
2222
from connect.cli.core.utils import validate_output_options
23-
from connect.cli.plugins.product.constants import PARAM_TYPES
23+
from connect.cli.plugins.product.constants import (
24+
BILLING_PERIOD,
25+
COMMITMENT,
26+
PARAM_TYPES,
27+
PRECISIONS,
28+
)
2429
from connect.cli.plugins.product.utils import get_json_object_for_param
2530
from connect.cli.plugins.shared.export import alter_attributes_sheet, get_translation_workbook
2631
from connect.cli.plugins.shared.utils import (
@@ -42,6 +47,10 @@ def _setup_locales_list(ws, client):
4247
ws[f'AB{idx}'].value = loc
4348

4449

50+
def _build_f1_options(option_list):
51+
return '"{options}"'.format(options=','.join(option_list))
52+
53+
4554
def _setup_cover_sheet(ws, product, location, client, media_path):
4655
ws.title = 'General Information'
4756
ws.column_dimensions['A'].width = 50
@@ -486,9 +495,7 @@ def _dump_parameters(ws, client, product_id, param_type, progress):
486495
)
487496
type_validation = DataValidation(
488497
type='list',
489-
formula1='"{params}"'.format(
490-
params=','.join(PARAM_TYPES),
491-
),
498+
formula1=_build_f1_options(PARAM_TYPES),
492499
allow_blank=False,
493500
)
494501
ordering_fulfillment_scope_validation = DataValidation(
@@ -818,19 +825,19 @@ def _dump_items(ws, client, product_id, progress):
818825
)
819826
period_validation = DataValidation(
820827
type='list',
821-
formula1='"onetime,monthly,yearly,2 years,3 years,4 years,5 years"',
828+
formula1=_build_f1_options(BILLING_PERIOD),
822829
allow_blank=False,
823830
)
824831

825832
precision_validation = DataValidation(
826833
type='list',
827-
formula1='"integer,decimal(1),decimal(2),decimal(4),decimal(8)"',
834+
formula1=_build_f1_options(PRECISIONS),
828835
allow_blank=False,
829836
)
830837

831838
commitment_validation = DataValidation(
832839
type='list',
833-
formula1='"-,1 year,2 years,3 years,4 years,5 years"',
840+
formula1=_build_f1_options(COMMITMENT),
834841
allow_blank=False,
835842
)
836843

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

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515
get_item_by_mpn,
1616
update_item,
1717
)
18-
from connect.cli.plugins.product.constants import BILLING_PERIOD, COMMITMENT, PRECISIONS
18+
from connect.cli.plugins.product.constants import (
19+
ALLOWED_COMMITMENTS,
20+
BILLING_PERIOD,
21+
COMMITMENT,
22+
PRECISIONS,
23+
)
1924
from connect.cli.plugins.shared.base import ProductSynchronizer
2025
from connect.cli.plugins.shared.constants import ITEMS_COLS_HEADERS
2126

@@ -163,26 +168,13 @@ def _validate_commitment(row):
163168
'is invalid for `ppu` items.',
164169
]
165170

166-
if row.billing_period == 'onetime' and row.commitment != '-':
167-
return [
168-
f'the commitment `{row.commitment}` '
169-
'is invalid for `onetime` items.',
170-
]
171+
allowed_commitments = ALLOWED_COMMITMENTS.get(row.billing_period, [])
171172

172-
if row.billing_period == '2 years' and row.commitment not in ('-', '4 years'):
173-
return [
174-
f'for a billing period of `2 years` the commitment '
175-
'must be one between `-`, `4 years`, '
176-
f' not {row.commitment}.',
177-
]
178-
if row.billing_period in (
179-
'3 years',
180-
'4 years',
181-
'5 years',
182-
) and row.commitment != '-':
173+
if allowed_commitments and row.commitment not in allowed_commitments:
174+
valid_commitment = ', '.join([f'`{name}`' for name in allowed_commitments])
183175
return [
184-
f'for a billing period of `{row.billing_period}` the commitment '
185-
f'must be `-`, not {row.commitment}.',
176+
f'for a `{row.billing_period}` billing period the commitment '
177+
f'must be one of {valid_commitment}, not `{row.commitment}`.',
186178
]
187179

188180
return []

tests/plugins/product/sync/test_items.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def test_validate_wrong_period_reservation(mocker, fs, get_sync_items_env):
356356
}
357357
assert stats['Items']._row_errors == {
358358
2: ['the item `Billing period` must be one between `onetime`, `monthly`, `yearly`, '
359-
'`2 years`, `3 years`, `4 years`, `5 years`, not `century`.'],
359+
'`2 years`, `3 years`, `4 years`, `5 years`, `6 years`, not `century`.'],
360360
}
361361

362362

@@ -662,7 +662,7 @@ def test_create_item_validate_commitment(
662662
}
663663
assert stats['Items']._row_errors == {
664664
2: ['the item `Commitment` must be one between `-`, `1 year`, `2 years`, `3 years`, '
665-
'`4 years`, `5 years`, not `commitment`.'],
665+
'`4 years`, `5 years`, `6 years`, not `commitment`.'],
666666
}
667667

668668

@@ -738,7 +738,7 @@ def test_create_item_validate_commitment_onetime(
738738
'deleted': 0, 'skipped': 0, 'errors': 1,
739739
}
740740
assert stats['Items']._row_errors == {
741-
2: ['the commitment `1 year` is invalid for `onetime` items.'],
741+
2: ['for a `onetime` billing period the commitment must be one of `-`, not `1 year`.'],
742742
}
743743

744744

@@ -776,8 +776,8 @@ def test_create_item_validate_commitment_wrong_multiyear(
776776
'deleted': 0, 'skipped': 0, 'errors': 1,
777777
}
778778
assert stats['Items']._row_errors == {
779-
2: ['for a billing period of `2 years` the commitment must be one between `-`, `4 years`, '
780-
' not 3 years.'],
779+
2: ['for a `2 years` billing period the commitment must be one of `-`, `4 years`'
780+
', `6 years`, not `3 years`.'],
781781
}
782782

783783

@@ -815,7 +815,7 @@ def test_create_item_validate_commitment_wrong_multiyear_vs_commitment(
815815
'deleted': 0, 'skipped': 0, 'errors': 1,
816816
}
817817
assert stats['Items']._row_errors == {
818-
2: ['for a billing period of `3 years` the commitment must be `-`, not 5 years.'],
818+
2: ['for a `3 years` billing period the commitment must be one of `-`, `6 years`, not `5 years`.'],
819819
}
820820

821821

0 commit comments

Comments
 (0)