def cancel_order()

in order/utils/order_actions.py [0:0]


def cancel_order(order, cancel_reason:CancellationReasonCode, restock_items:bool = False, items=None):
    ''' Cancel an order
    NOTE: currently only cancels an order COMPLETELY

    params:
    order: the Order to cancel
    cancel_reason: CancellationReasonCode
    restock_items: set True if inventory should be restocked on successful cancel
    items: the subset of items this particular cancellation is for
    returns:
    order, data:  tuple of the order object and response data if successful.
    '''
    fb_meta = FacebookMetadata.objects.get(store=order.store)
    token = fb_meta.token_info
    url = settings.BASE_API_URL + order.ext_order_id + '/cancellations'
    body = {
        'access_token': token,
        'idempotency_key': get_idempotency_key(),
        'cancel_reason': {
            'reason_code': str(cancel_reason.name),
            'reason_description': str(cancel_reason.label),
        },
        'restock_items': restock_items,
    }
    if items:
        body['items'] = items
    res = requests.post(url, json=body)
    data = res.json()
    if not data.get("success", False):
        print(json.dumps(res.json(), indent=2))
        return None, None

    update_order_cancel_state(order, OrderCancellationState.FULLY_CANCELLED)
    update_order_state(order, OrderStatus.COMPLETED)
    return order, data