示例#1
0
    def post(self):
        user_dict = get_jwt_identity()
        user = UserModel.find_by_username(user_dict['username'])
        item_id = purchase_parser.parse_args()['id']
        item = ShopItemModel.find_item_by_id(item_id)
        if item:
            new_transaction = TransactionModel(
                sender_id=user.id,
                receiver_id=0,
                amount=item.price,
                date=datetime.datetime.now(),
                transaction_type='Purchase'
            )

            if user.current_balance < item.price:
                return {'message': 'Not enough money'}, 400

            try:
                item.purchase_item(user)
                user.change_balance(user.current_balance - item.price)
                new_transaction.save_to_db()
                return {'message': 'You have successfully bought {}'.format(item.name)}, 200
            except:
                return {'message': 'Something went wrong'}, 500
        return {'message': 'Item not found'}, 400
示例#2
0
def retract_twopack(fraction_id, source_fraction_id):
    """ two fractions are defined
    """
    if request.args.get('acquiredate'):
        session['acquiredate']= request.args.get('acquiredate')
        
    fraction = FractionModel(fraction_id)
    source_fraction = FractionModel(source_fraction_id)
    transaction_model = TransactionModel(fraction_id,source_fraction_id)
    

        #print('req.arg:'+request.args.get('acquiredate'))
    if 'acquiredate' in session:
        #print('RETRACTacquiredateInSession:',session.get('acquiredate'))
        transactions = transaction_model.get_simple(date=str(session.get('acquiredate')))
    else:
        transactions = None
        
    #print(str(transactions))  
    
    nav_dates = transaction_model.acqusitions_get_last_dates()
    
    return render_template('transaction/retraction.html',
                            fraction=fraction,
                            source_fraction=source_fraction,
                            nav_dates=nav_dates,
                            transactions=transactions
                            )
示例#3
0
def acquire_twopack(fraction_id, source_fraction_id):
    #print('acquire_twopack'+str(fraction_id)+'/'+str(source_fraction_id))
    fraction = FractionModel(fraction_id)
    source_fraction = FractionModel(source_fraction_id)
    transactions = TransactionModel(fraction_id,source_fraction_id)
    
    #get all transactions for the actuall date
    if 'acquiredate' in session:
        #print('ACQIREacquiredateInSession:',(session.get('acquiredate')))
        trdata = transactions.get_simple(date=session.get('acquiredate'))
        #trdata = False
    else:
        trdata = False
    #get last inputs    
    history_entries = transactions.acqusitions_get_last_inserts(12)
        
    # track productgroup
    if request.args.get('productgroup',''):
        session['productgroup']= request.args.get('productgroup','')

    
    
    return render_template('transaction/acquisition.html',
                           fraction=fraction,
                           source_fraction=source_fraction,
                           history_entries=history_entries,
                           transactions= trdata)
示例#4
0
def acquire_delete(fraction_id,timestamp,next_url):
    
    tmodel = TransactionModel(fraction_id)
    
    if tmodel.acqusition_delete(timestamp):
        flash('Eintrag erfolgreich gelöscht','success')
    else:
        flash('Konnte nicht gelöscht werden','alert')
    return redirect(next_url)
示例#5
0
def index():  
    """ """
    tr= TransactionModel()
    sqldump = tr.index('100')
    #print(sqldump)
    das = {'item_name': 'Blumenkohl', 'unit_name': 'kg', 'fraction_id': 3, 'source_fraction_id': 2, 'product_id': 131000, 'unit_id': 1, 'netto': 36, 'retour': 9}
    avgs = das
    #avgs = (zip(*sqldump))
    #print(avgs)
    return jsonify(avgs)
示例#6
0
def _populate_model(entity):
    model = TransactionModel()
    model.id = get_resource_id_from_key(entity.key)
    model.user_id = entity.user_id
    model.rule_item_ids = entity.rule_item_ids
    model.total_preferences = entity.total_preferences
    model.total_likes = entity.total_likes
    model.total_dislikes = entity.total_dislikes
    model.created_timestamp = entity.created_timestamp
    model.latest_timestamp = entity.latest_timestamp
    return model
示例#7
0
def product(fraction_id, product_id):
    
    fraction = FractionModel(fraction_id)
    transactions = TransactionModel(fraction_id)
    
    return render_template('transtest.html',fraction=fraction,
                           transactions=transactions,
                           product_id=product_id)
