Exemplo n.º 1
0
def issue_listing(bag):
    countries = orm_to_json(
        g.tran.query(db.Countries).filter_by(_deleted='infinity').all())

    currencies = orm_to_json(
        g.tran.query(db.Currencies).filter_by(_deleted='infinity').all())

    return {'countries': countries, 'currencies': currencies}
Exemplo n.º 2
0
def save(bag):
    if bag.get('company_type'):
        role_supplier = g.tran.query(db.Roles).filter_by(_deleted='infinity') \
            .filter(db.Roles.data['code'].astext.cast(TEXT) == bag['company_type']).first()
        role_supplier = orm_to_json(role_supplier)
    else:
        role_supplier = g.tran.query(db.Roles).filter_by(_deleted='infinity') \
            .filter(db.Roles.data['code'].astext.cast(TEXT) == 'supplier').first()
        role_supplier = orm_to_json(role_supplier)
    bag_company = bag['main_info']

    bag_company['type'] = 'Companies'
    bag_company['user_id'] = g.user.id
    if 'roles_id' not in bag_company:
        bag_company['roles_id'] = []
    bag_company['roles_id'].append(role_supplier['_id'])
    bag_company['role'] = 0
    bag_company["company_status"] = bag_company["company_status"] if "company_status" in bag_company else 'waiting'
    bag_company["company_type"] = role_supplier['data']['code']
    company = controller.call(controller_name='data.put', bag=bag_company)

    bag_bank = bag['bank_info']
    bag_bank['company_id'] = company['id']
    bag_bank['type'] = 'Companybank'
    bank = controller.call(controller_name='data.put', bag=bag_bank)

    bag_employee = {}
    if 'roles_id' not in bag_employee:
        bag_employee['roles_id'] = []
    if bag.get('company_type') and bag['company_type'] == 'purchaser':
        role = g.tran.query(db.Roles._id).filter_by(_deleted='infinity') \
            .filter(db.Roles.data['code'].astext.cast(TEXT) == 'purhead').first()
    else:
        role = g.tran.query(db.Roles._id).filter_by(_deleted='infinity') \
            .filter(db.Roles.data['code'].astext.cast(TEXT) == 'head').first()
    bag_employee['user_id'] = g.user.id
    bag_employee['roles_id'] = role
    bag_employee['company_id'] = company['id']
    bag_employee['head'] = True
    entity.add({CRUD: db.Companyemployees, BOBJECT: bag_employee})

    bag_prequal = bag['prequal_info']
    bag_prequal['company_id'] = company['id']
    bag_prequal['type'] = 'Companyqualification'

    # bag_prequal['data'] = {}

    if 'certificates' in bag_prequal:
        bag_prequal['data']['certificates'] = bag_prequal['certificates']
    if 'supplies' in bag_prequal:
        bag_prequal['data']['supplies'] = bag_prequal['supplies']
    if 'experiences' in bag_prequal:
        bag_prequal['data']['experiences'] = bag_prequal['experiences']
    if 'finances' in bag_prequal:
        bag_prequal['data']['finances'] = bag_prequal['finances']
    prequal = controller.call(controller_name='data.put', bag=bag_prequal)
    return
Exemplo n.º 3
0
def dashboard(bag):
    query = g.tran.query(db.Journal) \
        .filter_by(_deleted='infinity')

    if 'status' in bag:
        query = query.filter(db.Journal.status == bag['status'])

    if 'date_start' in bag:
        query = query.filter(db.Journal.date >= bag['date_start'])

    if 'date_end' in bag:
        query = query.filter(db.Journal.date <= bag['date_end'])

    incoming_query = query.filter_by(status='Входящий')
    outgoing_query = query.filter_by(status='Исходящий')
    spoiled_query = query.filter_by(status='испорчен')
    refused_query = query.filter_by(status='Отказано')

    incoming = orm_to_json(incoming_query.all())
    incoming_sum = 0
    incoming_count = incoming.__len__()
    for inc in incoming:
        incoming_sum += inc['summ']
    outgoing = orm_to_json(outgoing_query.all())
    outgoing_sum = 0
    outgoing_count = outgoing.__len__()
    for out in outgoing:
        outgoing_sum += out['summ']
    spoiled = orm_to_json(spoiled_query.all())
    spoiled_sum = 0
    spoiled_count = spoiled.__len__()
    for inc in spoiled:
        spoiled_sum += inc['summ']
    refused = orm_to_json(refused_query.all())
    refused_sum = 0
    refused_count = refused.__len__()
    for ref in refused:
        refused_sum += ref['summ']

    return {
        'data': {
            'incoming': incoming_sum,
            'incoming_count': incoming_count,
            'outgoing': outgoing_sum,
            'outgoing_count': outgoing_count,
            'spoiled': spoiled_sum,
            'spoiled_count': spoiled_count,
            'refused': refused_sum,
            'refused_count': refused_count
        }
    }
