From f2258594461b8c87ebfa0ca0fc62db9064184f12 Mon Sep 17 00:00:00 2001 From: 20128094 <20128094@tafe.wa.edu.au> Date: Thu, 21 Nov 2024 00:37:32 +0800 Subject: [PATCH] docs(finance_services): Added comments to clarify the functions that i made for invoices and receipts --- .../__pycache__/service.cpython-312.pyc | Bin 5171 -> 5171 bytes myfinances/clients/service.py | 2 +- .../__pycache__/service.cpython-312.pyc | Bin 3472 -> 3894 bytes myfinances/finance/invoices/service.py | 65 +++++++++--- .../__pycache__/service.cpython-312.pyc | Bin 3149 -> 3782 bytes myfinances/finance/receipts/service.py | 97 ++++++++++++------ ...test_receipts.cpython-312-pytest-8.3.3.pyc | Bin 13831 -> 13836 bytes tests/test_receipts.py | 6 +- 8 files changed, 121 insertions(+), 49 deletions(-) diff --git a/myfinances/clients/__pycache__/service.cpython-312.pyc b/myfinances/clients/__pycache__/service.cpython-312.pyc index 10ad26c25ed331f12576a2326346fdba5d9b72f0..b7f102af9c1357d8c1a4c592b0884619f12a4378 100644 GIT binary patch delta 29 jcmdn2u~~!nG%qg~0}xnq*rhjZL}?`yxhZ z@EM5F&uPv2+VYA_F(PYIIr9mC7$X7AmavhvLZwJSAktYb%iaY+_G-|AEBWJAW`mJb zG^XIQyqD$W1Edw_DGwHS=FkS6L{l5gWHdE_kEPA!oh}uPbk`$plh246`nctD8B9Fs`#(|#wYE|jLrjJV7;zcw*#kpp=R!~P80GW zTLc93D&zKR?CtKIQVppU!}imPu0|I3+cWSaes4dPm`4ED$_yE0*l1_n(WO`53X2;vn-9kk<5j>XU!;shF>D?pM? eLkKs)iEm&i4~8~D+ZKBs!tg@!2QX0f6U{I1u?l$r delta 591 zcmY+AO-LI-6vt;~cQ%{MW}~dtR%2osMZ}K~O2n2ZO6iA+L91RA{J?%av-P__RLg~fJ2KC;zy9aR&@ArQ5pIPSZ&se!d{Syv{5G*U1 zU7ZSEr~?=WEAQ|j!GA0NgfPYp{7$rRj_*oy>Qgwl^#aOQWNS_QM*0Q8n7pY*9|e`) zvW{^Z&xSq^eTQTpt)Y@+kX>pJL(1bU>=^=>07g6$!9*~@GYUq*M4k<%I;nxbp}cee zr_TbX1TMoW1-7Z*A(WTbkP+a=G)aOv&RK7>sA~{jNsAwsw^s^!07QQRrAy}5EEdtb z-3@OV89E+S28Vl~*(yPS+3K}Dsmkh2)@sK)_TH8UEG1fHjV60;x2M1dEhSN9n#tmJ zq6_?$rNsDr=o$Z^^isXW{bWtq#3{ZU?%829W4CuYg3ENj&o}RV&M){}Hynh%;Av7r zsEB9Ct$W&OCNyKl)92k*eCQT|I5L!@702z(zTwLzt8ernIMMtd{rYm;N>6%0P3DT4 z7^$O~lca+H=bt>7A7*_Piaw1UkMN8MvPb|+WYvAm1Sya^RL3{e{m@Go47 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 ca0ceae2f2da461eeee0170efc3e1f9aa3d332c3..34b9465241b46f1cc0f5e2c88ed7518a9eed48ce 100644 GIT binary patch delta 1433 zcmZuv-A^1<6u)jn3bflFFfeeCDb%N>AA~J4d6}Yobx;9{LVe+ z&iSSBhql;H(WrvpY=o~Zd>{EN_7DEki{a0!WF(`VhxjdARBs0mQb^^DTU2$ZO;lpg zRbo+%>dTJuB0Od-*qIlIa||_4leS}}GUUxgT86}&Cl1(JPN#-*EL+d33p9Ci+0jiy z%}r0}xgvc-brxrUKCkB}Sq9+q%gH{dw9)VXR?V9$hLfDnnW|HH;Bvqp?|-T0szI$&*WTn_pI4sY=&!!Z=bxg^ zie;Smvy*ERx}h2xwWp}PY#KJ5o;uox*RsB6CPT^_1HaR+?e9$GT}dkB%?O=4Ey4)K z!`@WYA2{W`EKcK#I~!sM<1TM2n8hRBesD4&!=eiC9sUa93*=%q;0kV)E4o29r%WsCGLs3 zL-V$E7TDG~F8Cl;6NpsQYUXyAcSq`O+Y{cSYkT7RYHo#EE!^Jq=-rijYyLiL0c?wK&%^4mM9|xowVF;qdxCB_ zRu5QK+Urz0ilZ2zj}Qx@;VY%|h0^8GQsx>r`Y#?-C&WvoHo^qZPushk0mZG%U{ xJD0D*L%{F|7y$71W_dpYG7Kw(q&5f-!4e&mM5zw5QW2|L zH$A01BD`rQr2@gAy46L32;STVPeZqeV8S{^eQ)+w1MmC3-+bSjzkBJ=-SJPcn1SH9 zy?1){iLn;{g98@FPj_G8YZzB|Yovy8CwrrO#oKICtzmojx2j^CV?@7*3v5!q(o|r( z4C~+vglA|DE$R*Ym^5%hpTTG0Ttfm$ASsdzl0kB$Hc%U=EfN6{5Q(IK6p#{01*sr4 zk_OU1TC|a^NlsR8=r4^I65J7vMPq@qDuia}9BLTzDyteja?z}^rZEwBd!b#V?r}(N zj(s!o2{$R~6ofj3zy|4f(-C?N;SmZIboj`!640ZZX8mMtd1CeC%H@D2I8FNLEb!Dy zHK4~h&H07O@&xa&J+m*M?VP6kj1B#fm8<`ar#S8R2S&ws-ZKjU?c&t-b3-sb=9wM6 z|L*VTVw^hcghm)Or`!AB(e~xJy9;hVRIbC8%q+IphM8=3l8T@131!GZCcp8(%alU` zfcF4Suipq&Ar1AHcjV2*P!}?gGrTjrT?(m?iSkYu6IC2pg^l|9oiHKPj*Jvfl{|g$ z;E-@xA{A~8?Kqw_c7On(Cb7|2cT+<*@ig`yF8PzyA0$I6TXu*by}b}6e!UiD-zscr zo;4K8(DTPHeY8KMTlKul>-W6*`;mg&KqxK}oH_q~_+6=0Pu=3Pt~XWxDLSqtzJmCB g)naU4Vc%oVjS&!rRkzuCJe4?yE336%2vRis7dUm+IsgCw 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 35f9fc8991ac2f91441c0aa668358f38c141773f..a5dd1a3dac461b5fc744a4e991b223e8b7d1fb6e 100644 GIT binary patch delta 1173 zcma)*%TE(g6vjJ1N*|0&k%2PP>J+5y7(&bNC>SXuF4Pqdb>WKC=};P`56%=58%QLY zn5c<~cj?NwbYV;r{t4KyYwAK1SNsbs(ECxI2_#H1zxi^`nKSo(_sl!{qb=@;qR+)I z)1S`m{}ea8o~q}8owte=_Su_iKi0K9?@K}GVUPR~b%<9V+{ieNMHOu@UVb&9JB?QU zpkDUYzu@lYdAiMh`QNxT$N`q^NDFcHtz-Mn6CSw9Z|A$@cY?Guq8IqTxAu!6Q%Uq6xZiv_vv_ zuG*f+TDDcOuII+z=(Lbyk(e@fZs%A=3cbz`$)xU39vK`8jRIr91b}M2i&~+Zma+G- zuymO{DGfzAydYC2bO%rX;13l!8opzTm-5*&heE@R_TxCMqx8tI64WBF2Fw8q9FEMs zsxtd+bV^M}PL7SLH5Ru$7t9r8wiykXSJ{hMtp?6U&9O3Mt|SO?U1+$=8Oju#>sh`% zqK{zqXcokB0@DL#JI9TqQnI$?EuwjDR%}F9>zu& zCdLgpD;FlZHZDw!8&@ukCa|pI#;q~@19jv5wN#3cgeLRNx#!$D>G|%=bM>ie|6;e> zO#HX|dusXDJNvfPTCrYJvr1m~(vEf9QeTvItq%mjNi(9)bAj)#w52pnVY>HhsIW06 zYeqA_F&8}+ljZ?lXI}ayJ~8_c4$@-lv>?;#)(?YoJaL*|+8e=SDw=+Dc*>pq<&K`R zG*Ir9%Pzj`DQ(#&MCyt-1PAT8T(s}%ZD+mwp`T4?*Udqa`%0n@tA4=GQL%-Yl2)<> zT??}SvLQeQ&H-Uy7>EE-dg0DGh7gW%V1OvYXe>@nXTGt)}lUFhwh@=D9eTc1HZ>BsR^`nkOr;(sz$; zqqc}!av*yfxC6`scY$tt81UVgV@C&<1vZK5BFAP+IHRbFuAI!keqc&iqM@Mls9{?4 zilbNK5yxeXt)Nmpf>A^v}1xr;R;u4&?t(XvqcD@I%G&WEoa4{OkeClVa=IoLmb zsBwv>WCv?UxfM_Wcw{*a!*HSEeW4(|`=}NsfE0&t0 tUj^YR?Tto-1f7cIFXH264A=mQzyx3iM2?E(a&9%Vt}4^)8NG_Be*pAh{t^HH 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"},