
    |j                        d dl mZ d dlmZ d dlmZ d dlmZmZm	Z	m
Z
 d dlmZ d dlmZ d dlmZ d Zd	 ZddZddZddZddZdS )    )annotations)confirm_create_budget_account)confirm_create_category)batch_mark_candidateslist_transaction_candidates preview_batch_confirm_candidates%seed_credit_card_candidates_from_rows)list_budget_transactions)connect_memory)apply_migrationsc                 @    t                      } t          |            | S )N)r   r   )conns    4tests/unit/test_budget_review_bulk_assign_confirm.pydbr      s     DTK    c           
        t          | dddd          d         }t          | ddd          d         }t          | d	dd          d         }t          | d
dddddddddddddddgdd           t          | d          }d |D             }|                     d|d         f           |                                  ||||fS )NzReview KontocashCHF)nameaccount_typecurrency	entity_idzEssen & Haushaltexpense)r   category_typezElektronische Medienz
2026-05-01APPLE.COM/BILLz9.90)DatumBeschreibungBetragz
2026-05-02GOOGLE STORAGEz2.00z
2026-05-03NETFLIXz19.90z
2026-05-04COVERED SOURCEz5.00zvisa.csvF)source_file_labelmigros_coveredT)include_referencec                ,    i | ]}|d          |d         S )descriptiontransaction_candidate_id .0rows     r   
<dictcomp>zsetup_bulk.<locals>.<dictcomp>&   s%    SSSss=!3'A#BSSSr   zdUPDATE budget_transaction_candidates SET status='covered_by_source' WHERE transaction_candidate_id=?)r   r   r	   r   executecommit)r   
account_idfood_idmedia_idrowsby_descs         r   
setup_bulkr4      sD   .tn^drw5x5xyy  {F  GJ%d5GZc,d,deefqrG&t6L_h-i-ijjkvwH)"4DPVWW"4DPVWW"IQQ"4DPVWW		
 %
 
 
 
 'ttDDDDSSdSSSGLLw  {B  CS  {T  zV  W  W  WKKMMMw'11r   returnNonec                    t                      } t          |           \  }}}}t          | |d         |d         |d         gd|d          }|d         dk    sJ |d	         d
k    sJ |d         d         d         |d         k    sJ |                     d|d         f                                          }|                     d|d         f                                          }|d         |k    sJ |d         J |d         dk    sJ |                     d                                          d         dk    sJ d S )Nr   r   r!   category2026candidate_idsactioncategory_idbudget_yearupdated_count   skipped_count   errorsr   candidate_idz_SELECT proposed_category_id FROM budget_transaction_candidates WHERE transaction_candidate_id=?zgSELECT proposed_category_id, status FROM budget_transaction_candidates WHERE transaction_candidate_id=?proposed_category_idstatuscovered_by_sourcez^SELECT COUNT(*) FROM audit_log WHERE action IN ('batch_category_candidates','update_category'))r   r4   r   r-   fetchone)r   _account_id_food_idr1   idsresulteditableblockeds           r   Ytest_bulk_category_assignment_updates_only_editable_candidates_and_reports_partial_errorsrO   ,   s   44D+5d+;+;(K8S"+,c2B.CSIYEZ[  F /"a''''/"a''''(A~.#6F2GGGGG||}  AD  EU  AV  @X  Y  Y  b  b  d  dHll  E  HK  L\  H]  G_  `  `  i  i  k  kG*+x7777)*2228 33333<<xyy  C  C  E  E  FG  H  LM  M  M  M  M  M  Mr   c                    t                      } t          |           \  }}}}t          | |d         gd|d           |                     d|d         f           |                     d|d         f           |                                  t          | |d         |d         |d         |d	         g|d
          }|d         dk    sJ d |d         D             }d||d                  v sJ d||d                  v sJ d||d	                  v sJ |d         d         dk    sJ |d         d         dk    sJ |d         d         dk    sJ |d         d         dk    sJ d S )Nr   r8   r9   r:   zfUPDATE budget_transaction_candidates SET status='duplicate_candidate' WHERE transaction_candidate_id=?r   zUPDATE budget_transaction_candidates SET status='transfer_candidate', classification='transfer_candidate' WHERE transaction_candidate_id=?r    r!   r;   r/   r>   countrB   c                ,    i | ]}|d          |d         S )rD   reasonr(   )r*   items     r   r,   zgtest_bulk_confirm_preview_blocks_duplicates_covered_transfer_and_missing_categories.<locals>.<dictcomp>S   s#    UUUtN#T(^UUUr   	conflicts	duplicatetransferrG   blockersduplicate_candidatestransfer_candidateswithout_categoryr   )r   r4   r   r-   r.   r   )r   r/   rJ   r1   rK   previewreasonss          r   Stest_bulk_confirm_preview_blocks_duplicates_covered_transfer_and_missing_categoriesr_   C   s	   44D*4T*:*:'J(C$s3C/D.Ejfn  }C  D  D  D  DLLy|  AQ  }R  |T  U  U  ULL  ^  ad  en  ao  `q  r  r  rKKMMM.+,c2B.CS^UXYiUjk	  G 7q    UU@TUUUG'#&6"788888Y00000'#.>*?"@@@@@:56!;;;;:45:::::23q8888:12a777777r   c                 v   t                      } t          |           \  }}}}|d         |d         g}t          | |d|d           t          | ||d          }t          | |d||d         d	          }|d
         dk    sJ |d         dk    sJ |                     d|                                          }d |D             dhk    sJ t          d |D                       sJ t          t          | dd                    dk    sJ d t          |           D             }	t          |          |	z  rJ d S )Nr   r   r8   r9   r:   rQ   confirm