Exemplo n.º 4
0
def get(bag):
    pur_comp = aliased(db.Companies)
    sup_comp = aliased(db.Companies)

    cons, pur_company, adv, section, procur, sup_company = g.tran.query(
        db.Consignment, pur_comp, db.Advert, db.DirSection, db.DirProcurement, sup_comp) \
        .outerjoin(pur_comp, and_(db.Consignment.purchaser_company_id == pur_comp._id,
                                  pur_comp._deleted == INFINITY)) \
        .outerjoin(db.Advert, and_(db.Consignment.advert_id == db.Advert._id,
                                   db.Advert._deleted == INFINITY)) \
        .outerjoin(db.DirSection, and_(db.Advert.dirsection_id == db.DirSection._id,
                                       db.DirSection._deleted == INFINITY)) \
        .outerjoin(sup_comp, and_(db.Consignment.supplier_company_id == sup_comp._id,
                                  sup_comp._deleted == INFINITY)) \
        .filter(db.Consignment.id == bag['id']).first()

    consignment = orm_to_json(cons)
    pur_company_bank = g.tran.query(db.Companybank).filter_by(_deleted='infinity', company_id=pur_company._id).first()
    if pur_company_bank:
        dirbank = g.tran.query(db.DirBank).filter_by(_deleted='infinity', _id=pur_company_bank.dirbank_id).first()
        if dirbank:
            pur_company_bank.dirbank = dirbank
        pur_company.bank = pur_company_bank
    sup_company_bank = g.tran.query(db.Companybank).filter_by(_deleted='infinity', company_id=sup_company._id).first()
    if sup_company_bank:
        dirbank = g.tran.query(db.DirBank).filter_by(_deleted='infinity', _id=sup_company_bank.dirbank_id).first()
        if dirbank:
            sup_company_bank.dirbank = dirbank
        sup_company.bank = sup_company_bank

    consignment['pur_company'] = pur_company if pur_company else ''
    consignment['sup_company'] = sup_company if sup_company else ''

    ann = orm_to_json(adv)
    ann['dirprocurement_name'] = procur.name if procur else ''
    consignment['announce'] = ann

    cons_lots = g.tran.query(db.ConsignmentLots, db.Advert_lot, db.DirCategory) \
        .outerjoin(db.Advert_lot, and_(db.ConsignmentLots.advert_lot_id == db.Advert_lot._id,
                                       db.Advert_lot._deleted == INFINITY)) \
        .outerjoin(db.DirCategory, db.Advert_lot.dircategory_id == db.DirCategory.id)\
        .filter(db.ConsignmentLots.consignment_id == cons.id).all()
    lots = []
    for cl, al, cat in cons_lots:
        lot = orm_to_json(al)
        lot['dircategory_name'] = cat.name if cat else ''
        lots.append(lot)
    consignment['lots'] = lots

    return {'doc': consignment}
Exemplo n.º 5
0
def listing(bag):
    query = g.tran.query(db.DirCoate)
    if bag.get('name'):
        if bag.get('lang') == 'ru':
            query = query.filter(
                db.DirCoate.name.ilike('%' + bag.get('name') + '%'))
            del bag['name']
        elif bag.get('lang') == 'kg':
            query = query.filter(
                db.DirCoate.name_kg.ilike('%' + bag.get('name') + '%'))
            del bag['name']
        elif bag.get('lang') == 'en':
            query = query.filter(
                db.DirCoate.name_en.ilike('%' + bag.get('name') + '%'))
            del bag['name']
    if bag.get('center'):
        query = query.filter(db.DirCoate.center == bag.get('center'))
    if bag.get('code'):
        query = query.filter(db.DirCoate.code == bag.get('code'))
    if bag.get('parent_id'):
        query = query.filter(db.DirCoate.parent_id == bag.get('parent_id'))
    questions = query.all()
    items = []
    for _questions in questions:
        item = orm_to_json(_questions)
        items.append(item)

    return {'docs': items}
