Skip to content

Commit

Permalink
docs(finance_services): Added comments to clarify the functions that …
Browse files Browse the repository at this point in the history
…i made for invoices and receipts
  • Loading branch information
MoMo2Win committed Nov 20, 2024
1 parent 76931d4 commit f225859
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 49 deletions.
Binary file modified myfinances/clients/__pycache__/service.cpython-312.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion myfinances/clients/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def update_client(self,
MyFinancesResponse[Client]: Data of the client's details is updated
"""
params = {
key: value for key, value in{
key: value for key, value in {
"name": name,
"phone_number": phone_number,
"email": email,
Expand Down
Binary file modified myfinances/finance/invoices/__pycache__/service.cpython-312.pyc
Binary file not shown.
65 changes: 50 additions & 15 deletions myfinances/finance/invoices/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,49 @@ def create_invoice(self,
}

response = self._client._post("/invoices/create", json=payload)

return MyFinancesResponse(**response.dict())

def list_invoices(self) -> MyFinancesResponse[InvoiceList]:
response = self._client._get(f"/invoices/")
return MyFinancesResponse(**response.dict())

def get_invoice(self, invoice_id: int) -> MyFinancesResponse[Invoice]:
"""
Gathering a specific Invoice by ID
Args:
invoice_id (int): Invoice ID
Returns:
MyFinancesResponse[Client]: Invoice details
"""
response = self._client._get(f"/invoices/{invoice_id}/")
return MyFinancesResponse(**response.dict())

def delete_invoice(self, invoice_id: int) -> MyFinancesResponse[InvoiceList]:
def delete_invoice(self, invoice_id: int) -> MyFinancesResponse[Invoice]:
"""
Delete a specific Invoice by ID
Args:
invoice_id (int): Invoice ID
Returns:
MyFinancesResponse[Invoice]: Deleting the specified Invoice
"""
response = self._client._delete(f"/invoices/{invoice_id}/delete")
return MyFinancesResponse(**response.dict())

def search_invoices(self, customer_id: int = None, status: str = None) -> MyFinancesResponse[InvoiceList]:
"""
Search for a specific Invoice by use of filters
Args:
customer_id (int): Customer ID
status (str): Invoice status
Returns:
MyFinancesResponse[InvoiceList]: invoice list with the specified filters
"""
params = {}

if customer_id is not None:
Expand All @@ -42,19 +69,27 @@ def search_invoices(self, customer_id: int = None, status: str = None) -> MyFina
return MyFinancesResponse(**response.dict())

def update_invoice(self, customer_id: int, amount: float = None, description: str = None, due_date: str = None, status: str = None ) -> MyFinancesResponse[Invoice]:
params = {}

if amount is not None:
params["amount"] = amount

if description is not None:
params["description"] = description

if due_date is not None:
params["due_date"] = due_date

if status is not None:
params["status"] = status
"""
Updating an existing Invoice
Args:
customer_id (int): customer's ID
amount (float): Invoice total amount to be change
description (str): Invoice description to be change
due_date (str): due date of the invoice to be changed
status (str): Invoice status to be changed
Returns:
MyFinancesResponse[Invoice]: updating an existing invoice's details
"""
params = {
key: value for key, value in{
"amount": amount,
"description": description,
"due_date": due_date,
"status": status,
}.items() if value is not None
}

response = self._client._patch(f"/invoices/{customer_id}/update", json=params)
return MyFinancesResponse(**response.dict())
Binary file modified myfinances/finance/receipts/__pycache__/service.cpython-312.pyc
Binary file not shown.
97 changes: 67 additions & 30 deletions myfinances/finance/receipts/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ def create_receipt(self,
total_amount: float = None,
owner: Optional[str] = None
) -> MyFinancesResponse[ReceiptIDResponse]:
"""
Creates a new receipt
Args:
name(str): The name of the client
image(Optional[FilePath]): file path of the image of the receipt.
date(Optional[str]): date of the receipt (format: YYYY-MM-DD)
merchant_store(Optional[str]): The names store or merchant
purchase_category(Optional[str]): Category of the purchase
total_amount(float): The total of the purchase
owner(Optional[str]): Owner of the store
Returns:
MyFinancesResponse[ReceiptIDResponse]: Creation of the receipt
"""

params = {
"name": name,
Expand All @@ -29,45 +44,67 @@ def create_receipt(self,
}

response = self._client._post("/receipts/create/", json=params)

return MyFinancesResponse(**response.dict())

def list_receipts(self) -> MyFinancesResponse[ReceiptList]:
"""
Lists all the receipts
Returns:
MyFinancesResponse[ReceiptList]: lists of all the receipts in the system
"""
response = self._client._get("/receipts/")
return MyFinancesResponse(**response.dict())

def delete_receipt(self, receipt_id: int) -> MyFinancesResponse[ReceiptIDResponse]:
response = self._client._delete(f"/receipts/{receipt_id}/delete")
return MyFinancesResponse(**response.dict())

def search_receipts(self, receipt_id: int = None, name: str = None, merchant_store: str = None,
image: Optional[FilePath] = None, date: Optional[str] = None, purchase_category: Optional[str] = None,
total_amount: float = None, owner: Optional[str] = None ) -> MyFinancesResponse[ReceiptList]:
params = {}

if receipt_id is not None:
params["id"] = receipt_id

if name is not None:
params["name"] = name

if merchant_store is not None:
params["merchant_store"] = merchant_store
"""
Deletes a receipt by its ID.
if image is not None:
params["image"] = image
Args:
receipt_id(int): Receipt ID's to delete the receipt
if date is not None:
params["date"] = date

if purchase_category is not None:
params["purchase_category"] = purchase_category

if total_amount is not None:
params["total_amount"] = total_amount

if owner is not None:
params["owner"] = owner
Returns:
MyFinancesResponse[ReceiptIDResponse]: Deletion of the receipt
"""
response = self._client._delete(f"/receipts/{receipt_id}/delete")
return MyFinancesResponse(**response.dict())

def search_receipts(self,
receipt_id: int = None,
name: str = None,
merchant_store: str = None,
image: Optional[FilePath] = None,
date: Optional[str] = None,
purchase_category: Optional[str] = None,
total_amount: float = None,
owner: Optional[str] = None) -> MyFinancesResponse[ReceiptList]:
"""
Searching for the receipts for a specific receipt by using filters
Args:
receipt_id(Optional[int]): Receipt ID's
name(str): The name of the client
image(Optional[FilePath]): file path of the image of the receipt.
date(Optional[str]): date of the receipt (format: YYYY-MM-DD)
merchant_store(Optional[str]): The names store or merchant
purchase_category(Optional[str]): Category of the purchase
total_amount(float): The total of the purchase
owner(Optional[str]): Owner of the store
Returns:
MyFinancesResponse[ReceiptList]: List of receipts returning base the filter
"""
params = {
key: value for key, value in {
"id": receipt_id,
"name": name,
"merchant_store": merchant_store,
"image": image,
"date": date,
"purchase_category": purchase_category,
"total_amount": total_amount,
"owner": owner
}.items() if value is not None
}
response = self._client._get("/receipts/search/", params=params)
return MyFinancesResponse(**response.dict())
Binary file modified tests/__pycache__/test_receipts.cpython-312-pytest-8.3.3.pyc
Binary file not shown.
6 changes: 3 additions & 3 deletions tests/test_receipts.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ def receipts_service(mock_client):

def test_create_receipt(receipts_service, mock_client):
receipts_data = {
"name": "Client 1",
"name": "Client 1",
"image": "file_example",
"date": "2024-05-21",
"merchant_store": "Store 1",
"purchase_category": "Purchase 1",
"total_amount": 500,
"owner": "Client 2"
"owner": "Client 2"
}

mock_response_data = {
Expand Down Expand Up @@ -113,7 +113,7 @@ def test_delete_receipt(receipts_service, mock_client):
assert remaining_receipts[0]["id"] == 1


def test_update_receipt(receipts_service, mock_client):
def test_search_receipt(receipts_service, mock_client):
list_of_receipts = [
{"id": 1, "name": "Client 1", "image": "file_example", "date": "2024-05-21",
"merchant_store": "Store 1", "purchase_category": "Purchase 1", "total_amount": 100, "owner": "Owner 1"},
Expand Down

0 comments on commit f225859

Please sign in to comment.