preview_id)r;   r<   r/   rb   r>   confirmed_countr@   rA   r   zSELECT status, confirmed_transaction_id FROM budget_transaction_candidates WHERE transaction_candidate_id IN (?, ?) ORDER BY transaction_candidate_idc                    h | ]
}|d          S rF   r(   r)   s     r   	<setcomp>zktest_bulk_confirm_creates_transactions_sets_candidate_links_and_removes_from_open_review.<locals>.<setcomp>p   s    ***cCM***r   	confirmedc              3  &   K   | ]}|d          V  dS )confirmed_transaction_idNr(   r)   s     r   	<genexpr>zktest_bulk_confirm_creates_transactions_sets_candidate_links_and_removes_from_open_review.<locals>.<genexpr>q   s(      ??3s-.??????r   r   )transaction_typeyearc                    h | ]
}|d          S )r'   r(   r)   s     r   rf   zktest_bulk_confirm_creates_transactions_sets_candidate_links_and_removes_from_open_review.<locals>.<setcomp>s   s    ]]]C./]]]r   )r   r4   r   r   r-   fetchallalllenr
   r   set)
r   r/   rJ   r1   rK   selectedr]   rL   r2   open_idss
             r   Xtest_bulk_confirm_creates_transactions_sets_candidate_links_and_removes_from_open_reviewrt   ]   s   44D*4T*:*:'J(C$%s+;'<=H$hzW_mstttt.t8XbpvwwwG"<(  F #$))))/"a''''<<  p  rz  {  {  D  D  F  FD**T***{m;;;;??$????????'yvVVVWW[\\\\\]];VW[;\;\]]]H8}}x''''''r   c                    t                      } t          |           \  }}}}|d         |d         g}t          | |dd          }t          | |dd          }|d         dk    sJ |d	         dk    sJ d
 |                     d|                                          D             }|ddhk    sJ |                     d                                          d         dk    sJ d S )Nr   r   ignorer9   )r;   r<   r>   reopenignored_countr@   reopened_countc                    h | ]
}|d          S re   r(   r)   s     r   rf   zMtest_bulk_ignore_and_reopen_multiple_candidates_with_audit.<locals>.<setcomp>   s.      i  i  i#H  i  i  ir   zYSELECT status FROM budget_transaction_candidates WHERE transaction_candidate_id IN (?, ?)pendingneeds_reviewzvSELECT COUNT(*) FROM audit_log WHERE action IN ('batch_ignore_candidates','batch_reopen_candidates','ignore','reopen')r      )r   r4   r   r-   rn   rH   )	r   rI   rJ   	_media_idrK   rr   ignoredreopenedstatusess	            r   :test_bulk_ignore_and_reopen_multiple_candidates_with_auditr   w   sh   44D,6t,<,<)K9c$%s+;'<=H#D_efffG$T(`fgggH?#q(((($%**** i  i  7R  T\  *]  *]  *f  *f  *h  *h  i  i  iH	>22222<<  Q  R  R  [  [  ]  ]  ^_  `  de  e  e  e  e  e  er   N)r5   r6   )
__future__r   'jarvis_finance.services.budget_accountsr   )jarvis_finance.services.budget_categoriesr   &jarvis_finance.services.budget_importsr   r   r   r	   +jarvis_finance.services.budget_transactionsr
   jarvis_finance.storage.databaser   !jarvis_finance.storage.migrationsr   r   r4   rO   r_   rt   r   r(   r   r   <module>r      s2   " " " " " " Q Q Q Q Q Q M M M M M M            Q P P P P P : : : : : : > > > > > >  2 2 2,M M M M.8 8 8 84( ( ( (4e e e e e er   