예제 #1
0
def test_update(repository, new_timesheet):
    print("\n\nUpdating new_timesheet in database")
    repository.update(new_timesheet)
    print("new_timesheet updated in database")
    print("Reloading new_timesheet from database")
    db_timesheets = repository.read(timesheet_id=new_timesheet._id)
    for p in db_timesheets:
        timesheet_from_db = Timesheet.build_from_json(p)
        print("new_timesheet = {}".format(timesheet_from_db.get_as_json()))
예제 #2
0
def test_create(repository, new_timesheet):
    print("\n\nSaving new_timesheet to database")
    repository.create(new_timesheet)
    print("new_timesheet saved to database")
    print("Loading new_timesheet from database")
    db_timesheets = repository.read(timesheet_id=new_timesheet._id)
    for p in db_timesheets:
        timesheet_from_db = Timesheet.build_from_json(p)
        print("new_timesheet = {}".format(timesheet_from_db.get_as_json()))
예제 #3
0
class TimesheetTestCase(unittest.TestCase):

    def setUp(self):
        self.timesheet = Timesheet('01-11-2016', '30-11-2016')

    def test_constructor_should_be_able_to_recive_string(self):
        t = Timesheet('01-01-2001', '31-01-2001')

        self.assertIsInstance(t.start_date, pendulum.Pendulum)
        self.assertIsInstance(t.end_date, pendulum.Pendulum)

    def test_constructor_should_be_able_to_recive_date(self):
        t = Timesheet(pendulum.from_date(2001, 1, 1), pendulum.from_date(2001, 1, 1))

        self.assertIsInstance(t.start_date, pendulum.Pendulum)
        self.assertIsInstance(t.end_date, pendulum.Pendulum)

    def test_arrival_time_should_be_in_range(self):
        arrival_time = self.timesheet.get_arrival_time()

        self.assertGreaterEqual(arrival_time, pendulum.from_time(9, 0))
        self.assertLessEqual(arrival_time, pendulum.from_time(11, 59))

    def test_lunch_start_time_should_be_in_range(self):
        lunch_start_time = self.timesheet.get_lunch_start_time()

        self.assertGreaterEqual(lunch_start_time, pendulum.from_time(12, 0))
        self.assertLessEqual(lunch_start_time, pendulum.from_time(14, 0))

    def test_lunch_end_time_should_be_1_hour_later(self):
        lunch_start_time = pendulum.from_time(12, 0)

        self.assertEqual(self.timesheet.get_lunch_end_time(lunch_start_time), pendulum.from_time(13, 0))

    def test_departure_time_should_be_9_hours_later(self):
        arrival_time = pendulum.from_time(9, 0)

        self.assertEqual(self.timesheet.get_departure_time(arrival_time), pendulum.from_time(18, 0))

    def test_timesheet_should_have_all_days_in_range(self):
        timesheet = self.timesheet.get_timesheet()

        self.assertEqual(timesheet, [])
예제 #4
0
def load_all_items_from_database(repository):
    print("Loading all items from database:")
    timesheets = repository.read()
    at_least_one_item = False
    for p in timesheets:
        at_least_one_item = True
        tmp_timesheet = Timesheet.build_from_json(p)
        print("ID = {} | User = {} | Date = {}".format(tmp_timesheet._id,
                                                       tmp_timesheet.user,
                                                       tmp_timesheet.date))
    if not at_least_one_item:
        print("No items in the database")
예제 #5
0
def test_delete(repository, timesheet):
    print("\n\nDeleting timesheet to database")
    repository.delete(timesheet)
    print("timesheets deleted from database")
    print("Trying to reload timesheets from database")
    db_timesheets = repository.read(timesheet_id=timesheet._id)
    found = False
    for p in db_timesheets:
        found = True
        timesheet_from_db = Timesheet.build_from_json(p)
        print("timesheet = {}".format(timesheet_from_db.get_as_json()))

    if not found:
        print("Item with id = {} was not found in the database".format(
            timesheet._id))