Exemplo n.º 6
0
def mainlisting(bag):
    query = g.tran.query(db.New).filter_by(_deleted='infinity')\
        .filter(db.New.is_active == True)
    query.section = None
    if bag.get('name'):
        if bag.get('lang') == 'ru':
            query = query.filter(
                db.New.name_ru.ilike('%' + bag.get('name') + '%'))
        elif bag.get('lang') == 'kg':
            query = query.filter(
                db.New.name_kg.ilike('%' + bag.get('name') + '%'))
    if bag.get('created_from'):
        query = query.filter(db.New.created_from >= bag.get('created_from'))
    if bag.get('created_to'):
        query = query.filter(db.New.created_to <= bag.get('created_to'))
    if bag.get('is_active'):
        active = bag.get('is_active')
        if active == 'yes':
            query = query.filter_by(is_active=True)
        elif active == 'no':
            query = query.filter_by(is_active=False)

    section = g.tran.query(db.Sectionsofpublication.name_ru) \
        .select_from(db.Sectionsofpublication) \
        .filter_by(_deleted='infinity').filter(
        db.Sectionsofpublication._id == db.New.sectionsofpublication_id).as_scalar() \
        .label('section')

    query = query.add_columns(section)
    query = query.order_by(db.New.created_from.desc())
    query = query.limit(10).all()
    return {'docs': orm_to_json(query)}
Exemplo n.º 7
0
def userlist(bag):
    query = g.tran.query(db.User.id).select_from(db.User)
    if "filter" in bag:
        if bag['filter'].get('search', ''):
            query = query.filter(
                or_(
                    db.User.fullname.ilike(u"%{}%".format(
                        bag["filter"]["search"])),
                    db.User.email.ilike(u"%{}%".format(
                        bag["filter"]["search"]))))
            del bag["filter"]["search"]
        query = query.filter_by(**bag["filter"])
    doc_vars = vars(db.User)
    for var in doc_vars:
        if var != 'password' and var != 'secure' and isinstance(
                doc_vars[var], InstrumentedAttribute):
            query = query.add_column(doc_vars[var])
    if "limit" in bag:
        query = query.limit(bag.get('limit', 10))
    if "offset" in bag:
        query = query.offset(bag["offset"])
    users = []
    for u in query.all():
        usr = orm_to_json(u)
        usr['info'] = u'{} {}'.format(u.fullname, u.email)
        users.append(usr)

    return {'users': users}
Exemplo n.º 8
0
 def load(self, idx, rev=None, revs=False, as_dict=True, locked=False):
     if not self.contains(idx, rev):
         raise self.NotFound(idx)
     ti = g.tran.query(db.TableId).filter_by(_id=idx)
     if locked:
         ti = ti.with_for_update(of=db.TableId)
     ti = ti.first()
     table = self.__get_object(ti.table_name)
     doc = g.tran.query(table).filter_by(_id=idx)
     if rev:
         doc = doc.filter_by(_rev=rev)
     else:
         doc = doc.filter_by(_deleted='infinity')
     doc = doc.first()
     if not doc:
         raise self.NotFound(idx)
     setattr(doc, 'type', ti.table_name)
     d = orm_to_json(doc)
     d['type'] = ti.table_name
     del d['_created']
     del d['_deleted']
     if doc._deleted != 'infinity':
         d['_deleted'] = True
     if revs:
         d['_revisions'] = {'ids': []}
         sql = g.tran.query(table).filter_by(_id=idx).order_by(
             table._created.desc())
         for r in sql:
             d['_revisions']['ids'] = r._rev.split('-')[1]
             if not d['_revisions'].get('start'):
                 d['_revisions']['start'] = r._rev.split('-')[0]
     if as_dict:
         return d
     return doc
