Exemple #1
0
def account_edit_own_account():
    userdata = DB.User.query.get(current_user.id)
    form = forms.MembersEditOwnAccount(obj=userdata)
    if form.validate_on_submit():
        confirmation = app.config['CHANGE_MSG']
        atributes = ['name', 'date_of_birth', 'email', 'telephone', 'city',
                     'postalcode', 'bus', 'number', 'street', 'show_telephone',
                     'show_email']
        for atribute in atributes:
            old_value = getattr(userdata, atribute)
            if atribute in ['show_telephone', 'show_email']:
                new_value = atribute in request.form
            elif atribute in ['date_of_birth']:
                new_value = string_to_date(request.form.get(atribute))
            else:
                new_value = request.form.get(atribute)
            if str(new_value) != str(old_value):
                user = DB.User.query.get(current_user.id)
                setattr(user, atribute, new_value)
                DB.db.session.commit()
                confirmation = add_confirmation(confirmation, atribute +
                                                " = " + str(new_value) +
                                                " (was " + str(old_value) + ")")
        return_flash(confirmation)
        return redirect(request.url)
    return render_template('my_account/edit_own_account.html', userdata=userdata,
                           form=form)
Exemple #2
0
def accounting_edit_transaction(transaction_id):
    banks = DB.Bank.query.all()
    transaction = DB.Transaction.query.get(transaction_id)
    form = forms.EditTransaction(obj=transaction)
    form.bank_id.choices = [(bank.id, bank.name) for bank in banks]
    form.category_id.choices = accounting_categories()
    if form.validate_on_submit():
        confirmation = app.config['CHANGE_MSG']
        atributes = ['date', 'facturation_date', 'is_revenue', 'amount', 'to_from', 'description',
            'category_id', 'bank_id', 'bank_statement_number']
        for atribute in atributes:
            old_value = getattr(transaction, str(atribute))
            new_value = request.form.get(atribute)
            if atribute == 'is_revenue':
                if new_value == '1':
                    new_value = True
                elif new_value == '0':
                    new_value = False
            if str(new_value) != str(old_value):
                if atribute == 'facturation_date' and new_value == '':
                    new_value = request.form.get('date')
                setattr(transaction, atribute, new_value)
                confirmation = add_confirmation(confirmation, str(atribute) +
                    " = " + str(new_value) + " (was " + str(old_value) + ")")
            transaction.date_filed
        DB.db.session.commit()

        uploadconfirmation = upload_attachments(request, attachments, transaction, DB)

        confirmation = add_confirmation(confirmation, uploadconfirmation)
        return_flash(confirmation)
        return redirect(request.url)
    return render_template('accounting/edit_transaction.html', form=form, transaction=transaction)
Exemple #3
0
def bar_stockup_josto():
    # get all active stock items from josto that need stocking up
    items = DB.StockItem.query.filter_by(active=True, josto=True).order_by(DB.StockItem.name.asc()).all()
    items = [item for item in items if item.stockup > 0]

    # we need to redefine this form everytime the view gets called,
    # otherwise the setattr's are caried over
    class StockupForm(Form):
        submit = SubmitField('stockup!')
    for item in items:
        setattr(StockupForm,
                str(item.id),
                FormField(forms.StockupJostoFormMixin,
                          label=item.name,
                          default={'amount': item.stockup}))
    form = StockupForm()

    if form.validate_on_submit():
        confirmation = app.config['CHANGE_MSG']
        for item in items:
            checked = str(item.id) + '-check' in request.form
            if checked:
                amount = int(request.form[str(item.id) + "-amount"])
                if amount != 0:
                    changes = DB.BarLog(item_id=item.id,
                                        amount=amount,
                                        user_id=current_user.id,
                                        transaction_type="stock up")
                    DB.db.session.add(changes)
                    DB.db.session.commit()
                    confirmation = add_confirmation(confirmation, "stock " +
                                                    item.name + " = +" + str(amount))
        return_flash(confirmation)
        return redirect(request.url)
    return render_template('bar/stockup_josto.html', form=form)
