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

feat: add create_transaction_category #73

Merged
merged 7 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ As of writing this README, the following methods are supported:

- `delete_transaction_category` - deletes a category for transactions
- `delete_transaction_categories` - deletes a list of transaction categories for transactions
- `create_transaction_category` - creates a category for transactions
- `request_accounts_refresh` - requests a synchronization / refresh of all accounts linked to Monarch Money. This is a **non-blocking call**. If the user wants to check on the status afterwards, they must call `is_accounts_refresh_complete`.
- `request_accounts_refresh_and_wait` - requests a synchronization / refresh of all accounts linked to Monarch Money. This is a **blocking call** and will not return until the refresh is complete or no longer running.
- `create_transaction` - creates a transaction with the given attributes
Expand Down
88 changes: 88 additions & 0 deletions monarchmoney/monarchmoney.py
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,94 @@ async def get_transaction_category_groups(self) -> Dict[str, Any]:
operation="ManageGetCategoryGroups", graphql_query=query
)

async def create_transaction_category(
self,
group_id: str,
transaction_category_name: str,
rollover_start_month: datetime = datetime.today().replace(day=1),
icon: str = "\U00002753",
rollover_enabled: bool = False,
rollover_type: str = "monthly",
):
"""
Creates a new transaction category
:param group_id: The transaction category group id
:param transaction_category_name: The name of the transaction category being created
:param icon: The icon of the transaction category. This accepts the unicode string or emoji.
:param rollover_start_month: The datetime of the rollover start month
:param rollover_enabled: A bool whether the transaction category should be rolled over or not
:param rollover_type: The budget roll over type
"""

query = gql(
"""
mutation Web_CreateCategory($input: CreateCategoryInput!) {
createCategory(input: $input) {
errors {
...PayloadErrorFields
__typename
}
category {
id
...CategoryFormFields
__typename
}
__typename
}
}
fragment PayloadErrorFields on PayloadError {
fieldErrors {
field
messages
__typename
}
message
code
__typename
}
fragment CategoryFormFields on Category {
id
order
name
icon
systemCategory
systemCategoryDisplayName
budgetVariability
isSystemCategory
isDisabled
group {
id
type
groupLevelBudgetingEnabled
__typename
}
rolloverPeriod {
id
startMonth
startingBalance
__typename
}
__typename
}
"""
)
variables = {
"input": {
"group": group_id,
"name": transaction_category_name,
"icon": icon,
"rolloverEnabled": rollover_enabled,
"rolloverType": rollover_type,
"rolloverStartMonth": rollover_start_month.strftime("%Y-%m-%d"),
},
}

return await self.gql_call(
operation="Web_CreateCategory",
graphql_query=query,
variables=variables,
)

async def get_transaction_tags(self) -> Dict[str, Any]:
"""
Gets all the tags configured in the account.
Expand Down
Loading