Пример #1
0
    def rollback(self, bag):
        pg_db = PostgresDatabase()
        document = orm_to_json(g.tran.query(db.Document).filter_by(_deleted='infinity', _id=bag[ID]).one())
        document['type'] = 'Document'
        document['document_status'] = 'canceled'
        _id, _rev = pg_db.store(document)

        for payment in g.tran.query(db.Payments).filter_by(_deleted='infinity', document_id=_id).all():
            payment = orm_to_json(payment)
            payment['payment_status'] = 'canceled'
            controller.call('accounting.put', payment)

        for operation in g.tran.query(db.Operations).filter_by(_deleted='infinity', document_id=_id).all():
            operation = orm_to_json(operation)
            operation['operation_status'] = 'canceled'
            controller.call('operation.put', operation)
Пример #2
0
def listing(bag):
    query = g.tran.query(db.Operations._id).filter_by(
        _deleted='infinity', company_id=g.session['company_id'])
    operation_vars = vars(db.Operations)
    for operation_var in operation_vars:
        if isinstance(operation_vars[operation_var], InstrumentedAttribute):
            query = query.add_column(operation_vars[operation_var])

    if "filter" in bag:
        query = query.filter_by(**bag["filter"])

    if "order_by" in bag:
        query = query.order_by(*bag["order_by"])
    else:
        query = query.order_by(db.Operations._created.desc())

    count = query.count()
    if "limit" in bag:
        query = query.limit(bag["limit"])
    if "offset" in bag:
        query = query.offset(bag["offset"])
    if 'with_related' in bag and bag['with_related'] is True:
        query = find_relations(query)
    operations = query.all()
    operations = orm_to_json(operations)
    return {'operations': operations, 'count': count}
Пример #3
0
def listing(bag):
    query = g.tran.query(db.Payments._id).filter_by(
        _deleted='infinity', company_id=g.session['company_id'])
    payment_vars = vars(db.Payments)
    for payment_var in payment_vars:
        if isinstance(payment_vars[payment_var], InstrumentedAttribute):
            query = query.add_column(payment_vars[payment_var])

    if "filter" in bag:
        if "data" in bag["filter"] and isinstance(bag["filter"]["data"], dict):
            query = query.filter(
                db.Payments.data.contains(
                    type_coerce(bag["filter"]["data"], JSONB)))
            del bag["filter"]["data"]
        query = query.filter_by(**bag["filter"])

    if "order_by" in bag:
        query = query.order_by(*bag["order_by"])
    else:
        query = query.order_by(db.Payments._created.desc())

    count = query.count()
    if "limit" in bag:
        query = query.limit(bag["limit"])
    if "offset" in bag:
        query = query.offset(bag["offset"])
    if 'with_related' in bag and bag['with_related'] is True:
        query = find_relations(query)
    payments = query.all()
    payments = orm_to_json(payments)
    return {'payments': payments, 'count': count}
Пример #4
0
def listing(bag):
    ur = None
    table_name = bag["type"]
    table = getattr(db, table_name) if hasattr(db, table_name) else None
    # System dictionary
    if not issubclass(table, db.CouchSync):
        query = g.tran.query(table)
        return {"docs": orm_to_json(query.all()), "count": query.count()}

    return data.listing(bag)
Пример #5
0
def get(bag):
    query = g.tran.query(db.Operations._id)\
        .filter_by(_deleted='infinity', _id=bag[ID], company_id=g.session['company_id'])
    operation_vars = vars(db.Operations)
    for operation_var in operation_vars:
        if isinstance(operation_vars[operation_var], InstrumentedAttribute):
            query = query.add_column(operation_vars[operation_var])
    if 'with_related' in bag and bag['with_related'] is True:
        query = find_relations(query)
    operation = orm_to_json(query.one())
    return {'operation': operation}
Пример #6
0
def get(bag):
    query = g.tran.query(db.Payments._id)\
        .filter_by(_deleted='infinity', _id=bag[ID], company_id=g.session['company_id'])
    payment_vars = vars(db.Payments)
    for payment_var in payment_vars:
        if isinstance(payment_vars[payment_var], InstrumentedAttribute):
            query = query.add_column(payment_vars[payment_var])
    if 'with_related' in bag and bag['with_related'] is True:
        query = find_relations(query)
    payment = orm_to_json(query.one())
    return {'payment': payment}