Exemple #4
0
def bar_edit_item_amounts():
    items = DB.StockItem.query.filter_by(active=True).order_by(DB.StockItem.name.asc()).all()
    for item in items:
        setattr(forms.BarEditAmounts, 'amount_' + str(item.id),
            IntegerField(item.name, [validators.NumberRange(min=0,
                message='please enter a positive number')],
            default=item.stock))
    form = forms.BarEditAmounts()
    if form.validate_on_submit():
        confirmation = app.config['CHANGE_MSG']
        for item in items:
            if int(request.form["amount_" + str(item.id)]) != int(item.stock):
                changes = DB.BarLog(
                    item_id = item.id,
                    amount = int(request.form["amount_" + str(item.id)]) - int(item.stock),
                    user_id = current_user.id,
                    transaction_type = "correction")
                DB.db.session.add(changes)
                DB.db.session.commit()
                confirmation = add_confirmation(confirmation, "stock " +
                    item.name + " = " + request.form["amount_" +
                    str(item.id)])
        return_flash(confirmation)
        return redirect(request.url)
    return render_template('bar/edit_amounts.html', form=form)
Exemple #5
0
def members_edit_member(user_id):
    userdata = DB.User.query.get(user_id)
    roles = DB.Role.query.all()
    # add roles to form
    for role in roles:
        # check the checkbox if the user has the role
        if role in userdata.roles:
            setattr(forms.MembersEditAccount, 'perm_' + str(role.name),
                    BooleanField(role.name, default='y'))
        else:
            setattr(forms.MembersEditAccount, 'perm_' + str(role.name),
                    BooleanField(role.name))
    form = forms.MembersEditAccount(obj=userdata)
    del form.email
    if form.validate_on_submit():
        confirmation = app.config['CHANGE_MSG']
        atributes = [
            'name', 'date_of_birth', 'telephone', 'city', 'postalcode', 'bus',
            'number', 'street', 'show_telephone', 'show_email',
            'membership_dues'
        ]
        atributes.extend([role for role in roles])
        for atribute in atributes:
            if atribute in roles:
                old_value = atribute in userdata.roles
                new_value = 'perm_' + atribute.name in request.form
            elif atribute in ['show_telephone', 'show_email']:
                old_value = getattr(userdata, atribute)
                new_value = atribute in request.form
            elif atribute in ['date_of_birth']:
                old_value = getattr(userdata, atribute)
                new_value = string_to_date(request.form.get(atribute))
            else:
                old_value = getattr(userdata, atribute)
                new_value = request.form.get(atribute)
            if str(new_value) != str(old_value):
                if atribute in roles:
                    if new_value:
                        DB.user_datastore.add_role_to_user(userdata, atribute)
                    else:
                        DB.user_datastore.remove_role_from_user(
                            userdata, atribute)
                else:
                    user = DB.User.query.get(user_id)
                    setattr(user, atribute, new_value)
                confirmation = add_confirmation(
                    confirmation,
                    str(atribute) + " = " + str(new_value) + " (was " +
                    str(old_value) + ")")
                DB.db.session.commit()
        return_flash(confirmation)
        return redirect(request.url)
    return render_template('members/edit_account.html', form=form)
Exemple #6
0
def members_edit_member(user_id):
    userdata = DB.User.query.get(user_id)
    roles = DB.Role.query.all()
    # add roles to form
    for role in roles:
        # check the checkbox if the user has the role
        if role in userdata.roles:
            setattr(forms.MembersEditAccount, 'perm_' + str(role.name),
                    BooleanField(role.name, default='y'))
        else:
            setattr(forms.MembersEditAccount, 'perm_' + str(role.name),
                    BooleanField(role.name))
    form = forms.MembersEditAccount(obj=userdata)
    del form.email
    if form.validate_on_submit():
        confirmation = app.config['CHANGE_MSG']
        atributes = ['name', 'date_of_birth', 'telephone', 'city', 'postalcode',
                     'bus', 'number', 'street', 'show_telephone', 'show_email',
                     'membership_dues']
        atributes.extend([role for role in roles])
        for atribute in atributes:
            if atribute in roles:
                old_value = atribute in userdata.roles
                new_value = 'perm_' + atribute.name in request.form
            elif atribute in ['show_telephone', 'show_email']:
                old_value = getattr(userdata, atribute)
                new_value = atribute in request.form
            elif atribute in ['date_of_birth']:
                old_value = getattr(userdata, atribute)
                new_value = string_to_date(request.form.get(atribute))
            else:
                old_value = getattr(userdata, atribute)
                new_value = request.form.get(atribute)
            if str(new_value) != str(old_value):
                if atribute in roles:
                    if new_value:
                        DB.user_datastore.add_role_to_user(userdata, atribute)
                    else:
                        DB.user_datastore.remove_role_from_user(userdata, atribute)
                else:
                    user = DB.User.query.get(user_id)
                    setattr(user, atribute, new_value)
                confirmation = add_confirmation(confirmation, str(atribute) + " = " +
                                                str(new_value) + " (was " + str(old_value) + ")")
                DB.db.session.commit()
        return_flash(confirmation)
        return redirect(request.url)
    return render_template('members/edit_account.html', form=form)