示例#8
0
    def post(self):
        data = transaction_parser.parse_args()
        sender = UserModel.find_by_username(get_jwt_identity()['username'])
        receiver = UserModel.find_by_username(data['receiver_username'])
        if not receiver:
            return {'message': 'Receiver does not exist'}, 500

        sender_id = sender.id
        receiver_id = receiver.id
        amount = data['amount']

        new_transaction = TransactionModel(
            sender_id=sender_id,
            receiver_id=receiver_id,
            amount=amount,
            date=datetime.datetime.now(),
            transaction_type='Transfer'
        )

        try:
            if amount <= 0:
                return {'message': 'Amount is less or equal to zero'}, 400

            if sender_id == receiver_id:
                return {'message': 'Sender == Receiver'}, 400

            if sender.current_balance < amount:
                return {'message': 'Sender does not have enough unicoins'}, 400

            sender.change_balance(sender.current_balance - amount)
            new_transaction.save_to_db()
            receiver.change_balance(receiver.current_balance + amount)

            return {
                'message': 'Transaction from {0} to {1}: {2} unicoins'.format(sender.username, receiver.username, amount)
            }, 200
        except:
            return {'message': 'Something went wrong'}, 500
示例#9
0
def consumer():
    context = zmq.Context()
    # recieve work
    consumer_receiver = context.socket(zmq.PULL)
    consumer_receiver.connect("tcp://127.0.0.1:5557")

    # instance a Txid Consumer
    # txid_consumer = TxidConsumer()
    dig = DigTX()
    tm = TransactionModel()

    while True:
        work = consumer_receiver.recv_json()
        txid = work['data']
        try:
            ret = dig.dig(txid)
            unspent = ret.get("unspent") or []
            spent = ret.get("spent") or []
            for i in unspent:
                print(">>> %s" % i)
                tm.save_unspent(i, spent)
        except:
            print(traceback.format_exc())
示例#10
0
def conception_by_product_id(fraction_id, year_of_growth, product_id):
    """render all sets (Sätze) of one product"""
    start = time.time()  #performence time start
    if request.args.get('pivot'):
        pivot = int(request.args.get('pivot'))  #or_test (trinity operator)
    else:
        pivot = 0

    fraction = FractionModel(fraction_id)
    product = ProductModel(product_id, fraction_id)
    transact = TransactionModel(fraction_id)

    #productlist = fraction.get_product_list()
    productlist = fraction.cheata_menue()  #implement list2nested!!!
    the_product = product.get_data()  #:one dict

    area_info = conception_model.get_involved_areas(fraction_id,
                                                    year_of_growth)

    #t=transact.get_transactions(product_id)
    #print('Transactions:'+str(t))

    #and the_product[0]['has_data'] == fraction_id

    if the_product['has_data'] == fraction_id:

        entries = conception_model.get_product_by_id(fraction_id,
                                                     year_of_growth,
                                                     product_id)
        summary = conception_model.get_summary_by_id(fraction_id,
                                                     year_of_growth,
                                                     product_id)
        end = time.time()  #performence time end
        print('Performence conception.by_product_id:' + str(end - start) +
              'sec.')
        return render_template('vegetables/conception_one.html',
                               entries=entries,
                               summary=summary,
                               productlist=productlist,
                               fraction=fraction,
                               the_product=the_product,
                               area_info=area_info,
                               year_of_growth=year_of_growth,
                               pivot=pivot)

    elif the_product['tree_diff'] != 1 or the_product['has_data'] < 0:
        return str(the_product)
示例#11
0
 def post(self):
     data = transaction_par.parse_args()
     id = data['user_id']
     return TransactionModel.return_transfer_by_user_id(id)
示例#12
0
 def get(self):
     return TransactionModel.return_all()
示例#13
0
def retract_getsome(fraction_id,source_fraction_id,product_id,unit_id):
    """Hit the retraction Table
    date is handled over session-cookie
    first get the entrie in the acquire data from that retour what you want
    we could restrict boxes ID  to acquire data but the user could retour in
    boxes of another date, years ago.
    """
    fraction = FractionModel(fraction_id)
    source_fraction = FractionModel(source_fraction_id)
    product = ProductModel(product_id, source_fraction_id)
    product_entries = product.get_data()
    unit = UnitModel(product_entries['unit_set_id'])
    box = BoxModel(product_entries['boxes_set_id'])
    vehicle = VehicleModel()
    transaction_model = TransactionModel(fraction_id,source_fraction_id)
    #Do I repeat myself?
    
    if request.args.get('acquiredate'):
        session['acquiredate']= request.args.get('acquiredate')
        
    if 'acquiredate' in session:
        the_date = str(session.get('acquiredate'))
    #
    acquire_data = transaction_model.acquisitions_get_summary_by_date_product_unit(the_date,product_id,unit_id)

    form = Acquisition_Retraction_Form()
    
    form.unit_id.choices = unit.get_wtform_choices()
    form.vehicle_id.choices = vehicle.get_wtform_choices()
    form.box_id.choices = box.get_wtform_choices()
    form.alternate_unit_id.choices = unit.get_wtform_choices()
    
    #prefill formdata
    form.aq_date.data = datetime.strptime(the_date,form.aq_date.format).date()
    form.product_id.data = product_id
    form.fraction_id.data = fraction_id
    form.source_fraction_id.data = source_fraction_id
    form.unit_id.data = acquire_data['unit_id']
    form.unit_id.render_kw={"disabled":"disabled"}
    
    form.box_id.data = acquire_data['box_id']
    #form.box_id.render_kw={"disabled":"disabled"}
    
    if acquire_data['alternatesum'] and acquire_data['alternate_unit_id'] in [item[0] for item in form.alternate_unit_id.choices] :
        form.alternate_unit_id.data = acquire_data['alternate_unit_id']
    else:
        form.alternate_unit_id.data = 1 #defaults to KG (Datenmüll)
    
    if form.validate_on_submit():
        
        result = transaction_model.retraction_insert(form)
        if type(result) is str:
            flash(result, 'alert')
        elif result:
            flash(u'Übernommen!','success')
            
            return redirect(url_for('.retract_twopack', fraction_id=fraction_id,
                                    source_fraction_id=source_fraction_id))
        else:
            abort(500)
            
    if form.csrf_token.errors:
        flash(u'Zeitüberschreitung. Das Formular wird nach einer Stunde warten ungültig. Nichts gespeichert. Gleich nochmal versuchen.','warning')
        
        
    return render_template('transaction/retraction.html',
                            fraction=fraction,
                            source_fraction=source_fraction,
                            product_entries=product_entries,
                            acquire_data=acquire_data,
                            form=form
                            )
