tuttle-dev / tuttle

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

Test: Invoice creation #177

Closed clstaudt closed 1 year ago

clstaudt commented 1 year ago

When pressing Done in New Invoice, the modal closes and I get an error in the main page. It said something about checking the logs, but I don't know where they are. The reason for the error might be that the time tracking data is outside the contract dates (because I happened to have a calender file from 2021 lying around).

Changed the contract date and tried again, nope, still does not work.

vlad-ed-git commented 1 year ago

should be fixed on dev-refactor-branch. Pending merge and review.

clstaudt commented 1 year ago

@vlad-ed-git I think this requires some more testing and debugging.

On trying to set the status of a newly created invoice:

2023-01-23 18:01:39.081 | ERROR    | invoicing.intent:toggle_invoice_paid_status:265 - ❌ Error toggling invoice paid status: Can't attach instance <Invoice at 0x17cd94380>; another instance with key (<class 'tuttle.model.Invoice'>, (1,), None) is already present in this session.
2023-01-23 18:01:39.081 | ERROR    | invoicing.intent:toggle_invoice_paid_status:266 - Can't attach instance <Invoice at 0x17cd94380>; another instance with key (<class 'tuttle.model.Invoice'>, (1,), None) is already present in this session.
Traceback (most recent call last):

  File "/Users/cls/miniforge3/envs/tuttle/lib/python3.10/threading.py", line 973, in _bootstrap
    self._bootstrap_inner()
    │    └ <function Thread._bootstrap_inner at 0x1055d4af0>
    └ <Thread(Thread-902 (<lambda>), started daemon 6438449152)>
  File "/Users/cls/miniforge3/envs/tuttle/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
    │    └ <function Thread.run at 0x1055d4820>
    └ <Thread(Thread-902 (<lambda>), started daemon 6438449152)>
  File "/Users/cls/miniforge3/envs/tuttle/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
    │    │        │    │        │    └ {}
    │    │        │    │        └ <Thread(Thread-902 (<lambda>), started daemon 6438449152)>
    │    │        │    └ (<flet.control_event.ControlEvent object at 0x1458bbd60>,)
    │    │        └ <Thread(Thread-902 (<lambda>), started daemon 6438449152)>
    │    └ <function InvoiceTile.build.<locals>.<lambda> at 0x17c7ce4d0>
    └ <Thread(Thread-902 (<lambda>), started daemon 6438449152)>

  File "/Users/cls/Documents/Work/Projects/PrototypeFund/Dev/tuttle/app/invoicing/view.py", line 487, in <lambda>
    on_click=lambda e: self.toggle_paid_status(self.invoice),
                    │  │    │                  │    └ Invoice(id=1, contract_id=1, sent=False, cancelled=False, number='2023-01-23-01', date=datetime.date(2023, 1, 23), project_id...
                    │  │    │                  └ <invoicing.view.InvoiceTile object at 0x136c39cf0>
                    │  │    └ <bound method InvoicingListView.toggle_paid_status of <invoicing.view.InvoicingListView object at 0x136c277f0>>
                    │  └ <invoicing.view.InvoiceTile object at 0x136c39cf0>
                    └ <flet.control_event.ControlEvent object at 0x1458bbd60>

  File "/Users/cls/Documents/Work/Projects/PrototypeFund/Dev/tuttle/app/invoicing/view.py", line 324, in toggle_paid_status
    result: IntentResult = self.intent.toggle_invoice_paid_status(invoice)
                           │    │      │                          └ Invoice(id=1, contract_id=1, sent=False, cancelled=False, number='2023-01-23-01', date=datetime.date(2023, 1, 23), project_id...
                           │    │      └ <function InvoicingIntent.toggle_invoice_paid_status at 0x136c80790>
                           │    └ <invoicing.intent.InvoicingIntent object at 0x136c279a0>
                           └ <invoicing.view.InvoicingListView object at 0x136c277f0>

> File "/Users/cls/Documents/Work/Projects/PrototypeFund/Dev/tuttle/app/invoicing/intent.py", line 259, in toggle_invoice_paid_status
    self._invoicing_data_source.save_invoice(invoice)
    │    │                      │            └ Invoice(id=1, contract_id=1, sent=False, cancelled=False, number='2023-01-23-01', date=datetime.date(2023, 1, 23), project_id...
    │    │                      └ <function InvoicingDataSource.save_invoice at 0x136c800d0>
    │    └ <invoicing.data_source.InvoicingDataSource object at 0x136abf190>
    └ <invoicing.intent.InvoicingIntent object at 0x136c279a0>

  File "/Users/cls/Documents/Work/Projects/PrototypeFund/Dev/tuttle/app/invoicing/data_source.py", line 75, in save_invoice
    self.store(invoice)
    │    │     └ Invoice(id=1, contract_id=1, sent=False, cancelled=False, number='2023-01-23-01', date=datetime.date(2023, 1, 23), project_id...
    │    └ <function SQLModelDataSourceMixin.store at 0x136abbe20>
    └ <invoicing.data_source.InvoicingDataSource object at 0x136abf190>

  File "/Users/cls/Documents/Work/Projects/PrototypeFund/Dev/tuttle/app/core/abstractions.py", line 222, in store
    session.add(entity)
    │       │   └ Invoice(id=1, contract_id=1, sent=False, cancelled=False, number='2023-01-23-01', date=datetime.date(2023, 1, 23), project_id...
    │       └ <function Session.add at 0x107f7c040>
    └ <sqlmodel.orm.session.Session object at 0x1458bab00>

  File "/Users/cls/miniforge3/envs/tuttle/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 2626, in add
    self._save_or_update_state(state)
    │    │                     └ <sqlalchemy.orm.state.InstanceState object at 0x17097d300>
    │    └ <function Session._save_or_update_state at 0x107f7c160>
    └ <sqlmodel.orm.session.Session object at 0x1458bab00>
  File "/Users/cls/miniforge3/envs/tuttle/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 2645, in _save_or_update_state
    self._save_or_update_impl(st_)
    │    │                    └ <sqlalchemy.orm.state.InstanceState object at 0x14352aa10>
    │    └ <function Session._save_or_update_impl at 0x107f7c700>
    └ <sqlmodel.orm.session.Session object at 0x1458bab00>
  File "/Users/cls/miniforge3/envs/tuttle/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3226, in _save_or_update_impl
    self._update_impl(state)
    │    │            └ <sqlalchemy.orm.state.InstanceState object at 0x14352aa10>
    │    └ <function Session._update_impl at 0x107f7c670>
    └ <sqlmodel.orm.session.Session object at 0x1458bab00>
  File "/Users/cls/miniforge3/envs/tuttle/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3215, in _update_impl
    self.identity_map.add(state)
    │    │            │   └ <sqlalchemy.orm.state.InstanceState object at 0x14352aa10>
    │    │            └ <function WeakInstanceDict.add at 0x107d13eb0>
    │    └ <sqlalchemy.orm.identity.WeakInstanceDict object at 0x16f914220>
    └ <sqlmodel.orm.session.Session object at 0x1458bab00>
  File "/Users/cls/miniforge3/envs/tuttle/lib/python3.10/site-packages/sqlalchemy/orm/identity.py", line 151, in add
    raise sa_exc.InvalidRequestError(
          │      └ <class 'sqlalchemy.exc.InvalidRequestError'>
          └ <module 'sqlalchemy.exc' from '/Users/cls/miniforge3/envs/tuttle/lib/python3.10/site-packages/sqlalchemy/exc.py'>

sqlalchemy.exc.InvalidRequestError: Can't attach instance <Invoice at 0x17cd94380>; another instance with key (<class 'tuttle.model.Invoice'>, (1,), None) is already present in this session.
Exception in thread Thread-902 (<lambda>):
Traceback (most recent call last):
  File "/Users/cls/miniforge3/envs/tuttle/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/Users/cls/miniforge3/envs/tuttle/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/cls/Documents/Work/Projects/PrototypeFund/Dev/tuttle/app/invoicing/view.py", line 487, in <lambda>
    on_click=lambda e: self.toggle_paid_status(self.invoice),
  File "/Users/cls/Documents/Work/Projects/PrototypeFund/Dev/tuttle/app/invoicing/view.py", line 328, in toggle_paid_status
    self.invoices_to_display[result.data.id] = result.data
AttributeError: 'NoneType' object has no attribute 'id'

(After reloading the invoicing screen, toggling the status works.)

vlad-ed-git commented 1 year ago

@clstaudt on it.

vlad-ed-git commented 1 year ago

@clstaudt @clstaudt I can't re create this but I think the issue is as I described under #183