Exemple #1
0
    def sync(self):  # noqa: CCR001
        ws = self._wb['Embedding Static Resources']

        row_indexes = trange(
            2,
            ws.max_row + 1,
            disable=self._silent,
            leave=True,
            bar_format=DEFAULT_BAR_FORMAT,
        )
        download = []
        documentation = []
        for row_idx in row_indexes:
            data = _RowData(
                *[ws.cell(row_idx, col_idx).value for col_idx in range(1, 5)])
            row_indexes.set_description(
                f'Processing item {data.title or data.type}')
            if data.action not in ('-', 'create', 'delete'):
                self._mstats.skipped()
                continue
            row_errors = self._validate_row(data)
            if row_errors:
                self._mstats.error(row_errors, row_idx)
                continue
            if data.action == 'delete':
                self._mstats.deleted()
                continue
            if data.type == 'Download':
                download.append(
                    {
                        "title": data.title,
                        "url": data.url,
                        "visible_for": "admin",
                    }, )
            if data.type == "Documentation":
                documentation.append({
                    "title": data.title,
                    "url": data.url,
                }, )
            if data.action == '-':
                self._mstats.skipped()
            else:
                self._mstats.created()

        product = cleanup_product_for_update(
            self._client.products[self._product_id].get())
        try:
            product['customer_ui_settings']['download_links'] = download
            product['customer_ui_settings']['documents'] = documentation
            self._client.products[self._product_id].update(product)
        except Exception as e:
            self._mstats.error(str(e), 1)