Exemple #7
0
def members_approve_new_members():
    new_members = DB.User.query.filter_by(membership_start=None)
    for user in new_members:
        setattr(forms.NewMembers, 'activate_' + str(user.id), BooleanField('activate user'))
    form = forms.NewMembers()
    if form.validate_on_submit():
        confirmation = app.config['CHANGE_MSG']
        for user in new_members:
            new_value = 'activate_' + str(user.id) in request.form
            if new_value != user.active_member:
                user.membership_start = datetime.date.today()
                DB.db.session.commit()
                confirmation = add_confirmation(confirmation, user.email +
                                                " was made an active member")
        return_flash(confirmation)
        return redirect(request.url)
    return render_template('members/approve_new_members.html', new_members=new_members, form=form)
def accounting_edit_transaction(transaction_id):
    banks = DB.Bank.query.all()
    transaction = DB.Transaction.query.get(transaction_id)
    form = forms.EditTransaction(obj=transaction)
    form.bank_id.choices = [(bank.id, bank.name) for bank in banks]
    form.category_id.choices = accounting_categories()
    if form.validate_on_submit():
        confirmation = app.config["CHANGE_MSG"]
        atributes = [
            "date",
            "facturation_date",
            "is_revenue",
            "amount",
            "to_from",
            "description",
            "category_id",
            "bank_id",
            "bank_statement_number",
        ]
        for atribute in atributes:
            old_value = getattr(transaction, str(atribute))
            new_value = request.form.get(atribute)
            if atribute == "is_revenue":
                if new_value == "1":
                    new_value = True
                elif new_value == "0":
                    new_value = False
            elif atribute in ["date", "facturation_date"]:
                new_value = string_to_date(request.form.get(atribute))
            if str(new_value) != str(old_value):
                if atribute == "facturation_date" and new_value == "":
                    new_value = request.form.get("date")
                setattr(transaction, atribute, new_value)
                confirmation = add_confirmation(
                    confirmation, str(atribute) + " = " + str(new_value) + " (was " + str(old_value) + ")"
                )
            transaction.date_filed
        DB.db.session.commit()

        uploadconfirmation = upload_attachments(request, attachments, transaction, DB)

        confirmation = add_confirmation(confirmation, uploadconfirmation)
        return_flash(confirmation)
        return redirect(request.url)
    return render_template("accounting/edit_transaction.html", form=form, transaction=transaction)
Exemple #9
0
def bar_activate_stockitems():
    stockitems = DB.StockItem.query.filter_by(active=False).all()
    for stockitem in stockitems:
        setattr(forms.BarActivateItem, 'activate_' + str(stockitem.id),
                BooleanField('activate item'))
    form = forms.BarActivateItem()

    if form.validate_on_submit():
        confirmation = 'the following stockitem\'s status were set to "active": '
        for stockitem in stockitems:
            new_value = 'activate_' + str(stockitem.id) in request.form
            if new_value != stockitem.active:
                stockitem.active = True
                confirmation = confirmation + stockitem.name + ", "
        DB.db.session.commit()
        return_flash(confirmation)
        return redirect(request.url)

    return render_template('bar/activate_stockitems.html', stockitems=stockitems, form=form)
Exemple #10
0
def bar_edit_items():
    items = DB.StockItem.query.filter_by(active=True).order_by(DB.StockItem.name.asc()).all()
    categories = DB.StockCategory.query.all()
    for item in items:
        setattr(forms.BarEdit, str(item.id),
                FormField(forms.BarEditItem, default=item, separator='_'))
    form = forms.BarEdit()
    for item in form:
        if item.name != 'csrf_token' and item.name != 'submit':
            item.category_id.choices = [(category.id, category.name) for category in categories]
    if form.validate_on_submit():
        confirmation = app.config['CHANGE_MSG']
        for item in items:
            # only write to DB and display a confirmation if the value given in the POST
            # does not equal the value in the DB
            atributes = ['name', 'price', 'stock_max', 'category_id', 'josto']
            for atribute in atributes:
                old_value = getattr(item, atribute)
                if atribute == 'josto':
                    new_value = str(item.id) + '_josto' in request.form
                else:
                    new_value = request.form[str(item.id) + '_' + atribute]
                if str(old_value) != str(new_value):
                    setattr(item, atribute, new_value)
                    DB.db.session.commit()
                    if atribute == "name":
                        confirmation = add_confirmation(confirmation,
                                                        old_value + " => " + new_value)
                    elif atribute == "category_id":
                        newcat = DB.StockCategory.query.get(new_value).name
                        oldcat = DB.StockCategory.query.get(old_value).name
                        confirmation = add_confirmation(confirmation,
                                                        "category" + " " + item.name + " = \"" +
                                                        newcat + "\" (was \"" + oldcat + "\")")
                    else:
                        confirmation = add_confirmation(confirmation,
                                                        atribute + " " + item.name + " = " +
                                                        str(new_value) + " (was " +
                                                        str(old_value) + ")")
        return_flash(confirmation)
        return redirect(request.url)
    return render_template('bar/edit_items.html', form=form)
