diff options
author | Markus Krogh <markus@nordu.net> | 2016-03-10 11:53:42 +0000 |
---|---|---|
committer | Markus Krogh <markus@nordu.net> | 2016-03-10 11:53:42 +0000 |
commit | 4575c7ea47680e7f589477c917a73353d6faef73 (patch) | |
tree | 5f1fb1d8d120b8d609b2018a5eb8e8ad30183952 /maconomy_hours.py | |
parent | 67abade3147d6d706c18beaac219d549fb71c35e (diff) |
Manager mail + ceo mail
Diffstat (limited to 'maconomy_hours.py')
-rw-r--r-- | maconomy_hours.py | 61 |
1 files changed, 51 insertions, 10 deletions
diff --git a/maconomy_hours.py b/maconomy_hours.py index 1001964..62a328f 100644 --- a/maconomy_hours.py +++ b/maconomy_hours.py @@ -1,21 +1,62 @@ -from maconomy import cli, Employee, Timesheet, create_db, TimeRegistrationRepository +from maconomy import cli, create_db, TimeRegistrationRepository +from maconomy.views import EmployeeEmailView, ManagerEmailView, CEOEmailView -def main(config, dry_run): +def main(config, options): db = create_db(config) timereg_repo = TimeRegistrationRepository(db) + timesheets = timereg_repo.all_active() - for employee, timesheet in timereg_repo.all_active(): - if timesheet.is_missing(): - print u"Timesheet for {} has not been created".format(employee) - elif not timesheet.is_submitted(): - print u"Missing time sheet for {}".format(employee) - elif not timesheet.is_approved(): - print u"Timesheet for {} not approved".format(employee) + if options.manager: + manager(timesheets, config, options.dry) + elif options.ceo: + ceo(timesheets, config, options.dry) + elif options.summary: + summary(timesheets) + else: + normal(timesheets, config, options.dry) + # Close stuff timereg_repo.close() db.close() +def normal(timesheets, config, dry_run): + view = EmployeeEmailView(config) + for timesheet in timesheets: + if not timesheet.is_submitted(): + mail = view.render(timesheet) + subjct = u"Timesheet reminder for {}".format(timesheet.employee) + if dry_run: + print subjct + print mail + else: + pass +def manager(timesheets, config, dry_run): + relevant = [t for t in timesheets if need_manager_mail(t)] + view = ManagerEmailView(config) + mail = view.render(relevant) + if dry_run: + print mail + +def ceo(timesheets, config, dry_run): + relevant = [t for t in timesheets if need_manager_mail(t)] + view = CEOEmailView() + mail = view.render(relevant) + if dry_run: + print mail + +def need_manager_mail(timesheet): + return not timesheet.is_submitted() or not timesheet.is_approved() + +def summary(timesheets): + for timesheet in timesheets: + if timesheet.is_missing(): + print u"[Not created] {}".format(timesheet.employee) + elif not timesheet.is_submitted(): + print u"[Unsubmitted] {}".format(timesheet.employee) + elif not timesheet.is_approved(): + print u"[Not approved] {}".format(timesheet.employee) + if __name__ == '__main__': args = cli.parse() config = cli.load_config(args.config) - main(config, args.dry) + main(config, args) |