示例#1
0
def index(projet_id):
    menu = 'projet'
    submenu = 'projet'
    context = 'frais'
    title_page = 'Projets - Frais'

    search = False
    q = request.args.get('q')
    if q:
        search = True
    try:
        page = int(request.args.get('page', 1))
    except ValueError:
        page = 1

    projet = Projet.get_by_id(projet_id)
    datas = FraisProjet.query(FraisProjet.projet_id == projet.key)
    pagination = Pagination(css_framework='bootstrap3', page=page, total=datas.count(), search=search, record_name='Projets')

    if datas.count() > 10:
        if page == 1:
            offset = 0
        else:
            page -= 1
            offset = page * 10
        datas = datas.fetch(limit=10, offset=offset)

    return render_template('frais/frais_projet.html', **locals())
示例#2
0
def delete(frais_id):
    fraiss = Frais.get_by_id(frais_id)

    frais_projet = FraisProjet.query(
        FraisProjet.frais_id == fraiss.key
    ).count()

    if frais_projet:
        flash('Impossible de supprimer cet element', 'danger')
    else:
        fraiss.key.delete()
        flash('Suppression reussie', 'success')
    return redirect(url_for('frais.index'))
示例#3
0
def edit(tache_id, detail_frais_id=None):

    tache = Tache.get_by_id(tache_id)

    if detail_frais_id:
        detail_frais = DetailFrais.get_by_id(detail_frais_id)
        form = FormFraisTache(obj=detail_frais)
        form.frais_projet_id.data = detail_frais.frais_projet_id.get().key.id()
        if detail_frais.detail_fdt:
            form.detail_fdt.data = detail_frais.detail_fdt.get().key.id()
    else:
        detail_frais = DetailFrais()
        form = FormFraisTache()

    form.frais_projet_id.choices = [(0, 'Selectionnez le frais applique')]
    for frais in FraisProjet.query(FraisProjet.projet_id == tache.projet_id):
        form.frais_projet_id.choices.append((frais.key.id(), frais.frais_id.get().libelle))

    day = datetime.date.today().strftime('%d/%m/%Y')
    dt = datetime.datetime.strptime(day, '%d/%m/%Y')
    start = dt - timedelta(days=dt.weekday())
    end = start + timedelta(days=6)


    temps = Temps.query(
        Temps.tache_id == tache.key,
        Temps.date_start == start,
        Temps.date_end == end
    ).get()

    form.detail_fdt.choices = [(0, 'Selectionnez la FDT concernee')]
    if temps:
        for frais in DetailTemps.query(DetailTemps.temps_id == temps.key):
            form.detail_fdt.choices.append((frais.key.id(), frais.description))

    success = False
    if form.validate_on_submit():

        detail_frais.date = function.date_convert(form.date.data)
        detail_frais.montant = form.montant.data
        detail_frais.description = form.description.data

        frais_projet = FraisProjet.get_by_id(form.frais_projet_id.data)
        detail_frais.frais_projet_id = frais_projet.key

        if form.detail_fdt.data:
            details_DFT = DetailTemps.get_by_id(form.detail_fdt.data)
            detail_frais.detail_fdt = details_DFT.key

        if temps:
            detail_frais.temps_id = temps.key
        else:
            temps = Temps()
            temps.user_id = tache.user_id
            temps.date_start = function.date_convert(start)
            temps.date_end = function.date_convert(end)
            temps.tache_id = tache.key
            time = temps.put()
            detail_frais.temps_id = time

        detail_frais.put()

        flash('Enregistrement effectue avec succes', 'success')
        success = True

    return render_template('frais/frais_tache_edit.html', **locals())