def reset_supplier_declaration(stage, framework_slug, reason, email, supplier_id):
    data_api_token = get_auth_token('api', stage) if stage != 'development' else 'myToken'
    data_api_client = DataAPIClient(get_api_endpoint_from_stage(stage), data_api_token)

    if email:
        user = data_api_client.get_user(email_address=email)

        if not user:
            print(f'No user found for email address `{email}`')
            exit(1)

        user_supplier_id = user['users']['supplier']['supplierId']
        if user_supplier_id and supplier_id and user_supplier_id != supplier_id:
            print(f'Email address provided does not match with supplier provided. Email address `{email}` is '
                  f'associated with supplierId `{supplier_id}`. Script was called with supplierId `{supplier_id}`.')
            exit(2)

        supplier_id = user_supplier_id

    try:
        supplier_framework = data_api_client.get_supplier_framework_info(supplier_id=supplier_id,
                                                                         framework_slug=framework_slug)
        print(f"Current supplier declaration: {supplier_framework['frameworkInterest']['declaration']}")

    except HTTPError:
        print(f'No supplier framework found for supplierId `{supplier_id}` on framework `{framework_slug}`.')
        exit(3)

    if not supplier_framework:
        print(f'No supplier framework/interest record found for supplierId `{supplier_id}` on framework '
              f'`{framework_slug}`.')
        exit(4)

    data_api_client.set_supplier_declaration(supplier_id=supplier_id, framework_slug=framework_slug, declaration={},
                                             user=f'{getpass.getuser()} - {reason}')
    data_api_client.set_supplier_framework_prefill_declaration(supplier_id=supplier_id, framework_slug=framework_slug,
                                                               prefill_declaration_from_framework_slug=None,
                                                               user=f'{getpass.getuser()} - {reason}')
    print(f'Supplier declaration for supplierId `{supplier_id}` on framework `{framework_slug}` has been reset.')
예제 #2
0
        logger.error(
            f"Cannot suspend services for '{framework_slug}' with status {framework['status']}"
        )
        exit(1)

    supplier_ids = get_supplier_ids_from_args(args)
    suppliers = find_suppliers_without_agreements(client, framework_slug,
                                                  supplier_ids)

    framework_name = framework["name"]
    contract_title = get_framework_contract_title(FRAMEWORKS_PATH,
                                                  framework_slug)

    for supplier in suppliers:
        supplier_id = supplier["supplierId"]
        framework_info = client.get_supplier_framework_info(
            supplier_id, framework_slug)

        logger.info(f"{prefix}Suspending services for supplier {supplier_id}")
        if not dry_run:
            # Do the suspending
            suspended_service_count = suspend_supplier_services(
                client, logger, framework_slug, supplier_id, framework_info,
                dry_run)

            if suspended_service_count > 0:
                logger.info(
                    f"{prefix}Suspended {suspended_service_count} services for supplier {supplier_id}"
                )
            else:
                logger.warning(
                    f"{prefix}Something went wrong - suspended 0 services for supplier {supplier_id}"
    dry_run = bool(arguments.get("--dry-run"))

    frameworks = tuple(client.get_framework(framework_slug)["frameworks"] for framework_slug in framework_slugs)

    logger.info("Inspecting framework declarations in this order: %s", ", ".join(fw["slug"] for fw in frameworks))

    for supplier in client.find_suppliers_iter():
        logger.info("Processing supplier %s", supplier["id"])
        if supplier.get("tradingStatus") and (supplier["contactInformation"][0]).get("address2") == "":
            logger.info("  already done: {}".format(supplier["id"]))
            continue
        try:
            supplier_framework = next(
                sfr["frameworkInterest"] for sfr in (
                    _catch_404_none(
                        lambda: client.get_supplier_framework_info(supplier["id"], framework["slug"])
                    ) for framework in frameworks
                ) if sfr and sfr["frameworkInterest"]["onFramework"]
            )
        except StopIteration:
            logger.info("Supplier %s: not on any relevant frameworks", supplier["id"])
            supplier_framework = None
        else:
            logger.info(
                "Supplier %s: using data from framework %s",
                supplier["id"],
                supplier_framework["frameworkSlug"],
            )

        supplier_update = {}
        if supplier_framework: