Files
ds_quickbooks/__pycache__/main.cpython-311.pyc
T

182 lines
25 KiB
Plaintext
Raw Normal View History

§
£3dh^Lãó"ddlmZmZmZmZddlmZddlmZddlm Z ddl
Z
ddl Z ddl Z ddl
mZmZmZmZmZmZmZmZmZmZmZmZddlmZmZmZddlmZdd l m!Z!dd
l"m#Z#dd l$m%Z%ed d
d¬¦«Z&e& 'edgddgdg¬¦«e¦«Ze#¦«Z"e%¦«Z(iZ)e& *d¦«d¦«Z+e& ,de¬¦«defd¦«Z-e& ,de¬¦«ed¦«fdefd¦«Z.e& ,de¬¦«ed¦«fdefd¦«Z/e& ,de¬¦«d e0fd!„¦«Z1e& *d"¦«d#„¦«Z2e& ,d$e e¬¦«ed¦«fd%e efd&„¦«Z3e& ,d'e¬¦«defd(„¦«Z4e& *d)¦«d*„¦«Z5e& *d+¦«d,e0fd-„¦«Z6e& ,d.e¬¦«defd/„¦«Z7e& ,d0¦«defd1„¦«Z8e& ,d2¦«defd3„¦«Z9e& *d2¦«d4„¦«Z:e& ;d5¦«d6e0fd7„¦«Z<e& *d8¦«d9„¦«Z=e>d:krddl?Z?e?j@e&d;d<¬=¦«dSdS)>é)ÚFastAPIÚ
HTTPExceptionÚ
UploadFileÚFile)ÚCORSMiddleware)Údatetime)ÚListN) ÚMatchingRequestÚMatchingResponseÚ
MatchResponseÚApprovalRequestÚ RuleRequestÚDocumentUploadResponseÚDocumentProcessResponseÚDriveSyncRequestÚDriveSyncResponseÚQuickBooksImportRequestÚQuickBooksImportResponseÚTransactionRequest)ÚReceiptÚ TransactionÚMatch)ÚMatchingEngine)ÚAIRule)ÚDocumentProcessor)ÚGoogleDriveSyncz#AI Bookkeeper - Data Science EnginezˆAI-powered receipt-to-transaction matching engine. Receives QuickBooks data from backend and provides intelligent matching capabilities.ú1.0.0)ÚtitleÚ descriptionÚversionÚ*T)Ú
allow_originsÚallow_credentialsÚ
allow_methodsÚ
allow_headersú/cƒóKddddœS)zHealth check endpointz,AI Bookkeeper Data Science Engine is runningrÚhealthy)Úmessager Ústatus©r+óú"/Users/user/mkd/quickbooks/main.pyÚrootr.,s!èèðBØØð ð ðr,z/transactions/import/quickbooks)Úresponse_modelÚrequestc
ƒó,K g}g}|jD]·} tj|jd¦«}t |j|t
|j¦«|j|j p d|j
pd¬¦«}|  |¦«Œt#t$r7}|  d|jdt|¦«¦«Yd}~Œ°d}~wwxYwtt|¦«||¬¦«S#t$r#}t!d t|¦«¬
¦«d}~wwxYw)
Import and convert QuickBooks transactions to internal format.
This endpoint receives raw QuickBooks transaction data from the backend
and converts it to the internal format used by the AI matching engine.
ú%Y-%m-%dzQuickBooks transaction from zunknown account©ÚidÚtransaction_dateÚamountÚvendorÚnoteszError converting transaction ú: N)Úimported_countÚconverted_transactionsÚerrorséô©Ú status_codeÚdetail)Ú transactionsrÚstrptimeÚtxn_daterr4Úabsr6Ú
payee_nameÚmemoÚ account_nameÚappendÚ ExceptionÚstrrÚlenr)r0r;r<Úqb_txnrCÚ
converted_txnÚes r-Úimport_quickbooks_transactionsrO9slèèð<Ø!#ÐØˆàÔ Uð UˆFð
Uå,¨V¬_¸Iõ!3Ø”yØ%-ݘvœ}Ñ œ+ÐrÐ)rÈÔH[ÐHpÐ_pÐ)rÐ)rð !ñ!ô!
ð'×-¨mÑ<øåð
Uð
Uð
UØ
ÐS¸f¼iÐSÍ3ÈqÉ6Ì6ÐTøøøøð
UøøøõÐ6Ø#9Øð
ñ
ô
ð
øõ ð¨µC¸±F´FÐ;øøøøð<øøøsA
C&A0BÂC&Â
CÂ
-B?Â:C&Â?CÃ!C&Ã&
DÃ0DÄDz/transactions/import/csv.Úfilec
ƒóK | ¦«ƒd{V}| d¦«}tjt j|¦«¦«}g}g}t
|¦«D]\}} | d¦«p&| d ¦«¦«}| d¦«p&| d ¦«¦«} | d¦«p&| d ¦«¦«}
| d ¦«p&| d
 ¦«¦«} | d d ¦« ¦«d