Exemplo n.º 9
0
def pur_submit(bag):
    con_status = ["Schedule", "Review"]
    contract = g.tran.query(db.Contract) \
        .filter_by(id=bag['id']) \
        .filter(and_(db.Contract.status.in_(con_status),
                     db.Contract.purchaser_company_id == g.company._id)) \
        .first()

    if not contract:
        raise CbsException(GENERIC_ERROR, u'Не найден договор')

    contract.date_pur_submit = datetime.datetime.now()
    contract.status = 'Pending'

    if bag.get('comment'):
        contract.comment.append({
            "pur_company": g.company._id,
            "comment": bag['comment'],
            "date": datetime.datetime.now()
        })

    # save
    entity.add({CRUD: db.Contract, BOBJECT: orm_to_json(contract)})

    return
Exemplo n.º 10
0
def getsession(id):
    user = g.tran.query(db.User).filter_by(id=int(id)).first()
    company = None
    docs = None
    if user.default_company is not None and user.default_company != "":
        uc = g.tran.query(db.Companies).filter_by(
            _deleted='infinity', _id=user.default_company).first()
        if uc:
            company = orm_to_json(uc)
            company['roles'] = g.tran.query(db.Roles).filter_by(_deleted='infinity') \
                .filter(db.Roles._id.in_(company["roles_id"])).first()
    user_data = {
        'id': user.id,
        'username': user.username,
        'email': user.email,
        'fullname': user.fullname,
        'phone': user.phone,
        'inn': user.inn,
        'role': user.role,
        'rec_date': user.rec_date,
        'default_company': user.default_company,
        'data': user.data
    }
    token = redis_session.open_session({'user_id': user.id})
    session = redis_session.get_session(token)
    redis_session.update_session(token, session)
    return make_json_response({
        'token': token,
        'user': user_data,
        'company': company,
        'docs': docs
    })
Exemplo n.º 11
0
def listing(bag):
    query = g.tran.query(db.User.id).select_from(db.User)
    if "filter" in bag:
        if 'filter' in bag and 'first_name' in bag['filter']:
            query = query.filter(db.User.first_name.ilike(u"%{}%".format(bag["filter"]["first_name"])))
            del bag["filter"]["first_name"]
        if 'filter' in bag and 'last_name' in bag['filter']:
            query = query.filter(db.User.last_name.ilike(u"%{}%".format(bag["filter"]["last_name"])))
            del bag["filter"]["last_name"]
        if 'filter' in bag and 'middle_name' in bag['filter']:
            query = query.filter(db.User.middle_name.ilike(u"%{}%".format(bag["filter"]["middle_name"])))
            del bag["filter"]["middle_name"]
        query = query.filter_by(**bag["filter"])
    doc_vars = vars(db.User)
    for var in doc_vars:
        if var != 'password' and var != 'secure' and isinstance(doc_vars[var], InstrumentedAttribute):
            query = query.add_column(doc_vars[var])
    query = query.order_by(asc(db.User.id))
    count = query.count()
    if "limit" in bag:
        query = query.limit(bag["limit"])
    if "offset" in bag:
        query = query.offset(bag["offset"])

    return {'users': orm_to_json(query.all()), 'count': count}
Exemplo n.º 12
0
def listing(bag):
    # if user is operator
    if g.user.role == 1:
        notifications = g.tran.query(
            db.AdminNotification).filter_by(_deleted='infinity').all()
    else:
        sequence = ["all"]
        # user_company = g.tran.query(db.Companies).filter_by(_id=g.company._id, _deleted='infinity').one()
        # if user_company and user_company.company_type:
        #     role_id = user_company.roles_id[0]
        #     sequence.append(role_id)
        # else:
        #     raise CbsException(USER_NOT_AUTHORIZED)

        notifications = g.tran.query(
            db.AdminNotification).filter_by(_deleted='infinity').filter(
                db.AdminNotification.role_id.in_(sequence)).all()

    notifications = orm_to_json(notifications)
    # builds content without styles
    for n in notifications:
        content = ""
        if n.get('content'):
            for b in n['content']['blocks']:
                content += b['text']
            n['content'] = content
    return {"docs": notifications}
