Skip to content

Commit

Permalink
fix: update booking_type handling in FinancialMutation and fix typo i…
Browse files Browse the repository at this point in the history
…n financial mutation attributes
  • Loading branch information
TimEvci committed Dec 9, 2024
1 parent 9b7ca97 commit 9137edc
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
4 changes: 2 additions & 2 deletions moneysnake/financial_mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def book_payment(
{
"price_base": price_base,
"booking_id": booking_id,
"booking_type": booking_type,
"booking_type": booking_type.name,
},
method="PATCH",
)
Expand All @@ -101,7 +101,7 @@ def remove_payment(
"""
post_request(
f"financial_mutations/{self.id}/unlink_booking",
{"booking_id": booking_id, "booking_type": booking_type},
{"booking_id": booking_id, "booking_type": booking_type.name},
method="PATCH",
)

Expand Down
14 changes: 2 additions & 12 deletions moneysnake/financial_statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ def save(self) -> None:
Save the external sales invoice. Overrides the save method in MoneybirdModel.
"""
financial_statement_data = self.to_dict()

# For the POST and PATCH requests we need to use the details_attributes key
# instead of details key to match the Moneybird API.
financial_statement_data["financial_mutation_attributes"] = (
financial_statement_data["financial_mutations_attributes"] = (
financial_statement_data.pop("financial_mutations", [])
)

Expand Down Expand Up @@ -65,17 +66,6 @@ def add_financial_mutation(self, financial_mutation: FinancialMutation) -> None:
) from e
self.financial_mutations.append(financial_mutation.to_dict(exclude_none=True))

def get_financial_mutation(self, financial_mutation_id: int) -> dict[str, Any]:
"""
Get a financial mutation from the financial statement.
"""
for financial_mutation in self.financial_mutations:
if financial_mutation["id"] == financial_mutation_id:
return financial_mutation
raise ValueError(
f"Financial mutation with id {financial_mutation_id} not found."
)

@classmethod
def find_by_id(cls: type[Self], id: int) -> Self:
raise NotImplementedError(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "moneysnake"
version = "0.0.18"
version = "0.0.19"
description = "Moneybird SDK for Python"
authors = ["ArjanCodes"]
license = "MIT"
Expand Down

0 comments on commit 9137edc

Please sign in to comment.