Skip to content

Commit

Permalink
[HF] MPT-6549 Account revival is failing if the account to be transfe… (
Browse files Browse the repository at this point in the history
#323)

…rred has one-time items
  • Loading branch information
d3rky authored and Robert Segal committed Feb 4, 2025
2 parents e0fd807 + f07b7aa commit 183e845
Show file tree
Hide file tree
Showing 30 changed files with 817 additions and 107 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/pr-build-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ jobs:
run: |
sed -i 's/\/extension\/adobe_vipm/\/home\/runner\/work\/swo-adobe-vipm-extension\/swo-adobe-vipm-extension\/adobe_vipm/g' coverage.xml
- name: 'Run SonarCloud Scan'
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

- name: 'Run SonarQube Quality Gate check'
uses: sonarsource/sonarqube-quality-gate-action@master
timeout-minutes: 5
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# - name: 'Run SonarCloud Scan'
# uses: SonarSource/sonarcloud-github-action@master
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

# - name: 'Run SonarQube Quality Gate check'
# uses: sonarsource/sonarqube-quality-gate-action@master
# timeout-minutes: 5
# env:
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

- name: 'Stop containers'
if: always()
Expand Down
1 change: 0 additions & 1 deletion adobe_vipm/adobe/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,6 @@ def get_customer_deployments(
return response.json()



_ADOBE_CLIENT = None


Expand Down
8 changes: 6 additions & 2 deletions adobe_vipm/flows/fulfillment/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,9 +671,13 @@ def __call__(self, client, context, next_step):
for returnable_order, return_order in map_returnable_to_return_orders(
returnable_orders or [], return_orders
):
returnable_order_deployment_id = returnable_order.line.get("deploymentId", None)
returnable_order_deployment_id = returnable_order.line.get(
"deploymentId", None
)
is_returnable = (
(deployment_id == returnable_order_deployment_id) if deployment_id else True
(deployment_id == returnable_order_deployment_id)
if deployment_id
else True
)
if is_returnable:
if return_order:
Expand Down
45 changes: 22 additions & 23 deletions adobe_vipm/flows/fulfillment/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
switch_order_to_query,
)
from adobe_vipm.flows.helpers import SetupContext
from adobe_vipm.flows.mpt import update_order
from adobe_vipm.flows.mpt import get_product_items_by_skus, update_order
from adobe_vipm.flows.pipeline import Pipeline, Step
from adobe_vipm.flows.sync import sync_agreements_by_agreement_ids
from adobe_vipm.flows.utils import (
Expand Down Expand Up @@ -240,7 +240,7 @@ def _fulfill_transfer_migrated(
transfer,
one_time_skus,
gc_main_agreement,
adobe_subscriptions
adobe_subscriptions,
):
authorization_id = order["authorization"]["id"]

Expand Down Expand Up @@ -362,9 +362,7 @@ def __call__(self, client, context, next_step):
next_step(client, context)


def _create_new_adobe_order(
mpt_client, order, transfer, gc_main_agreement
):
def _create_new_adobe_order(mpt_client, order, transfer, gc_main_agreement):
# Create new order on Adobe with the items selected by the client
adobe_customer_id = get_adobe_customer_id(order)
if not adobe_customer_id:
Expand All @@ -378,9 +376,7 @@ def _create_new_adobe_order(
CreateOrUpdateSubscriptions(),
SetOrUpdateCotermNextSyncDates(),
UpdatePrices(),
SyncGCMainAgreement(
transfer, gc_main_agreement, STATUS_GC_CREATED
),
SyncGCMainAgreement(transfer, gc_main_agreement, STATUS_GC_CREATED),
CompleteOrder(TEMPLATE_NAME_BULK_MIGRATE),
UpdateTransferStatus(transfer, STATUS_SYNCHRONIZED),
)
Expand Down Expand Up @@ -429,9 +425,7 @@ def _transfer_migrated(
# and, it is pending to review the order status
adobe_order_id = get_adobe_order_id(order)
if adobe_order_id:
_create_new_adobe_order(
mpt_client, order, transfer, gc_main_agreement
)
_create_new_adobe_order(mpt_client, order, transfer, gc_main_agreement)
return

adobe_client = get_adobe_client()
Expand Down Expand Up @@ -470,10 +464,18 @@ def _transfer_migrated(
customer_deployments,
):
return

adobe_transfer = exclude_items_with_deployment_id(adobe_transfer)

one_time_skus = get_one_time_skus(mpt_client, order)
returned_skus = [
get_partial_sku(item["offerId"]) for item in adobe_subscriptions["items"]
]
items = get_product_items_by_skus(
mpt_client, order["agreement"]["product"]["id"], returned_skus
)
one_time_skus = [
item["externalIds"]["vendor"]
for item in items
if item["terms"]["period"] == "one-time"
]
adobe_items_without_one_time_offers = [
item
for item in adobe_subscriptions["items"]
Expand All @@ -484,9 +486,7 @@ def _transfer_migrated(
are_all_transferring_items_expired(adobe_items_without_one_time_offers)
or len(adobe_transfer["lineItems"]) == 0
) and not gc_main_agreement:
_create_new_adobe_order(
mpt_client, order, transfer, gc_main_agreement
)
_create_new_adobe_order(mpt_client, order, transfer, gc_main_agreement)
else:
_fulfill_transfer_migrated(
adobe_client,
Expand All @@ -495,7 +495,7 @@ def _transfer_migrated(
transfer,
one_time_skus,
gc_main_agreement,
adobe_subscriptions
adobe_subscriptions,
)


Expand Down Expand Up @@ -955,7 +955,8 @@ def _get_order_line_items_with_deployment_id(adobe_transfer_order, order):
]
if adobe_items_with_same_offer_id:
items_without_deployment = [
item for item in adobe_items_with_same_offer_id
item
for item in adobe_items_with_same_offer_id
if not item.get("deploymentId", "")
]
if not items_without_deployment:
Expand Down Expand Up @@ -1008,7 +1009,7 @@ def get_main_agreement(product_id, authorization_id, membership_id):
GCMainAgreement or None: The main agreement in Airtable if found, None otherwise.
"""
if get_market_segment(product_id) == MARKET_SEGMENT_COMMERCIAL:
return get_gc_main_agreement( product_id, authorization_id, membership_id)
return get_gc_main_agreement(product_id, authorization_id, membership_id)
return None


Expand Down Expand Up @@ -1069,9 +1070,7 @@ def fulfill_transfer_order(mpt_client, order):
customer_deployments = adobe_client.get_customer_deployments(
authorization_id, gc_main_agreement.customer_id
)
order = save_gc_parameters(
mpt_client, order, customer_deployments
)
order = save_gc_parameters(mpt_client, order, customer_deployments)
if not _check_pending_deployments(
gc_main_agreement, existing_deployments, customer_deployments
):
Expand Down
7 changes: 3 additions & 4 deletions adobe_vipm/flows/global_customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
def get_adobe_subscriptions_by_deployment(
adobe_client, authorization_id, agreement_deployment
):

try:
adobe_subscriptions = adobe_client.get_subscriptions(
authorization_id, agreement_deployment.customer_id
Expand Down Expand Up @@ -230,7 +229,7 @@ def get_listing(mpt_client, authorization_id, price_list_id, agreement_deploymen
agreement_deployment.product_id,
price_list_id,
agreement_deployment.seller_id,
authorization_id
authorization_id,
)
except Exception as e:
logger.error(f"Error getting listings: {e}")
Expand Down Expand Up @@ -291,7 +290,7 @@ def create_gc_agreement_deployment(
adobe_customer,
customer_deployment_ids,
listing,
licensee
licensee,
):
"""
Create a global customer agreement deployment.
Expand Down Expand Up @@ -552,7 +551,7 @@ def process_agreement_deployment(
adobe_customer,
customer_deployment_ids,
listing,
licensee
licensee,
)
if not gc_agreement_id:
return
Expand Down
10 changes: 7 additions & 3 deletions adobe_vipm/flows/mpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,10 @@ def get_all_agreements(
def get_authorizations_by_currency_and_seller_id(
mpt_client, product_id, currency, owner_id
):
authorization_filter = (f"eq(product.id,{product_id})&eq(currency,{currency})"
f"&eq(owner.id,{owner_id})")
authorization_filter = (
f"eq(product.id,{product_id})&eq(currency,{currency})"
f"&eq(owner.id,{owner_id})"
)
response = mpt_client.get(f"/catalog/authorizations?{authorization_filter}")
response.raise_for_status()
return response.json()["data"]
Expand Down Expand Up @@ -488,7 +490,9 @@ def get_listing_by_id(mpt_client, listing_id):


@wrap_http_error
def get_agreement_subscription_by_external_id(mpt_client, agreement_id, subscription_external_id):
def get_agreement_subscription_by_external_id(
mpt_client, agreement_id, subscription_external_id
):
response = mpt_client.get(
f"/commerce/subscriptions?eq(externalIds.vendor,{subscription_external_id})"
f"&eq(agreement.id,{agreement_id})"
Expand Down
9 changes: 3 additions & 6 deletions adobe_vipm/flows/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,7 @@ def sync_agreement_prices(mpt_client, agreement, dry_run, adobe_client, customer
except Exception:
logger.exception(f"Cannot sync agreement {agreement_id}")
notify_agreement_unhandled_exception_in_teams(
agreement["id"],
traceback.format_exc()
agreement["id"], traceback.format_exc()
)


Expand Down Expand Up @@ -292,8 +291,7 @@ def sync_global_customer_parameters(mpt_client, adobe_client, customer, agreemen
f"{agreement["id"]}: {e}"
)
notify_agreement_unhandled_exception_in_teams(
agreement["id"],
traceback.format_exc()
agreement["id"], traceback.format_exc()
)


Expand Down Expand Up @@ -325,8 +323,7 @@ def sync_agreement(mpt_client, agreement, dry_run):
except Exception as e:
logger.error(f"Error synchronizing agreement {agreement["id"]}: {e}")
notify_agreement_unhandled_exception_in_teams(
agreement["id"],
traceback.format_exc()
agreement["id"], traceback.format_exc()
)


Expand Down
7 changes: 6 additions & 1 deletion adobe_vipm/flows/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ def has_order_line_updated(order_lines, adobe_items, quantity_field):
}
return order_line_map != adobe_items_map


def get_global_customer(order):
"""
Get the globalCustomer parameter from the order.
Expand Down Expand Up @@ -884,7 +885,11 @@ def get_deployments(order):
order,
PARAM_DEPLOYMENTS,
)
return deployments_param.get("value").split(",") if deployments_param.get("value") else []
return (
deployments_param.get("value").split(",")
if deployments_param.get("value")
else []
)


def set_deployments(order, deployments):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def info(self, message):
self.stdout.write(message, ending="\n")

def handle(self, *args, **options):
self.info("Start processing Global Customer Agreement Deployments synchronization...")
self.info(
"Start processing Global Customer Agreement Deployments synchronization..."
)
check_gc_agreement_deployments()
self.success("Processing Global Customer Agreement Deployments completed.")
11 changes: 3 additions & 8 deletions tests/adobe/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,7 @@ def test_create_new_order(
client, authorization, api_token = adobe_client_factory()

adobe_order = adobe_order_factory(
ORDER_TYPE_NEW,
external_id="mpt-order-id",
deployment_id=deployment_id
ORDER_TYPE_NEW, external_id="mpt-order-id", deployment_id=deployment_id
)

requests_mocker.post(
Expand Down Expand Up @@ -569,9 +567,7 @@ def test_create_new_order_no_deployment(
client, authorization, api_token = adobe_client_factory()

adobe_order = adobe_order_factory(
ORDER_TYPE_NEW,
external_id="mpt-order-id",
deployment_id=deployment_id
ORDER_TYPE_NEW, external_id="mpt-order-id", deployment_id=deployment_id
)

requests_mocker.post(
Expand Down Expand Up @@ -928,8 +924,7 @@ def test_create_return_order(
reference_order_id=returning_order["orderId"],
external_id=expected_external_id,
items=adobe_items_factory(
deployment_id=deployment_id,
deployment_currency_code="USD"
deployment_id=deployment_id, deployment_currency_code="USD"
),
deployment_id=deployment_id,
)
Expand Down
4 changes: 3 additions & 1 deletion tests/commands/test_check_gc_agreement_delployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@


def test_process_transfers(mocker):
mocked = mocker.patch("adobe_vipm.flows.global_customer.check_gc_agreement_deployments")
mocked = mocker.patch(
"adobe_vipm.flows.global_customer.check_gc_agreement_deployments"
)

call_command("check_gc_agreement_deployments")

Expand Down
Loading

0 comments on commit 183e845

Please sign in to comment.