Exemplo n.º 13
0
def get(bag):
    label = ""
    dirsection = g.tran.query(db.DirSection).filter_by(_deleted='infinity',
                                                       _id=bag['_id']).first()
    specifications = g.tran.query(db.Specification)\
        .filter(db.Specification.id.in_(dirsection.dircategories_id)).all()
    specifications = orm_to_json(specifications)
    for spec in specifications:
        dircategory = g.tran.query(
            db.DirCategory).filter_by(id=spec['dircategory_id']).first()
        if g.lang == "ru":
            label = dircategory.name
        elif g.lang == "en":
            label = dircategory.name_en if dircategory.name_en and dircategory.name_en != 'null' else dircategory.name
        elif g.lang == "kg":
            label = dircategory.name_kg if dircategory.name_kg and dircategory.name_kg != 'null' else dircategory.name
        dirc = {
            "code": dircategory.code,
            "data": dircategory.data,
            "id": dircategory.id,
            "name": label,
            "parent_id": dircategory.parent_id
        }
        spec['dircategory'] = dirc
    return {'docs': specifications}
Exemplo n.º 14
0
def listing(bag):
    query = g.tran.query(db.Advert)
    if bag.get('name'):
        if bag.get('lang') == 'ru':
            query = query.filter(
                db.Advert.name_ru.ilike('%' + bag.get('name') + '%'))
        elif bag.get('lang') == 'kg':
            query = query.filter(
                db.Advert.name_kg.ilike('%' + bag.get('name') + '%'))
    if bag.get('created_from'):
        query = query.filter(db.Advert.created_from >= bag.get('created_from'))
    if bag.get('created_to'):
        query = query.filter(db.Advert.created_to <= bag.get('created_to'))
    if bag.get('is_active'):
        active = bag.get('is_active')
        if active == 'yes':
            query = query.filter_by(is_active=True)
        elif active == 'no':
            query = query.filter_by(is_active=False)
    query = query.order_by(desc(db.Advert.created_from))
    adverts = query.all()
    items = []
    for _adverts in adverts:
        item = orm_to_json(_adverts)
        items.append(item)

    return {'list': items}
Exemplo n.º 15
0
def publish(bag):
    bag_advert = bag['advert']
    result = None

    advert = g.tran.query(db.Advert) \
        .filter_by(_deleted='infinity', _id=bag_advert['_id'], status='Draft') \
        .first()

    if not advert:
        raise CbsException(GENERIC_ERROR, u'Объявление не найдено')
    Force_status_list = [
        'ENSURE_SECURITY_KR', 'EARLY_ELECTIONS', 'LOCALIZE_FORCE_MAJEURE',
        'THREE_PERCENT_SERVICE'
    ]
    dirprocumenet = g.tran.query(db.DirProcurement) \
        .filter_by(_deleted='infinity').filter(db.DirProcurement.code.in_(Force_status_list),
                                               db.DirProcurement._id == advert.dirprocurement_id) \
        .first()
    if not dirprocumenet:
        result = controller.call(controller_name='announce.put',
                                 bag=bag_advert)

    advert = orm_to_json(advert)

    advert['type'] = 'Advert'
    advert['code'] = result.get('orderNumber',
                                get_code()) if result else get_code()
    advert['published_date'] = datetime.datetime.now()
    advert['update_date'] = datetime.datetime.now()
    advert['status'] = 'Published'

    controller.call(controller_name='data.put', bag=advert)

    return
Exemplo n.º 16
0
def listing(bag):
    sql = g.tran.query(db.Companydocument, db.Companies, db.DirDocument) \
        .outerjoin(db.Companies, and_(db.Companydocument.company_id == db.Companies._id,
                                      db.Companies._deleted == INFINITY)) \
        .outerjoin(db.DirDocument, and_(db.Companydocument.dirdocument_id == db.DirDocument._id,
                                        db.DirDocument._deleted == INFINITY)) \
        .filter(db.Companydocument._deleted == INFINITY)

    if hasattr(g, 'company'):
        sql = sql.filter(db.Companydocument.company_id == g.company._id)
    if bag.get('dirdocument_id', ''):
        sql = sql.filter(
            db.Companydocument.dirdocument_id == bag['dirdocument_id'])

    comp_docs = []
    sql = sql.order_by(db.Companydocument.date_start.desc(),
                       db.Companydocument._created.desc())

    if 'limit' in bag:
        sql = sql.limit(bag['limit'])

    for cd, comp, doc in sql.all():
        d = orm_to_json(cd)
        d['company'] = comp.name
        d['inn'] = comp.inn
        d['document'] = doc.name
        d['debt'] = cd.debt
        d['debt_status'] = u'Имеется' if cd.debt else u'Не имеется'
        comp_docs.append(d)
    return {'docs': comp_docs}