예제 #6
0
    def Parse(self):
        timesheet  =  None;
        workbook  =  xlrd.open_workbook(self.Filename)
        
        if(len(workbook.sheets()) > 0):
            #interested on the first sheet
            sheet      =  workbook.sheets()[0];
            timesheet  = Timesheet(sheet.name);
            cell = sheet.cell(0,4) # the timesheet header text
            if(cell is not None):            
                timesheet.Header            = cell.value;
            timesheet.EmployeeName          = sheet.cell(2, 2).value
            timesheet.Title                 = sheet.cell(2, 4).value
            timesheet.WeekEndingSunday      = sheet.cell(2, 10).value
            timesheet.Department            = sheet.cell(3, 2).value
            timesheet.Description           = sheet.cell(4,0).value

            #Timesheet column titles
            timesheet.Projects.Header.append(sheet.cell(5,0).value) # RSRCE
            timesheet.Projects.Header.append(sheet.cell(5,1).value) # Work Order No
            timesheet.Projects.Header.append(sheet.cell(5,2).value) # Contract Number
            timesheet.Projects.Header.append(sheet.cell(5,3).value) # Total Hours
            timesheet.Projects.Header.append(sheet.cell(5,4).value) # Description

            # Load the projects that are filled by default its fixed to 24 records
            user_defineds_recs = self.__FromRowAtToList(sheet, 6,30);                
            self._ParseProjects(timesheet, user_defineds_recs, ProjectType.USER_DEFINED_PROJECT)

            #Fixed records
            fixed_project_recs =  self.__FromRowAtToList(sheet,31,45)
          
            self._ParseProjects(timesheet, fixed_project_recs, ProjectType.FIXED_PROJECT)
            
            # The year stamp time for the timesheet.
            timesheet.Template  = sheet.cell(50,0).value
        
        return timesheet
예제 #7
0
def load_all_items_by_user(repository, user):
    timesheetsViewModel = []
    print("Loading all items from database with user key:")
    timesheets = repository.getByUser(user)
    at_least_one_item = False
    for p in timesheets:
        at_least_one_item = True
        tmp_timesheet = Timesheet.build_from_json(p)
        timesheetsViewModel.append({
            'date': tmp_timesheet.date,
            'project': tmp_timesheet.project,
            'begin': tmp_timesheet.begin,
            'end': tmp_timesheet.end,
            'activity': tmp_timesheet.activity,
            'issue': tmp_timesheet.issue,
            'comment': tmp_timesheet.comment
        })

##        print("ID = {} | User = {} | Date = {}".format(tmp_timesheet._id,
##                                                       tmp_timesheet.user,
##                                                       tmp_timesheet.date))
    if not at_least_one_item:
        print("No items in the database")
    return timesheetsViewModel
예제 #8
0
def execute(args):
    """Checks which subcommand was given and executes it.

    :param args: The namespace containing the scripts arguments
    :type args: :class:`argparse.Namespace`
    """
    timesheet = Timesheet(args, config_file="config.json")
    if args.subcommand == "add":
        if not timesheet.add_record():
            print("Exiting. Record already exists.")
            sys.exit(1)
    elif args.subcommand == "update":
        if not timesheet.update_record():
            print("Exiting. Record with given date not found.")
            sys.exit(1)
    elif args.subcommand == "delete":
        if not timesheet.delete_record():
            print("Exiting. Record with given date not found.")
            sys.exit(1)
    elif args.subcommand == "export":
        if not timesheet.export():
            print("Exiting. No idea why yet.")
            sys.exit(1)
예제 #9
0
import logging
import datetime
import json
from timesheet import Timesheet, Project, Task, Interval
from clint.textui import puts, colored, indent
log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)
log.addHandler(logging.FileHandler(filename='time.log'))

t = Timesheet()


def save_timesheet():
    data = {'projects': [], 'tasks': [], 'intervals': [], 'notes': []}
    for project in t.projects.values():
        data['projects'].append({
            'id': project.id,
            'title': project.title,
            'desc': project.desc
        })

    text = json.dumps(data, indent=4)
    log.debug(text)
    with open('data.json', 'w') as f:
        print(text, file=f)


def load_timesheet():
    with open('data.json') as f:
        data = json.load(f)
예제 #10
0
def timesheet():
    global gRepo

    if auth():
        timesheetsViewModel = []
        repository = TimesheetsRepository()

        if request.method == 'POST':

            print("TimeSheetPost")

            try:

                project = request.form['project']
                begin = request.form['begin']
                end = request.form['end']
                activity = request.form['activity']
                issue = request.form['issue']
                comment = request.form['comment']

                #create new_timesheet and read back from database
                new_timesheet = Timesheet.build_from_json({
                    "user":
                    session['username'],
                    "date":
                    datetime.now().strftime("%Y-%m-%d"),
                    "project":
                    project,
                    "begin":
                    begin,
                    "end":
                    end,
                    "activity":
                    activity,
                    "issue":
                    issue,
                    "comment":
                    comment
                })

                test_create(repository, new_timesheet)

                #update new_timesheet and read back from database
                new_timesheet.begin = 350
                new_timesheet.end = 750

                test_update(repository, new_timesheet)

                #delete new_timesheet and try to read back from database
                #test_delete(repository, new_timesheet)

                print("Rendered timesheet!")
            except Exception as e:
                print("Fail!")

        timesheetGit = TimeGit.getTimeGenData(gRepo, session['username'])
        print(timesheetGit)

        #display all items from DB
        load_all_items_from_database(repository)

        dateCalendar = datetime.now().strftime("%Y-%m-%d")
        timesheetsViewModel = load_all_items_by_user(repository,
                                                     session['username'])
        return render_template('timesheet.html',
                               user=session['username'],
                               timesheetsViewModel=timesheetsViewModel,
                               dateCalendar=dateCalendar)
    else:
        return redirect(url_for('index'))