| dd ¦« ¦«d
| dd ¦« ¦« ¦«} |d|dz}
|  ¦«}d}dD]<} tj
||¦«  d¦«}n#t$rYŒ9wxYw|std|¦«t|
 dd ¦« ¦«¦«}| |
|||  ¦«| dœ¦«Œ\#t$r6}| d|dzdt#|¦«¦«Yd}~Œ—d}~wwxYwt%|¬¦«}t'|¦«ƒd{V}t)|d¦«r|j |¦«|S#t$r#}t/dt#|¦«¬¦«d}~wwxYw)zU
Import QuickBooks transactions from a CSV file (custom bank export format).
Nzutf-8zAccount NumberzAccount Number zTransaction DatezTransaction Date ÚAmountzAmount z
Description 2zDescription 2 z Account TypeÚú z
Cheque Numberz
Description 1Ú)z%m/%d/%yz%m/%d/%Yr2zCould not parse date: ú,)r4rCr6rErFzRow r9)rAr<r=r>)ÚreadÚdecodeÚcsvÚ
DictReaderÚioÚStringIOÚ enumerateÚgetÚstriprrBÚstrftimerIÚ
ValueErrorÚfloatÚreplacerHrJrrOÚhasattrr<Úextendr)rPÚcontentÚdecodedÚreaderrAr<ÚidxÚrowÚaccount_numberÚ txn_date_rawÚ
amount_rawrErFÚtxn_idÚ txn_date_strrCÚfmtr6rNÚ request_objÚresponses r-Ú"import_quickbooks_transactions_csvrtaèèð
.Ÿ š ™ œ ÐØ—.’. ÑÝ¥¤ ¨GÑ 4Ô 4ÑØˆ ؈Ý!  8‰HˆCð
8à!$§¢Ð)9Ñ!:Ô!:Ð!`¸c¿gºgÐFW×F]ÒF]ÑF_ÔF_Ñ>`Ô>`Ø"ŸwšwÐ'9Ñb¸c¿gºgÐFY×F_ÒF_ÑFaÔFaÑ>bÔ>b Ø ŸWšW L°#·'²'¸)¿/º/Ñ:KÔ:KÑ2LÔ2L
Ø ŸWšW _ÑZ¸¿ºÐAQ×AWÒAWÑAYÔAYÑ9ZÔ9Z
ØŸ'š' Ñ4×KðK¸s¿wºwÀÐWYÑ?ZÔ?Z×?`Ò?`Ñ?bÔ?bðKðKÐeh×elÒelÐm|Ð}ñfAôfA÷fGòfGñfIôfIðKðK÷QòQñSôSà4¨S°©UÐ4à3 ØØ!!Ý#+Ô#4°\À3Ñ#GÔ#G×#PÒ#PÐQ[Ñ#\Ô#\˜Ø˜øÝ ˜ð!øøøàðNÝ$Ð%L¸lÐ%LÐ%Lјz×1°#°rÑCØ× Ø (Ø$Ø",×"2Ò"2Ñ"4Ô"4Ø ð %ð%ñôðñøõð



Ð6 ¡UÐ6­c°!©f¬fÐ7øøøøð
8øøøõ.¸<Ð Ý7¸ ÑDˆå 8˜  ŒO× "  ˆøÝ ð¨µC¸±F´FÐ;øøøøð<øøøsi„A.MÁ3F"KÈ(IÈ>KÉ
I
É
KÉ I
É
A9KËMË
LË+LË=MÌLÌAMÍ
N Í&NÎN z/uploadcƒódK gd¢}|j d¦«d ¦«}||vrtdd|¬¦«| ¦«ƒd{V}t
 ||j¦«ƒd{V}ttj ¦«¦«}|j||tj ¦«dd œt|<t||j|tj ¦«d¬
¦«S#t$r#}td t|¦«¬¦«d}~wwxYw) zs
Upload a receipt document (PDF or image) for processing.
Supports: PDF, JPG, JPEG, PNG, GIF, BMP
©ÚpdfÚjpgÚjpegÚpngÚgifÚbmpú.éÿÿÿÿéz Unsupported file type. Allowed: r>uploaded©ÚfilenameÚ file_pathÚ file_typeÚ upload_dater*©Úfile_idrr„r…r*r=)rÚsplitÚlowerrrXÚdocument_processorÚsave_uploaded_filerJÚuuidÚuuid4rÚnowÚuploaded_filesrrI)rPÚ
allowed_typesÚfile_extensionÚ file_contentrƒr‡rNs r-Úupload_documentr“šsYèèð#Cˆ
Øœ×,¨SÑ1°"Ô5×=ˆà  Ð ¨CÐ8jÐ[hÐ8jÐ8jÐ "ŸYšY™[œ[Ð õ ÈdÌmÑ\ˆ õ•d”j‘l”lÑðœ
Ø#œ<™>œ>Ø ð #
ð#
õØ”]Ø œ œØð 
ñ
ô
ð
øõ ð¨µC¸±F´FÐ;øøøøð<øøøs„C=DÄ
D/Ä D*Ä*D/z/process/{file_id}r‡c
ƒóäK |tvrtdd¬¦«t|}|d}|d}t ||¦«ƒd{V}d|vrdt|d <n d
t|d <|t|d <t || d d
¦«| d¦«| d¦«| d¦«| d¦«| d¦«| d¦«| d¦«¬¦ « S#t $r#}tdt|¦«¬¦«d}~wwxYw)
Process uploaded document and extract receipt data using AI.
Uses Groq LLM to extract vendor, amount, date, category from receipt images/PDFs.
i”zFile not foundr>r„errorÚfailedr*Ú processedÚextracted_dataÚextraction_successFr7Ú total_amountÚ
tax_amountÚdateÚcategoryÚ
confidence© r‡r™r7rrr•r=)rrÚ process_filerr_rIrJ)r‡Ú file_inforƒr„ÚresultrNs r-Úprocess_documentr£Æs~èèð  ¨CÐ8HÐ " +ˆ ؘ*ˆ ؘkÔ*ˆ õ6°yÀ)Ñð  Ð Ø08N˜ #  -à0;N˜ #  -Ø8>N˜ #Ð$4Ñ Ø%ŸzšzÐ*>ÀÑ—::˜Ÿš —z’z ,јFÑ—Z’Z 
Ñ—z’z ,Ñ—*’*˜WÑ

ñ

ô

ð
øõ ð¨µC¸±F´FÐ;øøøøð<øøøs„D=EÅ
E/Å E*Å*E/z
/documentsc ƒó@K g}t ¦«D]L\}}| ||d|d|d|d| d¦«dœ¦«ŒMd|iS#t$r#}t dt
|¦«¬ ¦«d
}~wwxYw) z)List all uploaded and processed documentsrr„r…r*r˜)r‡rr„r…r*r˜Ú documentsr=r>N)rÚitemsrHr_rIrrJ)r‡rNs r-Úlist_documentsr§îèèðˆ Ý"0×"6Ò"6Ñ"8Ô"8ð ð Ñ ˆG × Ò Ø% & Ô# -Ø"+§-¢-Ð0@Ñ"AÔ"Að
ðñ
ô
ð
ð
ð˜'øå ð¨µC¸±F´FÐ;øøøøð<øøøs„A+A0Á0
BÁ:BÂBz/upload-multipleÚfilescƒófKg}gd¢}|D]¤} |j d¦«d ¦«}||vrB| t d|j|t j¦«d|d¬¦«¦«Œ|| ¦«ƒd{V}t  ||j¦«ƒd{V}ttj ¦«¦«}|j||t j¦«d d
œt|<| t ||j|t j¦«d ¬¦«¦«ŒA#t$rX}| t d|jdt j¦«d t|¦«¬¦«¦«Yd}~Œžd}~wwxYw|S) zv
Upload multiple receipt documents (PDF or image) for processing.
Supports: PDF, JPG, JPEG, PNG, GIF, BMP
rvr}r~rSzfailed: unsupported file type (ú)r†Nr€rzfailed: )rrˆr‰rHrrrXrrJrrrI) r¨Ú responsesrrPrrr‡rNs r-Úupload_multiple_documentsr¬s èèð €IØ?€MØð$ñ$ˆð# Ø!œ]×Ñ5°bÔAˆNØ ]Ð× Ò Õ!7ØØ!œ]Ø,Ý (¤ ¡¤ØN¸ "ñ"ô"ñôððØ!%§¢¡¤Ð,ˆLÝ0×CÀLÐRVÔR_Ñ`ˆ$œ*™,œ,Ñ'ˆ œMØ'œ|™~œ~Ø 'ð'N˜ 
× Ò ÕØœØ$œL™NœNØ ñôñ
ô
ð
ñ
øõð ð ð Ø × Ò ÕØœØÝ$œL™NœNØ*¥# a¡&¤&Ð ñôñ
ô
ð
ð
ð
ð
ð
ñ
øøøøð øøøð Ðs A7E ÂCE Å
F.ÅA
F)Æ)F.z /drive/synccƒóðK t |j¦«ƒd{V}t|¦«}td|D¦«¦«}||z
}g}|D]Ú}| t | dd¦«| dd¦«| d¦«| d¦«| d ¦«| d
¦«| d ¦«| d ¦«| d
¦«¬¦ « ¦«ŒÛt||||¬¦«S#t$r#}tdt|¦«¬¦«d}~wwxYw)
Sync and process receipts from Google Drive folder.
Automatically downloads and processes all receipt files from the specified
Google Drive folder using AI extraction.
Ncó>g|]}| dd¦«¯|ŒS)r™F)r_©Ú.0Úrs r-ú
<listcomp>z%sync_google_drive.<locals>.<listcomp>Cs-Ð%_Ð%_Ð%_¨A¸A¿EºEÐBVÐX]Ñ<^Ô<^Ð%_ aÐ%_Ð%_Ð%_r,r‡rSr™Fr7rrr•)Úfiles_processedÚsuccessful_extractionsÚfailed_extractionsÚresultsr=r>) Ú
drive_syncÚprocess_drive_filesÚ folder_idrKrHrr_rrIrrJ)r0r´Úresponse_resultsr¢rNs r-Úsync_google_driver»5èèð "×6°wÔ7HÑõ˜g™,œ,ˆÝ!$Ð%_Ð%_°Ð%_Ñ%_Ô%_Ñ!`Ô!`ÐØ,Ð/EÑðÐØð ð ˆFØ × #Õ$;ØŸ
š
 9¨bÑ1Ø#)§:¢:Ð.BÀEÑ#JÔ#JØ—zz #ŸZšZ¨Ñ!Ÿ:š: lÑ—ZZ ÑŸš !Ÿ:š: lÑ—j’j Ñ