Exemplo n.º 17
0
def listing(bag):
    invoices = []
    pur_comp = aliased(db.Companies)
    sup_comp = aliased(db.Companies)

    if not bag.get('contract_id'):
        raise CbsException(GENERIC_ERROR, u'Укажите id договора')

    sql = g.tran.query(db.Invoice, pur_comp.short_name.label('pur_company'), db.DirSection,
                       sup_comp.short_name.label('sup_company')) \
        .outerjoin(pur_comp, and_(db.Invoice.purchaser_company_id == pur_comp._id,
                                  pur_comp._deleted == INFINITY)) \
        .outerjoin(db.Advert, and_(db.Invoice.advert_id == db.Advert._id,
                                   db.Advert._deleted == INFINITY)) \
        .outerjoin(db.DirSection, and_(db.Advert.dirsection_id == db.DirSection._id,
                                       db.DirSection._deleted == INFINITY)) \
        .outerjoin(sup_comp, and_(db.Invoice.supplier_company_id == sup_comp._id,
                                  sup_comp._deleted == INFINITY)) \
        .filter(or_(db.Invoice.purchaser_company_id == g.company._id,
                    db.Invoice.supplier_company_id == g.company._id)) \
        .filter(db.Invoice.contract_id == bag['contract_id'])\
        .order_by(db.Invoice.date)\
        .order_by(db.Invoice.created_date)

    for ct, pur_company, section, sup_company in sql.all():
        contract = orm_to_json(ct)
        contract['pur_company'] = pur_company if pur_company else ''
        contract['sup_company'] = sup_company if sup_company else ''
        contract['dirsection'] = section.name if section else ''
        invoices.append(contract)

    return {'docs': invoices}
Exemplo n.º 18
0
def get(self, bag):
    query = g.tran.query(db.Companies) \
        .filter_by(_deleted='infinity', _id=bag['id'])
    doc_vars = vars(db.Companies)
    for var in doc_vars:
        if isinstance(doc_vars[var], InstrumentedAttribute):
            query = query.add_column(doc_vars[var])

    if 'with_related' in bag and bag['with_related'] is True:
        company_status_value = g.tran.query(
            func.row_to_json(text('enums.*'))).select_from(db.Enums) \
            .filter_by(_deleted='infinity', name='company_status') \
            .filter(db.Enums.data['key'].cast(TEXT) == cast(db.Companies.company_status, TEXT)) \
            .as_scalar().label('company_status_value')

        company_type_value = g.tran.query(
            func.row_to_json(text('enums.*'))).select_from(db.Enums) \
            .filter_by(_deleted='infinity', name='company_type') \
            .filter(db.Enums.data['key'].cast(TEXT) == cast(db.Companies.company_type, TEXT)) \
            .as_scalar().label('company_type_value')

        entry_user = g.tran.query(func.json_build_object(
            "id", db.User.id, "username", db.User.username, "email", db.User.email, "rec_date", db.User.rec_date,
            "data", db.User.data, "role", db.User.role)).select_from(db.User).filter_by(
            id=db.Companies.entry_user_id) \
            .as_scalar().label('entry_user')

        typeofownership = g.tran.query(func.row_to_json(text('typeofownership.*'))).select_from(db.Typeofownership) \
            .filter_by(_deleted='infinity', _id=db.Companies.typeofownership_id).as_scalar() \
            .label('typeofownership')

        dircountry = g.tran.query(func.row_to_json(text('dircountry.*'))).select_from(db.DirCountry) \
            .filter_by(_deleted='infinity', _id=db.Companies.dircountry_id).as_scalar() \
            .label('dircountry')

        dircoate = g.tran.query(func.row_to_json(text('dircoate.*'))).select_from(db.DirCoate) \
            .filter_by(_deleted='infinity', _id=db.Companies.dircoate_id).as_scalar() \
            .label('dircoate')

        roles = g.tran.query(func.jsonb_agg(func.row_to_json(text('roles.*')))).select_from(db.Roles) \
            .filter_by(_deleted='infinity') \
            .filter(type_coerce(db.Companies.roles_id).has_any(array([db.Roles._id]))) \
            .as_scalar().label('roles')

        company_users = g.tran.query(db.Companyemployees.user_id).filter_by(_deleted='infinity',
                                                                            company_id=bag['id']).all()
        company_users = []
        for user_id in company_users:
            user = g.tran.query(func.json_build_object(
                "id", db.User.id, "username", db.User.username, "email", db.User.email, "rec_date", db.User.rec_date,
                "data", db.User.data, "role", db.User.role)).select_from(db.User) \
                .filter_by(id=user_id).first()
            company_users.append(user)

        query = query.add_columns(company_status_value, company_type_value, entry_user, company_users, typeofownership,
                                  dircountry, roles, dircoate)

    company = query.one()
    return {'doc': orm_to_json(company)}