Exemple #11
0
def accounting_edit_transaction(transaction_id):
    banks = DB.Bank.query.all()
    transaction = DB.Transaction.query.get(transaction_id)
    form = forms.EditTransaction(obj=transaction)
    form.bank_id.choices = [(bank.id, bank.name) for bank in banks]
    form.category_id.choices = accounting_categories()
    if form.validate_on_submit():
        confirmation = app.config['CHANGE_MSG']
        atributes = [
            'date', 'facturation_date', 'is_revenue', 'amount', 'to_from',
            'description', 'category_id', 'bank_id', 'bank_statement_number'
        ]
        for atribute in atributes:
            old_value = getattr(transaction, str(atribute))
            new_value = request.form.get(atribute)
            if atribute == 'is_revenue':
                if new_value == '1':
                    new_value = True
                elif new_value == '0':
                    new_value = False
            elif atribute in ['date', 'facturation_date']:
                new_value = string_to_date(request.form.get(atribute))
            if str(new_value) != str(old_value):
                if atribute == 'facturation_date' and new_value == '':
                    new_value = request.form.get('date')
                setattr(transaction, atribute, new_value)
                confirmation = add_confirmation(
                    confirmation,
                    str(atribute) + " = " + str(new_value) + " (was " +
                    str(old_value) + ")")
            transaction.date_filed
        DB.db.session.commit()

        uploadconfirmation = upload_attachments(request, attachments,
                                                transaction, DB)

        confirmation = add_confirmation(confirmation, uploadconfirmation)
        return_flash(confirmation)
        return redirect(request.url)
    return render_template('accounting/edit_transaction.html',
                           form=form,
                           transaction=transaction)
Exemple #12
0
def members_approve_new_members():
    new_members = DB.User.query.filter_by(membership_start=None)
    for user in new_members:
        setattr(forms.NewMembers, 'activate_' + str(user.id),
                BooleanField('activate user'))
    form = forms.NewMembers()
    if form.validate_on_submit():
        confirmation = app.config['CHANGE_MSG']
        for user in new_members:
            new_value = 'activate_' + str(user.id) in request.form
            if new_value != user.active_member:
                user.membership_start = datetime.date.today()
                DB.db.session.commit()
                confirmation = add_confirmation(
                    confirmation, user.email + " was made an active member")
        return_flash(confirmation)
        return redirect(request.url)
    return render_template('members/approve_new_members.html',
                           new_members=new_members,
                           form=form)
Exemple #13
0
def bar_edit_item_amounts():
    items = DB.StockItem.query.filter_by(active=True).order_by(DB.StockItem.name.asc()).all()
    for item in items:
        setattr(forms.BarEditAmounts, 'amount_' + str(item.id),
                IntegerField(item.name, [validators.NumberRange(min=0,
                             message='please enter a positive number')],
                             default=item.stock))
    form = forms.BarEditAmounts()
    if form.validate_on_submit():
        confirmation = app.config['CHANGE_MSG']
        for item in items:
            if int(request.form["amount_" + str(item.id)]) != int(item.stock):
                changes = DB.BarLog(item_id=item.id,
                                    amount=int(request.form["amount_" + str(item.id)]) - int(item.stock),
                                    user_id=current_user.id,
                                    transaction_type="correction")
                DB.db.session.add(changes)
                DB.db.session.commit()
                confirmation = add_confirmation(confirmation, "stock " + item.name + " = " +
                                                request.form["amount_" + str(item.id)])
        return_flash(confirmation)
        return redirect(request.url)
    return render_template('bar/edit_amounts.html', form=form)