Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a way to allow to get budgets information #61

Merged
merged 3 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions actual/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ def before_flush(sess, flush_context, instances):
@event.listens_for(session, "after_commit")
@event.listens_for(session, "after_soft_rollback")
def after_commit_or_rollback(
sess, previous_transaction=None # noqa: previous_transaction needed for soft rollback
sess,
previous_transaction=None, # noqa: previous_transaction needed for soft rollback
):
if sess.info.get("messages"):
del sess.info["messages"]
Expand Down Expand Up @@ -236,6 +237,8 @@ class Categories(BaseModel, table=True):
tombstone: Optional[int] = Field(default=None, sa_column=Column("tombstone", Integer, server_default=text("0")))
goal_def: Optional[str] = Field(default=None, sa_column=Column("goal_def", Text, server_default=text("null")))

zero_budgets: "ZeroBudgets" = Relationship(back_populates="category_item")

transactions: List["Transactions"] = Relationship(
back_populates="category",
sa_relationship_kwargs={
Expand Down Expand Up @@ -571,7 +574,14 @@ class ZeroBudgets(SQLModel, table=True):

bvanelli marked this conversation as resolved.
Show resolved Hide resolved
id: Optional[str] = Field(default=None, sa_column=Column("id", Text, primary_key=True))
month: Optional[int] = Field(default=None, sa_column=Column("month", Integer))
category: Optional[str] = Field(default=None, sa_column=Column("category", Text))
category: Optional[str] = Field(default=None, sa_column=Column("category", ForeignKey("categories.id")))
bvanelli marked this conversation as resolved.
Show resolved Hide resolved
category_item: "Categories" = Relationship(
back_populates="zero_budgets",
sa_relationship_kwargs={
"uselist": False,
"primaryjoin": "and_(ZeroBudgets.category == Categories.id,Categories.tombstone == 0)",
},
)
amount: Optional[int] = Field(default=None, sa_column=Column("amount", Integer, server_default=text("0")))
carryover: Optional[int] = Field(default=None, sa_column=Column("carryover", Integer, server_default=text("0")))
goal: Optional[int] = Field(default=None, sa_column=Column("goal", Integer, server_default=text("null")))
Expand Down
16 changes: 16 additions & 0 deletions actual/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,22 @@ def get_or_create_account(s: Session, name: str | Accounts) -> Accounts:
return account


def get_budgets(s: Session) -> typing.Sequence[ZeroBudgets]:
bvanelli marked this conversation as resolved.
Show resolved Hide resolved
"""
Returns a list of all available ZeroBudgets.
:param s: session from Actual local database.
:return: list of ZeroBudgets
"""
query = select(ZeroBudgets).options(joinedload(ZeroBudgets.category_item))
return s.exec(query).unique().all()


def get_budget(s: Session, category_name: str) -> typing.Optional[ZeroBudgets]:
"""Gets an existing budget by category name, returns `None` if not found"""
query = select(ZeroBudgets).join(Categories).filter(Categories.name == category_name)
return s.exec(query).unique().all()
bvanelli marked this conversation as resolved.
Show resolved Hide resolved


def create_transfer(
s: Session,
date: datetime.date,
Expand Down
Loading