Exemplo n.º 19
0
def update(bag):
    company = g.tran.query(db.Companies).filter_by(_deleted='infinity', _id=bag['id']).first()

    if company:
        company = orm_to_json(company)
        company['type'] = 'Companies'
        company['short_name'] = bag.get('short_name', '')
        controller.call(controller_name='data.put', bag=company)
Exemplo n.º 20
0
def regulationsListing():
    query = g.tran.query(db.Regulation)
    regulations = query.all()
    items = []
    for _regulations in regulations:
        item = orm_to_json(_regulations)
        items.append(item)
    return make_json_response({'regulations': items})
Exemplo n.º 21
0
def activate(bag):
    if 'id' in bag:
        DirDoc = g.tran.query(db.DirDoc).filter_by(id=bag['id']).first()
        DirDoc = orm_to_json(DirDoc)
        if 'active' in bag:
            DirDoc['type'] = 'DirDoc'
            DirDoc['is_active'] = bag['active']
            return entity.add({CRUD: db.DirDoc, BOBJECT: DirDoc})
Exemplo n.º 22
0
def activate(bag):
    if '_id' in bag:
        new = g.tran.query(db.New).filter_by(_deleted='infinity', _id=bag['_id']).first()
        new = orm_to_json(new)
        if 'active' in bag:
            new['type'] = 'New'
            new['is_active'] = bag['active']
            return controller.call(controller_name='data.put', bag=new)
Exemplo n.º 23
0
def put_answer(bag):
    answer = g.tran.query(db.Question).filter_by(id=bag.get('id')).first()
    answer = answer if answer else db.Question()
    answer.answer = bag.get('answer')
    answer.is_active = bag.get('is_active')
    g.tran.add(answer)

    return {'answer': orm_to_json(answer)}
Exemplo n.º 24
0
def sup_submit(bag):
    # check_otp(g.user.phone, bag['otpcode'])

    contract = g.tran.query(db.Contract) \
        .filter_by(id=bag['id']) \
        .filter(and_(db.Contract.status == 'Pending',
                     db.Contract.supplier_company_id == g.company._id)) \
        .first()

    if not contract:
        raise CbsException(GENERIC_ERROR, u'Не найден договор')

    contract.date_sup_submit = datetime.datetime.now()
    contract.status = 'Active'

    sql = g.tran.query(db.Advert_lot, db.Application) \
        .outerjoin(db.Application, and_(db.Advert_lot._id == db.Application.advert_lot_id,
                                        db.Application._deleted == INFINITY)) \
        .filter(db.Advert_lot.advert_id == contract.advert_id,
                db.Advert_lot._deleted == INFINITY)
    for lot, appl in sql.all():
        if appl:
            appl.lot_id = lot.lot_id
            appl.product_id = lot.product_id
            g.tran.add(appl)

    if bag.get('comment'):
        contract.comment.append({
            "pur_company": g.company._id,
            "comment": bag['comment'],
            "date": datetime.datetime.now()
        })
    advert = g.tran.query(db.Advert).filter_by(_deleted='infinity').filter(
        db.Advert._id == contract.advert_id).first()
    Force_status_list = [
        'ENSURE_SECURITY_KR', 'EARLY_ELECTIONS', 'LOCALIZE_FORCE_MAJEURE',
        'THREE_PERCENT_SERVICE'
    ]
    dirprocumenet = g.tran.query(db.DirProcurement)\
        .filter_by(_deleted='infinity').filter(and_(db.DirProcurement.code.in_(Force_status_list),
                                               db.DirProcurement._id == advert.dirprocurement_id))\
        .first()
    if dirprocumenet:
        controller.call(controller_name='announce.sendContract',
                        bag={
                            'contract': contract,
                            'code': dirprocumenet.code
                        })
    else:
        controller.call(controller_name='announce.sendAnnounce',
                        bag={
                            'advert_id': contract.advert_id,
                            'contract_code': contract.code
                        })

    entity.add({CRUD: db.Contract, BOBJECT: orm_to_json(contract)})
    return