%ñ
%ô
%ñ
ô
ð
ð
õ+Ø#9Ø
ñ
ô
ð
øõ ð¨µC¸±F´FÐ;øøøøð<øøøs„EEÅ
E5ÅE0Å0E5z/drive/folderscƒó¢K t ¦«}d|iS#t$r#}tdt |¦«¬¦«d}~wwxYw)z(List all accessible Google Drive foldersÚfoldersr=r>N)Ú list_foldersrIrrJ)rNs r-Úlist_drive_foldersr¿_s_èèðר˜7Ð#øå ð¨µC¸±F´FÐ;øøøøð<øøøs!¡
A«A Á Az/drive/folder/{folder_id}r¹cƒó K t |¦«}|S#t$r#}tdt |¦«¬¦«d}~wwxYw)z4Get information about a specific Google Drive folderr=r>N)Úget_folder_inforIrrJ)Ú folder_inforNs r-is\èèð ×Ñ ØÐøå ð¨µC¸±F´FÐ;øøøøð<øøøs  
A
ªAÁA
z/matchcƒóPK d|jD¦«}d|jD¦«}t ||¦«}d|D¦«}t |¦«}t ||¬¦«S#t $r#}tdt|¦«¬¦«d}~wwxYw)
Match receipts to transactions using AI.
Core AI matching engine that compares receipts against QuickBooks transactions
using intelligent algorithms and returns confidence scores.
c óŒg|]A}t|j|j|j|j|j|j|j|j¬¦«ŒBS))r4Ú file_namer…Ú receipt_dater6Útaxr7r) rr4r…r6r7rs r-z/match_receipts_transactions.<locals>.<listcomp>s\ð
ð
ð
ð
õ
Ø”4 1¤;¸A¼MØœ^°A´HÀ!Ä%Ø”x¨!¬*ð
ñ
ô