Пример #1
0
def quickbooks_query(query_type, query_params):
    """
    args are query type string and any query_params which should be a dict
    query types include 
    purchase_order, item, check
    """
    try:
        qb = QuickBooks(**QB_LOOKUP)
        qb.begin_session()
        results = qb.quickbooks_query(query_type, query_params)
        celery_app.send_task(
            'quickbooks.tasks.process_quickbooks_entities',
            queue='quickbooks', args=[query_type, list(results)], expires=1800
        )
    finally:
        del(qb)
Пример #2
0
def qb_requests(request_list=None, app='quickbooks'):
    """
    Always send a list of requests so we aren't opening and closing file more than necessary
    ex: 
    qb_requests.delay([
        (item_key, model_name, ('ItemReceiptAddRq', receipt_instance.quickbooks_request_tuple)),
        (item_key, model_name, ('ItemReceiptAddRq', receipt_instance.quickbooks_request_tuple))
    ])
    """
    try:
        qb = QuickBooks(**QB_LOOKUP)
        qb.begin_session()

        # process request list if it exists or just get open purchase orders
        if request_list:
            for entry in request_list:
                try:
                    surrogate_key, model_name, request_body = entry
                    request_type, request_dict = request_body
                    response = qb.call(request_type, request_dictionary=request_dict)
                    if surrogate_key and request_dict:
                        celery_app.send_task(
                            'quickbooks.tasks.process_response',
                            queue='quickbooks',
                            args=[surrogate_key, model_name, response, app], expires=1800
                        )
                except Exception as e:
                    logger.error(e)

        celery_app.send_task(
            'quickbooks.tasks.process_preferences',
            queue='quickbooks',
            args=[qb.get_preferences()], expires=1800
        )
    finally:
        # making sure to end session and close file
        del(qb)