示例#14
0
def acquire_getsome(fraction_id, source_fraction_id, product_id):
    """ GET ready to fire a POST to the acquisitions table
    the flow is: from source_fraction to fraction
    
    WHAT happens IF fraction_id is to drive the boxes and units,
    like DEPOT wants to have 264' boxes in Pounds of a product???
    
    """
    #init destination fractions
    fraction = FractionModel(fraction_id)
    #init source fraction
    source_fraction = FractionModel(source_fraction_id)

    product = ProductModel(product_id, source_fraction_id)
    #dict of product spec data (one db row)
    product_entries = product.get_data()
    unit = UnitModel(product_entries['unit_set_id'])
    box = BoxModel(product_entries['boxes_set_id'])
    vehicle = VehicleModel()
    transactions = TransactionModel(fraction_id, source_fraction_id)
    #the latest entries in acquisitions table
    #TODO variable count
    history_entries = transactions.acqusitions_get_last_inserts(12)    
    
    form = Acquisition_Retraction_Form()
    #print('dateFORMAT:'+str(form.aq_date.format))
    #print('Session::acquiredate:'+str(session.get('acquiredate')))
    
        
        #form.aq_date.data = session.get('acquiredate')
        
    #before validating wtf choises (<option>) must be given 
    form.unit_id.choices = unit.get_wtform_choices()
    form.vehicle_id.choices = vehicle.get_wtform_choices()
    form.box_id.choices = box.get_wtform_choices()

    #with boxes we css-style <options> in the template (render_kw?)
    boxset = box.get_set_by_id(product_entries['boxes_set_id'])

    form.alternate_unit_id.choices = unit.get_wtform_choices()
    
    if form.validate_on_submit():
        session['acquiredate'] = str(form.aq_date.data)
        
        #print('form-data:'+str(form.aq_date.data))
        #print('sessionACQUIREdate:'+str(session.get('acquiredate')))
        
        result = transactions.acqusition_insert(form)
        
        #print('>>>>>>>>>aqcuisition_insert_result: '+ str(result))
        if type(result) is str:
            flash(result, 'alert')
        elif result:
            flash(u'Die Angaben und Werte wurden erfolgreich übernommen und gespeichert.','success')
 
            return redirect(url_for('.acquire_getsome', fraction_id=fraction_id,
                     source_fraction_id=source_fraction_id,
                     product_id=product_id))
        else:
            abort(500)

    if form.csrf_token.errors:
        flash(u'Zeitüberschreitung. Das Formular wird nach einer Stunde warten ungültig. Nichts gespeichert. Gleich nochmal versuchen.','warning')
    
    #manualy set wtform.data initial_preselected
    if not form.is_submitted():
        #print("FORM SUBMIT!")
        if 'acquiredate' in session:
            set_date = datetime.strptime(session.get('acquiredate'),form.aq_date.format).date()
            form.aq_date.data = set_date
            
        form.fraction_id.data = fraction.fraction_id
        form.source_fraction_id.data = source_fraction.fraction_id
        form.product_id.data = product_entries['product_id']
        if  request.args.get('unit_id',''):
            #print('UNIT_ID!!!!'+str(request.args.get('unit_id',''))+str(type(request.args.get('unit_id',''))))
            if int(request.args.get('unit_id','')) in[item[0] for item in form.unit_id.choices]:
                form.unit_id.data=int(request.args.get('unit_id',''))
        else:
            form.unit_id.data = product_entries['unit_pivot_id']
        form.box_id.data = product_entries['box_pivot_id']
        form.box_count.data = 0
        form.vehicle_count.data = 0
    

    return render_template('transaction/acquisition.html',
                           fraction=fraction,
                           source_fraction=source_fraction,
                           product_entries=product_entries,
                           boxset=boxset,
                           history_entries=history_entries,
                           form=form)