Example #1
0
def getWorkLog(contract, month, year):
    try:
        if contract.contract_begin.year > year or \
                        contract.contract_end.year < year or \
                (contract.contract_begin.year == year and contract.contract_begin.month > month) or \
                (contract.contract_end.year == year and contract.contract_end.month < month):
            raise ValidationError("Invalid workLog (shouldn't happen)")
        workL = WorkLog.objects.get(contract=contract, month=month, year=year)
    except ObjectDoesNotExist:
        workL = WorkLog()
        workL.month = month
        workL.year = year
        workL.contract = contract
        workL.save()
    return workL
Example #2
0
def worklog_add():
    form = WorkLogEditForm(request.form)

    if form.validate_on_submit():
        worklog = WorkLog()
        form.populate_obj(worklog)
        worklog.created_user = current_user.name
        worklog.updated_user = current_user.name
        worklog.created_time = datetime.datetime.now()
        worklog.updated_time = datetime.datetime.now()
        worklog.updated_count = 0
        db.session.add(worklog)
        db.session.commit()
        return redirect(url_for('worklog_list'))

    return render_template('worklog_edit.html', form=form)
Example #3
0
 def stop_counting(self):
     a = AdditionalTools.AdditionalTools()
     uid = self.uid
     total_time = self.total_duration
     # note the work finish time
     finish = datetime.datetime.now()
     finisht = str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
     # count the worktime
     delta = finish - self.start
     work_time = str(datetime.timedelta(seconds=delta.seconds))
     # get work note from input
     note = request.form['worknote']
     # put total time in a human way
     time_hours = a.time_hours(delta.seconds)
     time_precise = a.time_human(delta.seconds)
     # count monies
     session_monies = self.rate * time_hours
     # save worklog entry in worklog
     new_record = WorkLog(uid, self.startt, finisht, delta.seconds,
                          time_precise, int(session_monies), note)
     db.session.add(new_record)
     db.session.commit()
     # put some variables for page rendering
     tbutton = 'start'
     tbutton_class = 'btn-primary'
     note_class = 'hidden'
     status_class = ''
     # render page
     return render_template('logger.htm',
                            rate=self.rate,
                            currency=self.currency,
                            total_duration=self.total_duration,
                            total_month_duration=self.total_month_duration,
                            workitems=self.workitems,
                            client_name=self.client[0],
                            monies=self.monies,
                            month_monies=self.month_monies,
                            company_name=self.client[2],
                            uid=self.uid,
                            tbutton=tbutton,
                            tbutton_class=tbutton_class,
                            note_class=note_class,
                            status_class=status_class,
                            start_time=self.start,
                            stop_time=finisht)