diff --git a/myfinances/clients/__pycache__/service.cpython-312.pyc b/myfinances/clients/__pycache__/service.cpython-312.pyc index 10ad26c..b7f102a 100644 Binary files a/myfinances/clients/__pycache__/service.cpython-312.pyc and b/myfinances/clients/__pycache__/service.cpython-312.pyc differ diff --git a/myfinances/clients/service.py b/myfinances/clients/service.py index 9d7b88c..a2c96d2 100644 --- a/myfinances/clients/service.py +++ b/myfinances/clients/service.py @@ -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, diff --git a/myfinances/finance/invoices/__pycache__/service.cpython-312.pyc b/myfinances/finance/invoices/__pycache__/service.cpython-312.pyc index d6ba772..aaa6448 100644 Binary files a/myfinances/finance/invoices/__pycache__/service.cpython-312.pyc and b/myfinances/finance/invoices/__pycache__/service.cpython-312.pyc differ diff --git a/myfinances/finance/invoices/service.py b/myfinances/finance/invoices/service.py index d55cbe4..455f8e2 100644 --- a/myfinances/finance/invoices/service.py +++ b/myfinances/finance/invoices/service.py @@ -14,7 +14,6 @@ def create_invoice(self, } response = self._client._post("/invoices/create", json=payload) - return MyFinancesResponse(**response.dict()) def list_invoices(self) -> MyFinancesResponse[InvoiceList]: @@ -22,14 +21,42 @@ def list_invoices(self) -> MyFinancesResponse[InvoiceList]: 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: @@ -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()) diff --git a/myfinances/finance/receipts/__pycache__/service.cpython-312.pyc b/myfinances/finance/receipts/__pycache__/service.cpython-312.pyc index ca0ceae..34b9465 100644 Binary files a/myfinances/finance/receipts/__pycache__/service.cpython-312.pyc and b/myfinances/finance/receipts/__pycache__/service.cpython-312.pyc differ diff --git a/myfinances/finance/receipts/service.py b/myfinances/finance/receipts/service.py index 3c7c461..df1ce84 100644 --- a/myfinances/finance/receipts/service.py +++ b/myfinances/finance/receipts/service.py @@ -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, @@ -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()) diff --git a/tests/__pycache__/test_receipts.cpython-312-pytest-8.3.3.pyc b/tests/__pycache__/test_receipts.cpython-312-pytest-8.3.3.pyc index 35f9fc8..a5dd1a3 100644 Binary files a/tests/__pycache__/test_receipts.cpython-312-pytest-8.3.3.pyc and b/tests/__pycache__/test_receipts.cpython-312-pytest-8.3.3.pyc differ diff --git a/tests/test_receipts.py b/tests/test_receipts.py index d34af13..df3aa4c 100644 --- a/tests/test_receipts.py +++ b/tests/test_receipts.py @@ -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 = { @@ -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"},