Closed heysarver closed 1 month ago
Hey @heysarver,
Did you already initialise an entity and add it to the session?
from python_accounting.database.session import get_session
from python_accounting.models import Entity, Currency
with get_session(engine) as session:
entity = Entity(name="Example Company")
session.add(entity)
session.commit() # This automatically sets up a Reporting Period for the Entity
currency = Currency(name="US Dollars", code="USD", entity_id=entity.id)
session.add(currency)
session.commit()
Also, the entity filter accounts = session.query(Account).filter(Account.entity_id == entity_id).all()
is unnessesary because all accounting objects are filtered automatically by the current session's entity id. See isolation tests
Thanks, I got it working after reviewing the tests. I forgot to set session.entity = entity
.
What is the proper way to load an existing entity into a new session and get a list of accounts?
I'm currently trying this but am getting an error: