Example #1
0
def _dashboard_update(delta, quantity, date, company, type):
    """ Updates a documents dashboard """

    year, month = date.year, date.month - 1
    lookup = {key.company: company, key.year: year}

    empty = {
        key.company: company,
        key.year: year,
        key.invoices: empty_month_series(),
        key.orders: empty_month_series()
    }

    auth_field, auth_value = auth('documents')
    if auth_value:
        empty.update({auth_field: auth_value})

    if type == docs.doctype.invoice:
        doc_type = key.invoices
    elif type == docs.doctype.customer_order:
        doc_type = key.orders

    dashboard = app.data.driver.db['dashboard_documents']

    bulk = dashboard.initialize_ordered_bulk_op()

    # add dashboard if needed
    bulk.find(lookup).upsert().update({'$setOnInsert': empty})

    # update dashboard
    item = '%s.%d' % (doc_type, month)
    amount_item = '%s.%s' % (item, months_key.amount)
    quantity_item = '%s.%s' % (item, months_key.quantity)
    bulk.find(lookup).update(
        {'$inc': {
            amount_item: delta,
            quantity_item: quantity
        }})
    r = bulk.execute()

    # TODO remove or log?
    if app.config['DEBUG'] is True and os.environ.get('TESTING') is None:
        from pprint import pprint
        pprint(r)
Example #2
0
def _dashboard_update(delta, quantity, date, company, type):
    """ Updates a documents dashboard """

    year, month = date.year, date.month-1
    lookup = {key.company: company, key.year: year}

    empty = {
        key.company: company,
        key.year: year,
        key.invoices: empty_month_series(),
        key.orders: empty_month_series()
    }

    auth_field, auth_value = auth('documents')
    if auth_value:
        empty.update({auth_field: auth_value})

    if type == docs.doctype.invoice:
        doc_type = key.invoices
    elif type == docs.doctype.customer_order:
        doc_type = key.orders

    dashboard = app.data.driver.db['dashboard_documents']

    bulk = dashboard.initialize_ordered_bulk_op()

    # add dashboard if needed
    bulk.find(lookup).upsert().update({'$setOnInsert': empty})

    # update dashboard
    item = '%s.%d' % (doc_type, month)
    amount_item = '%s.%s' % (item, months_key.amount)
    quantity_item = '%s.%s' % (item, months_key.quantity)
    bulk.find(lookup).update({'$inc': {amount_item: delta, quantity_item:
                                       quantity}})
    r = bulk.execute()

    # TODO remove or log?
    if app.config['DEBUG'] is True and os.environ.get('TESTING') is None:
        from pprint import pprint
        pprint(r)
Example #3
0
def _dashboard_update(delta, quantity, date, company, type):
    """ Updates a documents dashboard """

    year, month = date.year, date.month-1
    lookup = {key.company: company, key.year: year}

    array = empty_month_series()
    empty = {
        key.year: year,
        key.payable: {
            key.debit_due: 0,
            key.month_series: array
        },
        key.receivable: {
            key.credit_due: 0,
            key.month_series: array
        }
    }

    auth_field, auth_value = auth('accounts')
    if auth_value:
        empty.update({auth_field: auth_value})

    dashboard = app.data.driver.db['dashboard_accounts']

    bulk = dashboard.initialize_ordered_bulk_op()

    # add dashboard if needed
    bulk.find(lookup).upsert().update({'$setOnInsert': empty})

    # update dashboard
    due = '%s.%s' % (type, key.credit_due
                     if type == key.receivable else key.debit_due)

    item = '%s.%s.%d' % (type, key.month_series, month)
    amount_item = '%s.%s' % (item, months_key.amount)
    quantity_item = '%s.%s' % (item, months_key.quantity)

    bulk.find(lookup).update({'$inc': {due: delta, amount_item: delta,
                                       quantity_item: quantity}})
    r = bulk.execute()

    # TODO remove or log?
    if app.config['DEBUG'] is True:
        from pprint import pprint
        pprint(r)