def create_timesheet(self, project_configuration, reports_set_folder,
                      timesheet_name_prefix):
     TimesheetLogger().log_on_console("=" * 50)
     TimesheetLogger().log_on_console(
         "Started creating timesheet: {}.".format(timesheet_name_prefix))
     report_name = self._names_generator.generate_report_name(
         timesheet_name_prefix)
     if not os.path.exists(
             os.path.join(self._timesheet_reports_folder,
                          reports_set_folder)):
         os.makedirs(
             os.path.join(self._timesheet_reports_folder,
                          reports_set_folder))
     workbook = xlsxwriter.Workbook(
         os.path.join(self._timesheet_reports_folder, reports_set_folder,
                      report_name))
     timesheet = Timesheet(workbook)
     self._project_teams_builder.clean_teams_container()
     self._teams_container = self._project_teams_builder.build_project_team(
         project_configuration['teams'], self._timesheet_data)
     teams_list = self._teams_container.get_teams_list()
     timesheet.add_summary_worksheet(
         teams_list, self._timesheet_date, self._national_holidays_list,
         project_configuration['po_number'],
         project_configuration['man_days_costs'])
     timesheet.add_statistics_worksheet(
         teams_list, self._timesheet_date,
         project_configuration['man_day_hours'])
     timesheet.add_worksheets_for_employees(
         teams_list, self._timesheet_date,
         project_configuration['man_day_hours'])
     timesheet.save_timesheet()
     TimesheetLogger().log_on_console("*" * 50)
     TimesheetLogger().log_on_console(
         "Timesheet: {} created.".format(timesheet_name_prefix))
     TimesheetLogger().log_on_console("=" * 50)
Ejemplo n.º 2
0
 def setUp(self):
     self.timesheet = Timesheet()
Ejemplo n.º 3
0
class TestTimesheet(unittest.TestCase):
    def setUp(self):
        self.timesheet = Timesheet()

    def testTimecardsDefaultValue(self):
        self.assertEqual(self.timesheet.timecards, {})

    def testGetTimecardReturnsATimecardObject(self):
        timecard = self.timesheet.get_timecard("2015-06-01")
        self.assertTrue(isinstance(timecard, Timecard))

    def testGetTimecardReturnsTimecardWithCorrectDate(self):
        timecard = self.timesheet.get_timecard("2015-06-01")
        self.assertEqual(timecard.date,
                datetime.strptime("2015-06-01", "%Y-%m-%d"))

    def testGetTimecardAddsTimecardToTimecardsDict(self):
        self.timesheet.get_timecard("2015-07-22")
        self.assertEqual(len(self.timesheet.timecards), 1)

    def testRepeatedCallsToGetTimecardReturnSameTimecard(self):
        tc1 = self.timesheet.get_timecard("2015-07-22")
        tc2 = self.timesheet.get_timecard("2015-07-22")

        self.assertEqual(tc1, tc2)

    def testDatesReturnsEmptyListWithoutTimecards(self):
        self.assertEqual(self.timesheet.dates(), [])

    def testDatesReturnsLengthTwoListWithTwoDifferentTimecards(self):
        self.timesheet.get_timecard("2015-06-01")
        self.timesheet.get_timecard("2015-06-02")

        self.assertEqual(len(self.timesheet.dates()), 2)

    def testDatesReturnsLengthOneListWithTwoSameTimecards(self):
        self.timesheet.get_timecard("2015-06-01")
        self.timesheet.get_timecard("2015-06-01")

        self.assertEqual(len(self.timesheet.dates()), 1)

    def testToCsvReturnsCsvFormattedDataForOneTimecard(self):
        item = {
                "time_spec": "10:00-18:30",
                "notes": "did stuff",
                }
        timecard = self.timesheet.get_timecard("2015-06-01")
        timecard.add(**item)

        timesheet_csv = self.timesheet.to_csv()
        expected = "Date work,Description,Tickets,Hours\r\n"
        expected += "2015-06-01,did stuff,,8.50\r\n"
        self.assertEqual(timesheet_csv, expected)

    def testToCsvReturnsCsvFormattedDataForTwoTimecards(self):
        first_item = {
                "time_spec": "10:00-18:30",
                "notes": "did stuff",
                }
        first_timecard = self.timesheet.get_timecard("2015-06-01")
        first_timecard.add(**first_item)

        second_item = {
                "time_spec": "19:00-20:00",
                "notes": "did more stuff",
                "tickets": "#123",
                }
        second_timecard = self.timesheet.get_timecard("2015-06-02")
        second_timecard.add(**second_item)

        timesheet_csv = self.timesheet.to_csv()
        expected = "Date work,Description,Tickets,Hours\r\n"
        expected += "2015-06-01,did stuff,,8.50\r\n"
        expected += "2015-06-02,did more stuff,#123,1.00\r\n"
        self.assertEqual(timesheet_csv, expected)
Ejemplo n.º 4
0
import yaml
import argparse
import os.path

from timesheets.timesheet import Timesheet

parser = argparse.ArgumentParser(description="Convert timesheets to CSV")
parser.add_argument("--timesheet", type=str, required=True, help="timesheet file name")
args = parser.parse_args()
timesheet_yml_fname = args.timesheet

yml_fh = open(timesheet_yml_fname)
timesheet_items = yaml.load_all(yml_fh)

timesheet = Timesheet()
total_hours = 0.0
for item in timesheet_items:
    timecard = timesheet.get_timecard(item.pop("date"))
    timecard.add(**item)

timesheet_csv = timesheet.to_csv()
timesheet_basename = os.path.basename(timesheet_yml_fname)
timesheet_stem = os.path.splitext(timesheet_basename)[0]
timesheet_csv_fname = timesheet_stem + ".csv"

csv_fh = open(timesheet_csv_fname, "w")
csv_fh.write(timesheet_csv)
csv_fh.close()

print "Total hours: {0:.2f}".format(timesheet.total_hours_worked())