예제 #11
0
    def Parse(self):
        timesheet  =  None;
        workbook  =  pyexcel_ods.get_data(self.Filename)
        keys =  list(workbook.keys())
        
        if(len(keys) > 0):
            sheets  =  list(workbook.items())
            
            if(len(sheets) > 0):
                # Interested in the first sheet
                sheet  =  sheets[0]
                if(sheet is not None):
                    timesheet =  Timesheet(sheet[0])
                    records  =  sheet[1]
                    """
                      Records are list of records.
                      record are python list object of cell values that are not empty.
                    """
                    if(len(records) > 0):
                        header_record       =  records[0]
                        timesheet.Header    =  header_record[-1]

                        #3record is weekly timesheet line
                        
                        weekly_record                  =  records[2]
                        timesheet.EmployeeName         = weekly_record[1]
                        timesheet.Title                = weekly_record[2]
                        timesheet.WeekEndingSunday     = weekly_record[4]

                        #department record line
                        department_record = records[3];
                        timesheet.Department    = department_record[1]

                        #timesheet description
                        timesheet.Description   =  records[4][0]

                        #project records
                        project_column_headers  =  records[5]
                        if(len(project_column_headers) > 5):
                            timesheet.Projects.Header.append(project_column_headers[0]) # RSRCE
                            timesheet.Projects.Header.append(project_column_headers[1]) # Work Order No
                            timesheet.Projects.Header.append(project_column_headers[2]) # Contract Number
                            timesheet.Projects.Header.append(project_column_headers[3]) # Total Hours
                            timesheet.Projects.Header.append(project_column_headers[4]) # Description
                    
                            # Load the projects that are filled by default its fixed to 24 records
                            user_defineds_recs = records[6:30]
                            self._ParseProjects(timesheet, user_defineds_recs, ProjectType.USER_DEFINED_PROJECT)

                            # Load the fixed projects or tasks projects.
                            # this involves holidays , pay leaves e.t.c
                            # there are 15 of does at the moment.
                            fixed_project_recs =  records[31:45]
                            self._ParseProjects(timesheet, fixed_project_recs, ProjectType.FIXED_PROJECT)

                            # The year stamp time for the timesheet.
                            template_records  = records[50:52];
                            if(len(template_records) > 0):
                                template_rec =  template_records[0]
                                if(len(template_rec) > 0):
                                   timesheet.Template =  template_rec[0]
                            
        return timesheet
from timesheet import Timesheet
from workentry import Workentry
import sys
import time

if __name__ == '__main__':

    timesheet = Timesheet('/Users/afuerstenau/Library/Mobile Documents/com~apple~CloudDocs/Arbeitszeit aktuell.xlsx')

    sys.stdout.write("Arbeitszeit:"+ str(timesheet.get_sum_working_time()) +" Differenz:" +str(timesheet.get_diff_normative_actual_working_time_in_hours()) + "verbleibende Tage:" +str(timesheet.get_remaining_days()))
    sys.stdout.flush()
    sys.exit(0)
예제 #13
0
from timesheet import Timesheet
from workentry import Workentry
import sys
import time

if __name__ == '__main__':
    lunchbreak = ""
    try:
        lunchbreak = sys.argv[4]
    except Exception as e:
        pass
    workentry = Workentry(sys.argv[1], sys.argv[2], sys.argv[3], lunchbreak)
    timesheet = Timesheet('/Users/afuerstenau/Library/Mobile Documents/com~apple~CloudDocs/Arbeitszeit aktuell.xlsx')
    sum_working_time = timesheet.append_workentry(workentry)
    sys.stdout.write(workentry.description() + " " + workentry.starttime() + "-" + workentry.endtime()+ "\nSumme:" + str(sum_working_time))
    sys.stdout.flush()
    sys.exit(0)
예제 #14
0
 def setUp(self):
     self.timesheet = Timesheet('01-11-2016', '30-11-2016')
예제 #15
0
    def test_constructor_should_be_able_to_recive_date(self):
        t = Timesheet(pendulum.from_date(2001, 1, 1), pendulum.from_date(2001, 1, 1))

        self.assertIsInstance(t.start_date, pendulum.Pendulum)
        self.assertIsInstance(t.end_date, pendulum.Pendulum)
예제 #16
0
    def test_constructor_should_be_able_to_recive_string(self):
        t = Timesheet('01-01-2001', '31-01-2001')

        self.assertIsInstance(t.start_date, pendulum.Pendulum)
        self.assertIsInstance(t.end_date, pendulum.Pendulum)