def listing(bag): inn = g.user.company['companyInn'] if not inn: raise CbsException(GENERIC_ERROR, u'ИНН организации отсутствует') year = datetime.date.today().year data = {'companyInn': inn, 'year': year} resp = portal_post('plan', data) return {'data': resp}
def getplan(bag): data = { "companyInn": '02505200110080', "okgz": '44512400-6', "year": datetime.date.today().year } response = portal_post('plan/okgz', data) if response: return {'docs': response}
def get_from_portal(bag): params = {'companyInn': g.company.inn, 'userPin': g.user.inn, 'username': g.user.username} resp = portal_post('company', data=params) if resp.get('bank', '') and resp['bank'].get('bik', ''): bank = g.tran.query(db.DirBank).filter(db.DirBank._deleted == INFINITY, db.DirBank.bik == resp['bank']['bik']).first() if bank: resp['bank']['dir_bank'] = bank return {'doc': resp}
def send_request(bag): comp = g.tran.query(db.Companies).filter_by(_deleted='infinity', _id=g.company._id).first() if comp: sf_doc = g.tran.query(db.DirDocument).filter_by(_deleted='infinity') \ .filter(db.DirDocument.data['type'].astext == 'sf').first() tax_doc = g.tran.query(db.DirDocument).filter_by(_deleted='infinity') \ .filter(db.DirDocument.data['type'].astext == 'tax').first() p_resp = utils.portal_post('debt', data={'companyInn': comp.inn}) sf, sf_debt = prepare_comp_doc(p_resp.get('sf', {}), comp._id, sf_doc._id, bag.get('advert_id', '')) save(sf) tax, tax_debt = prepare_comp_doc(p_resp.get('gns', {}), comp._id, tax_doc._id, bag.get('advert_id', '')) save(tax) return listing(bag)
def sendContract(bag): check_role() contract = bag['contract'] sql = g.tran.query(db.ContractLots, db.Application, db.Product, db.Advert_lot) \ .filter(db.ContractLots.contract_id == contract.id) \ .filter(db.Application._id == db.ContractLots.application_id) \ .filter(db.Product._id == db.Application.company_product_id) \ .filter(db.Advert_lot._id == db.Application.advert_lot_id) purcompany = g.tran.query(db.Companies).filter_by( _deleted='infinity', _id=contract.purchaser_company_id).first() supcompany = g.tran.query(db.Companies).filter_by( _deleted='infinity', _id=contract.supplier_company_id).first() user_purcompany = g.tran.query( db.User).filter(db.User.id == purcompany.user_id).first() user_supcompany = g.tran.query( db.User).filter(db.User.id == supcompany.user_id).first() purdata = { 'companyInn': purcompany.inn, 'userPin': user_purcompany.inn, 'username': user_purcompany.username } presp = portal_post('user', purdata) supdata = { 'companyInn': supcompany.inn, 'userPin': user_supcompany.inn, 'username': user_supcompany.username } sresp = portal_post('user', supdata) for cl, appl, prod, adlot in sql.all(): specifications = getSpecDict({'id': appl.advert_lot_id}) specs = getProductSpecs({'id': appl.company_product_id}) dircategory = g.tran.query(db.DirCategory).filter( db.DirCategory.id == adlot.dircategory_id).first() consignments = g.tran.query(db.Consignment).filter( db.Consignment.contract_id == contract.id).first() data = { "dateCreated": contract.created_date.strftime('%Y-%m-%d'), "contractDate": contract.date_sup_submit.strftime('%Y-%m-%d'), "contractNumber": contract.code, "proc_company_id": presp['company']['id'], "supplier_company_id": sresp['company']['id'], "orderType": "PRODUCT", "singleSourceContract": bag['code'], "products": [{ "priceOfUnit": appl.unit_price, "techSpecification": specifications['specifications'], "model": specs['model'], "countryOfOriginId": specs['country'], "product": { "specifications": specifications['specifications'], "okgz": dircategory.code, "measurementUnit": int(specifications['dirunitcode'].code), "amount": adlot.quantity, "priceForOneUnit": adlot.unit_price } }], "payments": [{ "type": "PREPAYMENT", "dateFrom": str(consignments.date_from), "dateTo": str(consignments.date_to), "doc": "PAYMENT_INVOICE" }], "schedules": [{ "deliveryPlace": adlot.delivery_place, "dateFrom": str(consignments.date_from), "dateTo": str(consignments.date_to), "deliveryCondition": "г.Талас ул.Сарыгулова № 59" }] } return portal_post('extraContract/publish', data)
def sendAnnounce(bag): check_role() advert = g.tran.query(db.Advert).filter_by(_deleted='infinity', _id=bag['advert_id']).first() contract = g.tran.query( db.Contract).filter_by(code=bag['contract_code']).first() if advert.status != 'Results': raise CbsException( GENERIC_ERROR, u'Ваше объявление не в статусе "Оценка предложении"') advert_lots = g.tran.query(db.Advert_lot).filter_by( _deleted='infinity', advert_id=advert._id).all() items = [] lots_id = [] evaluation = { "date": None, "orderId": 1, "comment": "", "lotEvaluations": [] } for lot in advert_lots: evaluation['lotEvaluations'].append({ "lotId": lot.lot_id, "canceled": False, "note": "" }) lots_id.append(lot._id) lot_applications = g.tran.query(db.Application) \ .filter(and_(db.Application.advert_lot_id.in_(lots_id), db.Application._deleted == INFINITY)) \ .order_by(db.Application.total, db.Application._created).all() lot_applications = orm_to_json(lot_applications) c = map(operator.itemgetter("company_id"), lot_applications) companies = [el for el, _ in groupby(c)] for company in companies: item = { "companyId": g.user.company['id'], "orderId": 1, "lotIds": [], "priceTables": [], "dateComplated": None, "status": 3, "contractNumber": contract.code, "dateOfContract": str(contract.date_sup_submit), "currencyId": None, "ratePerSom": None, "confirmed": None, "confirmedQualification": None, "confirmedQualificationText": None } lots = [x for x in lot_applications if x['company_id'] == company] for lot in lots: specs = getProductSpecs({'id': lot['company_product_id']}) item['lotIds'].append(lot['lot_id']) item["dateCreated"] = str(lot['_created']) item['priceTables'].append({ "priceOfProduct": [{ "priceOfUnit": lot['unit_price'], "techSpecification": specs['s'], "model": specs['model'], "countryOfOriginId": specs['country'], "productId": lot['product_id'] }], "lotId": lot['lot_id'], "position": 1 if lot['selected'] else 0, "canceled": True if lot.get('status', '') == 'Canceled' else False, "reason": lot['reason'], "dateUpdate": None, "sumContest": lot['total'] }) items.append(item) data = {'evaluation': evaluation, 'bids': items} return portal_post('order/evaluate', data)
def put(bag): advert = g.tran.query(db.Advert).filter_by(_deleted='infinity', _id=bag['_id']).first() advert = orm_to_json(advert) lots = g.tran.query(db.Advert_lot).filter_by( _deleted='infinity', advert_id=advert['_id']).all() payments = advert['data']['payments'] or None tehadress = '' data = { 'companyInn': g.user.company['companyInn'], 'userPin': g.user.inn, 'username': g.user.username } userdata = portal_post('user', data) dirprocurement = g.tran.query(db.DirProcurement) \ .filter_by(_deleted='infinity', _id=advert['dirprocurement_id']).first() dirsection = g.tran.query(db.DirSection) \ .filter_by(_deleted='infinity').filter(db.DirSection._id == advert['dirsection_id']).first() # generate lots data ls = [] totalSum = 0 for lot in lots: specifications = getSpecDict({'id': lot._id}) dircategory = g.tran.query(db.DirCategory).filter( db.DirCategory.id == lot.dircategory_id).first() totalSum += lot.budget ls.append({ "name": dircategory.name, "okgz": dircategory.code, "deliveryDetails": lot.delivery_place, "deliveryDate": None, "deliveryPeriod": lot.estimated_delivery_time, "deliveryCondition": "", "number": lot._id, "sumContest": lot.budget, "planId": lot.planid, "products": [{ "specifications": specifications['specifications'], "okgz": dircategory.code, "measurementUnit": int(specifications['dirunitcode'].code), "amount": lot.quantity, "priceForOneUnit": lot.unit_price }] }) data = { "dateContest": str(advert['deadline']), "dateCreated": str(advert['created_date']), "name": dirsection.name, "totalSum": totalSum, "orderType": "PRODUCT", "orderFormat": "STANDART", "company": { "id": g.user.company['id'], "title": g.user.company['title'], "companyInn": g.user.company['companyInn'] }, "specialRequirement": { "allowBenefits": advert['concession'] > 0, "benefits": advert['concession'] or 0 }, "contract": { "payment": { "allowAdvance": payments['advanceEnabled'], "advance": payments['advance'] or 0, "allowAfterShipment": payments['shipmentEnabled'], "afterShipment": payments['shipment'] or 0, "allowAfterAcceptance": payments['acceptEnabled'], "afterAcceptance": payments['accept'] or 0 }, "allowTechnicalControl": len(tehadress) > 0, "control": { "title": "", "placeOfAttendancetitle": tehadress } }, "status": 'VERIFIED_PUBLISHED', "procurementMethod": dirprocurement.code if dirprocurement.code == 'SIMPLICATED' else 'SINGLE_SOURCE', "singleSourceReason": dirprocurement.code if dirprocurement.code != 'SIMPLICATED' else None, "userId": userdata['id'], "lots": ls } resp = portal_post("order/publish", data) if len(resp['lots']): for lot in lots: l = orm_to_json(lot) response_lot = next( (x for x in resp['lots'] if x.get('tandoo_uid') == lot._id), None) if response_lot: l['lot_id'] = response_lot['id'] l['product_id'] = response_lot['products'][0]['id'] l['type'] = 'Advert_lot' controller.call(controller_name='data.put', bag=l) return resp