Exemple #2
0
    def sync(self):
        errors = []
        product = cleanup_product_for_update(
            self._client.products[self._product_id].get())
        ws = self._wb['General Information']
        product['short_description'] = ws['B10'].value.replace('\n', '')
        product['detailed_description'] = ws['B11'].value
        product['customer_ui_settings']['description'] = ws['B12'].value
        product['customer_ui_settings']['getting_started'] = ws['B12'].value
        product['name'] = ws['B6'].value
        product['category']['name'] = ws['B8'].value
        product['category']['id'] = self._category
        # Solution for v22 to avoid issue while updating capabilities
        del product['capabilities']['subscription']['change'][
            'editable_ordering_parameters']
        try:
            self._client.products[self._product_id].update(product)
        except ClientError as e:
            errors.append(
                f'Error while updating general product information: {str(e)}',
            )
            return errors
        payload = MultipartEncoder(fields={
            'icon': (
                ws['B9'].value,
                open(
                    os.path.join(
                        self._media_path,
                        'media',
                        ws['B9'].value,
                    ),
                    "rb",
                ),
            ),
        }, )
        try:
            self._client.products[self._product_id].update(
                data=payload,
                headers={'Content-Type': payload.content_type},
            )
        except ClientError as e:
            errors.append(
                f'Error while updating general product information: {str(e)}',
            )

        return errors
    def sync(self):  # noqa: CCR001
        ws = self._wb['Capabilities']

        row_indexes = trange(
            2, ws.max_row + 1, disable=self._silent, leave=True, bar_format=DEFAULT_BAR_FORMAT,
        )
        for row_idx in row_indexes:
            data = _RowData(*[ws.cell(row_idx, col_idx).value for col_idx in range(1, 4)])
            row_indexes.set_description(f'Processing Product capabilities {data.capability}')
            if data.action == '-':
                self._mstats.skipped()
                continue
            row_errors = self._validate_row(data)

            if row_errors:
                self._mstats.error(row_errors, row_idx)
                continue

            product = cleanup_product_for_update(self._client.products[self._product_id].get())

            if data.action == 'update':
                update = True
                try:
                    if data.capability == 'Pay-as-you-go support and schema':
                        if data.value != 'Disabled':
                            if not product['capabilities'].get('ppu', False):
                                product['capabilities']['ppu'] = {
                                    'schema': data.value,
                                    'dynamic': False,
                                    'future': False,
                                }
                            else:
                                product['capabilities']['ppu']['schema'] = data.value
                        else:
                            product['capabilities']['ppu'] = None
                    if data.capability == 'Pay-as-you-go dynamic items support':
                        if not product['capabilities'].get('ppu', False):
                            if data.value == 'Enabled':
                                raise Exception(
                                    "Dynamic items support can't be enabled without Pay-as-you-go "
                                    "support",
                                )
                            update = False
                        else:
                            if data.value == 'Enabled':
                                product['capabilities']['ppu']['dynamic'] = True
                            else:
                                product['capabilities']['ppu']['dynamic'] = False
                    if data.capability == "Pay-as-you-go future charges support":
                        if not product['capabilities'].get('ppu', False):
                            if data.value == 'Enabled':
                                raise Exception(
                                    "Report of future charges can't be enabled without Pay-as-you-go "
                                    "support",
                                )
                            update = False

                        else:
                            if data.value == 'Enabled':
                                product['capabilities']['ppu']['future'] = True
                            else:
                                product['capabilities']['ppu']['future'] = False
                    if data.capability == 'Consumption reporting for Reservation Items':
                        if data.value == 'Enabled':
                            product['capabilities']['reservation']['consumption'] = True
                        else:
                            product['capabilities']['reservation']['consumption'] = False

                    if data.capability == 'Dynamic Validation of the Draft Requests':
                        if data.value == 'Enabled':
                            product['capabilities']['cart']['validation'] = True
                        else:
                            product['capabilities']['cart']['validation'] = False

                    if data.capability == 'Dynamic Validation of the Inquiring Form':
                        if data.value == 'Enabled':
                            product['capabilities']['inquiring']['validation'] = True
                        else:
                            product['capabilities']['inquiring']['validation'] = False

                    if data.capability == 'Reseller Authorization Level':
                        if data.value == 'Disabled':
                            product['capabilities']['tiers']['configs'] = None
                        else:
                            product['capabilities']['tiers']['configs'] = {
                                'level': data.value,
                            }
                    if data.capability == 'Tier Accounts Sync':
                        if data.value == 'Enabled':
                            product['capabilities']['tiers']['updates'] = True
                        else:
                            product['capabilities']['tiers']['updates'] = False
                    if data.capability == 'Administrative Hold':
                        if data.value == 'Enabled':
                            product['capabilities']['subscription']['hold'] = True
                        else:
                            product['capabilities']['subscription']['hold'] = False
                    if data.capability == 'Dynamic Validation of Tier Requests':
                        if data.value == 'Enabled':
                            product['capabilities']['tiers']['validation'] = True
                        else:
                            product['capabilities']['tiers']['validation'] = False
                    if data.capability == 'Editable Ordering Parameters in Change Request':
                        if data.value == 'Enabled':
                            product[
                                'capabilities'
                            ][
                                'subscription'
                            ][
                                'change'
                            ][
                                'editable_ordering_parameters'
                            ] = True
                        else:
                            product[
                                'capabilities'
                            ][
                                'subscription'
                            ][
                                'change'
                            ][
                                'editable_ordering_parameters'
                            ] = False
                    if data.capability == 'Validation of Draft Change Request':
                        if data.value == 'Enabled':
                            product[
                                'capabilities'
                            ][
                                'subscription'
                            ][
                                'change'
                            ][
                                'validation'
                            ] = True
                        else:
                            product[
                                'capabilities'
                            ][
                                'subscription'
                            ][
                                'change'
                            ][
                                'validation'
                            ] = False
                    if data.capability == 'Validation of inquiring form for Change Requests':
                        if data.value == 'Enabled':
                            product[
                                'capabilities'
                            ][
                                'subscription'
                            ][
                                'change'
                            ][
                                'inquiring_validation'
                            ] = True
                        else:
                            product[
                                'capabilities'
                            ][
                                'subscription'
                            ][
                                'change'
                            ][
                                'inquiring_validation'
                            ] = False
                    if update:
                        self._client.products[self._product_id].update(product)
                    self._mstats.updated()

                except Exception as e:
                    self._mstats.error(str(e), row_idx)