Exemplo n.º 25
0
def get(bag):
    if hasattr(g, 'company'):
        roles = g.tran.query(db.Roles).filter_by(_deleted='infinity').filter(
            db.Roles.parent_id.in_(g.company.roles_id))
        count = roles.count()
        roles = orm_to_json(roles.all())
    else:
        raise CbsException(GENERIC_ERROR, u'У вас не выбрана организация')
    return {'docs': roles, 'count': count}
Exemplo n.º 26
0
def update_status(bag, status_list, new_status):
    company = g.tran.query(db.Companies).filter_by(_deleted='infinity', _id=bag['id']).first()

    if company and company.company_status in status_list:
        company = orm_to_json(company)
        company['type'] = 'Companies'
        company['company_status'] = new_status
        if new_status == 'rejected':
            company['reason'] = bag.get('reason')
        controller.call(controller_name='data.put', bag=company)
Exemplo n.º 27
0
def test(bag):
    advert_lots_ids = g.tran.query(db.Advert_lot._id) \
        .filter_by(_deleted='infinity', advert_id='e83b1f46-8c20-413d-a9d2-c71cf7c1f29f').all()
    advert_lots_ids = orm_to_json(advert_lots_ids)
    items = []
    for advert_lot in advert_lots_ids:
        application_count = g.tran.query(db.Application) \
            .filter_by(_deleted='infinity', advert_lot_id=advert_lot['_id'], status='Published').count()
        items.append(application_count)
    return {'items': items}
Exemplo n.º 28
0
def put(bag):
    regulations = g.tran.query(db.Regulation).filter_by(id=bag.get('id')).first()
    regulations = regulations if regulations else db.Regulation()
    regulations.departmentdocument_id = bag.get('departmentdocument_id')
    regulations.name_ru = bag.get('name_ru')
    regulations.name_kg = bag.get('name_kg')
    regulations.file = bag.get('file')
    g.tran.add(regulations)

    return {'regulations': orm_to_json(regulations)}
Exemplo n.º 29
0
def get(bag):
    query = g.tran.query(db.User).filter_by(id=bag['id']).one()
    query = orm_to_json(query)
    query['citizenship'] = {}
    query['nationality'] = {}
    query['citizenship'] = g.tran.query(db.Citizenship).filter_by(_deleted='infinity',
                                                                  _id=query['citizenship_id']).first()
    query['nationality'] = g.tran.query(db.Nationality).filter_by(_deleted='infinity',
                                                                  _id=query['nationality_id']).first()
    return {'user': query}
Exemplo n.º 30
0
    def get(self, bag):
        query = g.tran.query(db.Document).filter_by(_deleted='infinity', _id=bag[ID])
        query = query.filter(
            or_(db.Document.data.contains(type_coerce({"user_id": g.user.id}, JSONB)),
                db.Document.data.contains(type_coerce({"executor_id": g.user.id}, JSONB)),
                type_coerce(db.Document.approval['roles_id'], JSONB).has_any(array(g.user.roles_id)) if len(
                    g.user.roles_id) > 0 else None))

        doc = query.one()
        return {'docs': orm_to_json(doc)}