tuttle-dev / tuttle

🪰 Tuttle - time and money management for freelancers
GNU General Public License v3.0
62 stars 12 forks source link

Bug: Creating an invoice #151

Closed vlad-ed-git closed 1 year ago

vlad-ed-git commented 1 year ago

Getting a KeyError : duration when attempting to create a new invoice


2023-01-19 15:34:52.128 | ERROR    | invoicing.intent:create_invoice:142 - Failed to create invoice. Check the logs for more details.
2023-01-19 15:34:52.128 | ERROR    | invoicing.intent:create_invoice:143 - 'duration'
Traceback (most recent call last):

  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/core/indexes/base.py", line 3803, in get_loc
    return self._engine.get_loc(casted_key)
           │    │               └ 'duration'
           │    └ <pandas._libs.properties.CachedProperty object at 0x107ecc900>
           └ Index([], dtype='object')
  File "pandas/_libs/index.pyx", line 138, in pandas._libs.index.IndexEngine.get_loc
    cpdef get_loc(self, object val):
  File "pandas/_libs/index.pyx", line 165, in pandas._libs.index.IndexEngine.get_loc
    return self.mapping.get_item(val)
  File "pandas/_libs/hashtable_class_helper.pxi", line 5745, in pandas._libs.hashtable.PyObjectHashTable.get_item
  File "pandas/_libs/hashtable_class_helper.pxi", line 5753, in pandas._libs.hashtable.PyObjectHashTable.get_item

KeyError: 'duration'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):

  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py", line 973, in _bootstrap
    self._bootstrap_inner()
    │    └ <function Thread._bootstrap_inner at 0x1011971c0>
    └ <Thread(Thread-47 (on_submit_btn_clicked), started daemon 6208221184)>
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
    │    └ <function Thread.run at 0x101196ef0>
    └ <Thread(Thread-47 (on_submit_btn_clicked), started daemon 6208221184)>
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
    │    │        │    │        │    └ {}
    │    │        │    │        └ <Thread(Thread-47 (on_submit_btn_clicked), started daemon 6208221184)>
    │    │        │    └ (<flet.control_event.ControlEvent object at 0x1511f0c70>,)
    │    │        └ <Thread(Thread-47 (on_submit_btn_clicked), started daemon 6208221184)>
    │    └ <bound method InvoicingEditorPopUp.on_submit_btn_clicked of <invoicing.view.InvoicingEditorPopUp object at 0x15106d780>>
    └ <Thread(Thread-47 (on_submit_btn_clicked), started daemon 6208221184)>

  File "/Users/vlad/Desktop/vlad/tuttle/app/invoicing/view.py", line 136, in on_submit_btn_clicked
    self.on_submit(self.invoice, self.project, from_date, to_date)
    │    │         │    │        │    │        │          └ datetime.date(2023, 1, 19)
    │    │         │    │        │    │        └ datetime.date(2023, 1, 18)
    │    │         │    │        │    └ Project(id=2, tag='cultivate-granular', end_date=datetime.date(2023, 4, 9), contract_id=2, title='cultivate granular converge...
    │    │         │    │        └ <invoicing.view.InvoicingEditorPopUp object at 0x15106d780>
    │    │         │    └ Invoice(id=None, number='', date=datetime.date(2023, 1, 19), contract_id=None, project_id=None, sent=False, paid=False, cance...
    │    │         └ <invoicing.view.InvoicingEditorPopUp object at 0x15106d780>
    │    └ <bound method InvoicingListView.on_save_invoice of <invoicing.view.InvoicingListView object at 0x150ec0dc0>>
    └ <invoicing.view.InvoicingEditorPopUp object at 0x15106d780>

  File "/Users/vlad/Desktop/vlad/tuttle/app/invoicing/view.py", line 270, in on_save_invoice
    result: IntentResult = self.intent.create_invoice(
                           │    │      └ <function InvoicingIntent.create_invoice at 0x13f38e8c0>
                           │    └ <invoicing.intent.InvoicingIntent object at 0x150ec0df0>
                           └ <invoicing.view.InvoicingListView object at 0x150ec0dc0>

> File "/Users/vlad/Desktop/vlad/tuttle/app/invoicing/intent.py", line 109, in create_invoice
    invoice: Invoice = invoicing.generate_invoice(
                       │         └ <function generate_invoice at 0x13e7b41f0>
                       └ <module 'tuttle.invoicing' from '/Users/vlad/Desktop/vlad/tuttle/tuttle/invoicing.py'>

  File "/Users/vlad/Desktop/vlad/tuttle/tuttle/invoicing.py", line 29, in generate_invoice
    total_hours = timesheet.total / pandas.Timedelta("1h")
                  │         │       │      └ <class 'pandas._libs.tslibs.timedeltas.Timedelta'>
                  │         │       └ <module 'pandas' from '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/__init__.py'>
                  │         └ <property object at 0x12008dcb0>
                  └ Timesheet(id=None, title='cultivate granular convergence - 2023-01-18 - 2023-01-19', date=datetime.date(2023, 1, 19), project...

  File "/Users/vlad/Desktop/vlad/tuttle/tuttle/model.py", line 432, in total
    total_time = self.table["duration"].sum()
                 │    └ <property object at 0x12008dd00>
                 └ Timesheet(id=None, title='cultivate granular convergence - 2023-01-18 - 2023-01-19', date=datetime.date(2023, 1, 19), project...

  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/core/frame.py", line 3805, in __getitem__
    indexer = self.columns.get_loc(key)
              │    │               └ 'duration'
              │    └ <pandas._libs.properties.AxisProperty object at 0x110b68f10>
              └ Empty DataFrame
                Columns: []
                Index: []
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/core/indexes/base.py", line 3805, in get_loc
    raise KeyError(key) from err
                   └ 'duration'

KeyError: 'duration' ```
clstaudt commented 1 year ago

@vlad-ed-git Can't easily reproduce it with the demo data. What was the input?

clstaudt commented 1 year ago

I think it's because there is no time tracking data for the given project and date range. Improved error handling, please check.