Exemple #1
0
 def edit_billable_time(self, job):
     print("Estimated Time: " + job['estimated_time'])
     print("Actual Time: " + job['actual_time'])
     billable_time = input("Billable Time: ")
     self.repository.update_billable_time(job['id'], billable_time)
     self.repository.save()
     self.repository.check_rows_updated('Job Updated')
     Menu.wait_for_input()
Exemple #2
0
 def log_time(self, job_id):
     logged_time = ''
     while not Validation.isFloat(logged_time):
         logged_time = input('Log Time: ')
     self.repository.update_actual_time(job_id, logged_time)
     self.repository.save()
     self.repository.check_rows_updated('Job Updated')
     Menu.wait_for_input()
Exemple #3
0
 def add(self):
     print(Style.create_title('Add %s' % self.table_name))
     data = self.input_add_data()
     self.validate_model_data(data['own'])
     if self.model.is_valid():
         self.save_data(data)
     else:
         self.display_errors('%s not added' % self.table_name)
     Menu.wait_for_input()
Exemple #4
0
 def update_status(self, job_id):
     statusRepository = StatusRepository()
     paginated_menu = Pagination(statusRepository)
     status = paginated_menu(find=statusRepository.find_paginated,
                             find_by_id=statusRepository.find_by_id)
     self.repository.update(job_id, {
         'status_id': status['id'],
     })
     self.repository.save()
     self.repository.check_rows_updated('Status Updated')
     Menu.wait_for_input()
Exemple #5
0
 def generate(self):
     print(Style.create_title('Generate Invoice'))
     invoice = self.make_paginated_menu()
     if invoice:
         jobRepository = JobRepository()
         jobs = jobRepository.find_jobs_by_invoice_id(invoice['id'])
         self.enter_billable_time(jobRepository, jobs)
         jobs = jobRepository.find_jobs_by_invoice_id(invoice['id'])
         invoice_data = self.make_invoice_dictionary(invoice, jobs)
         LatexInvoice().generate(**invoice_data)
         self.mark_invoiced_jobs_as_complete(jobRepository, jobs)
         Menu.wait_for_input()
Exemple #6
0
 def __init__(self):
     controller = MainController()
     Menu.create('Manage', ActionCollection(
         ('Companies', controller.company_action),
         ('Clients', controller.client_action),
         ('Staff', controller.staff_action),
         ('Statuses', controller.status_action),
         ('Projects', controller.project_action),
         ('Jobs', controller.job_action),
         ('Invoices', controller.invoice_action),
         exit_action=Action('q', 'Quit', False)
     ))
Exemple #7
0
 def edit(self):
     print(Style.create_title('Edit %s' % self.table_name))
     item = self.make_paginated_menu()
     if item:
         data = self.input_edit_data(item)
         data['own'] = self.validate_model_data(data['own'])
         if self.model.is_valid:
             self.save_update(data, item)
         else:
             self.display_errors('%s not updated' % self.table_name)
     else:
         print('No changes made')
     Menu.wait_for_input()
Exemple #8
0
 def delete(self):
     print(Style.create_title('Delete %s' % self.table_name))
     item = self.make_paginated_menu()
     if item:
         user_action = False
         while not user_action == 'delete':
             user_action = input(
                 'Type \'%s\' to remove this item or %s to cancel: ' %
                 (Colour.red('delete'), Colour.green('c')))
             if user_action == 'c':
                 return
         self.save_remove(item)
         Menu.wait_for_input()
Exemple #9
0
 def input_edit_data(self, item):
     data = {'own': {}, 'relation': {}}
     for (key, field) in self.model:
         if not field.updatable:
             continue
         if isinstance(field, ForeignKeyField):
             if Menu.yes_no_question('Change %s?' %
                                     field.relationship.name):
                 foreign_key = Relationship.select_foreign_key_relationship(
                     field.relationship)
                 if foreign_key:
                     data['own'][key] = foreign_key
             else:
                 data['own'][key] = item[key]
         elif isinstance(field, OneToManyField):
             foreign_key = Relationship.select_foreign_key_relationship_inverse(
                 field.relationship)
             if foreign_key:
                 data['relation'][key] = foreign_key
             else:
                 data['relation'][key] = item[key]
             # Todo: handle removing relationships
         else:
             data['own'][key] = self.update_field(item[key],
                                                  Style.make_label(key))
     return data
 def select_foreign_key_relationship_inverse(relationship):
     foreign_keys = []
     repository = relationship.repository()
     while Menu.yes_no_question('Add %s' % relationship.name):
         print(Style.create_title('Select %s' % relationship.name))
         paginated_menu = relationship.paginated_menu or Pagination(
             repository)
         item = paginated_menu()
         if item:
             foreign_keys.append(item['id'])
         else:
             print('\nNo relationship added\n')
     return relationship.related_name, foreign_keys
Exemple #11
0
 def menu(self):
     result = False
     while not result:
         self.paginated_table()
         self.pagination_text()
         user_input = input('\nEnter an %s, use %s and %s to navigate, or %s to go back: ' % (
             Colour.green("'id'"),
             Colour.green("<"),
             Colour.green(">"),
             Colour.green("b")
         ))
         if (user_input == 'b'):
             break
         if self.should_change_page(user_input):
             self.change_page(user_input)
             continue
         if not Validation.is_number(user_input):
             print('Command not recognised')
             continue
         result = self.find_by_id(user_input)
         if not result:
             Menu.wait_for_input('An item with that ID was not found. Press any key to continue.')
     return result
Exemple #12
0
 def show_item_menu(self, id):
     Menu.create(self.table_name + ' Menu', ActionCollection())
Exemple #13
0
 def menu(self):
     Menu.create('Manage ' + self.table_name, self.menu_actions)
Exemple #14
0
 def show_item_menu(self, id):
     Menu.create(
         self.table_name + ' Menu',
         ActionCollection(('Update Status', lambda: self.update_status(id)),
                          ('Log Time', lambda: self.log_time(id))))
Exemple #15
0
 def show_item_menu(self, id):
     Menu.create(
         self.table_name + 'Menu',
         ActionCollection(
             ('Show Assigned Jobs',
              lambda: JobCrud().show_jobs_by_assigned_to(id)), ))