
    aj:                        d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ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)confirm_budget_plan_item)confirm_budget_transaction)get_budget_status_by_category)get_budget_dashboard_cockpitget_budget_vs_actual_analysis)connect_memory)apply_migrationsc                 @    t                      } t          |            | S )N)r   r   )conns    0tests/unit/test_budget_analytics_dashboard_v2.pydbr      s     DTK    c           
     t   t          | dddd          d         }t          | dddd	d
d          d         }t          | dddddd          d         }t          | dddddd          d         }t          | d|ddddd           t          | d|ddddd           t          | d|ddddd           ||||fS )NHaushaltcheckingCHF)nameaccount_typecurrency	entity_idEssen & Haushaltexpensez#22c55ebasket
   )r   category_typecoloricon
sort_orderzGesundheit / Medizinz#ef4444heart   zLohn Marcelincomez#38bdf8wallet   z	Food Planz2026-01100.00monthlymanual)r   category_id
plan_monthmonthly_amount_chfcadencesource_typezHealth Planz50.00zSalary Plan300.00)r   r   r   r   accountfoodhealthsalarys        r   seed_budgetr5      s   +D:Waot2u2uvv  xC  DG"42DW`kt  G  WY  *Z  *Z  [  [  \g  hD$T4J]fqz  EL  \^  ,_  ,_  `  `  al  mF$TMT\gp  {C  ST  ,U  ,U  V  V  Wb  cFTK\e  ~F  S\  mu  $v  $v  w  w  wTM&`i  BI  V_  px  $y  $y  z  z  zTM&`i  BJ  W`  qy  $z  $z  {  {  {D&&((r   r1   strr2   r3   r4   returnNonec                   t          | |ddddd|d           t          | |ddd	d	d
d|d           t          | |dddddd|d           t          | |ddddd|d           t          | |ddddd|d           |                     d|f           |                     d|f           |                     d|f           |                                  d S )Nr$   z
2026-05-25Lohnr/   r   )
account_idtransaction_typetransaction_datedescriptionamount_originalcurrency_originalr*   r   z
2026-05-03Migros120.00)r;   r<   r=   r>   payeer?   r@   r*   z
2026-05-10Apothekez40.00z
2026-02-10z
Migros Febz80.00z
2025-05-10Altjahr999.00a  INSERT INTO budget_transactions(budget_transaction_id, account_id, category_id, transaction_date, transaction_type, description, amount_original, currency_original, amount_chf, fx_status, source_type, status, created_at, updated_at) VALUES ('tx_transfer', ?, NULL, '2026-05-11', 'transfer', 'Umbuchung', '777.00', 'CHF', '777.00', 'not_needed', 'manual', 'confirmed', '2026', '2026')aP  INSERT INTO budget_transaction_candidates(transaction_candidate_id, source_type, source_file_label, transaction_date, description, merchant, amount_original, currency_original, proposed_category_id, status, created_at, updated_at) VALUES ('cand_open','csv','x','2026-05-12','Candidate','Migros','888.00','CHF',?,'pending','2026','2026')ab  INSERT INTO budget_transaction_candidates(transaction_candidate_id, source_type, source_file_label, transaction_date, description, merchant, amount_original, currency_original, proposed_category_id, status, created_at, updated_at) VALUES ('cand_covered','csv','x','2026-05-13','Covered Migros','Migros','999.00','CHF',?,'covered_by_migros','2026','2026'))r   executecommitr0   s        r   seed_transactionsrI      s   tGQYo{  MS  hp  GL  ]c  &d  &d  e  e  etGQZp|  NV  ai  ~F  ]b  sw  &x  &x  y  y  ytGQZp|  NX  cm  BI  `e  v|  &}  &}  ~  ~  ~tGQZp|  NZ  ov  MR  cg  &h  &h  i  i  itGQZp|  NW  lt  KP  ae  &f  &f  g  g  gLL  S  V]  U_  `  `  `LL  d  gk  fm  n  n  nLL  v  y}  x  @  @  @KKMMMMMr   c                b   t                      }t          |          \  }}}}t          |||||           t          |d          }|d         dk    sJ |d         dk    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         d         dk    sJ |d         d         dk    sJ t	          d |fD                       sJ |d         d         d         dk    sJ |d         sJ |d         d         dk    sJ d S )N2026-05)monthpurposemonthly_cockpitrL   kpisincome_current_month_chfr/   expense_current_month_chfz160.00net_cashflow_current_month_chf140.00budget_consumption_percentz106.67savings_rate_percentz46.67
open_todosreview_candidatesr&   c              3  |   K   | ]7}d t          |          vo!dt          |          vodt          |          vV  8dS )888.00rF   777.00N)r6   ).0sections     r   	<genexpr>zftest_budget_dashboard_cockpit_is_monthly_and_excludes_candidates_transfers_and_2025.<locals>.<genexpr>:   sk        G  Gryxs7||+mG0LmQYadelamamQm  G  G  G  G  G  Gr   top_expense_categoriesr   categoryr   critical_categoriesmonthly_cashflow
income_chf)r   r5   rI   r	   allbudget_reference_dater   r1   r2   r3   r4   results          r   Stest_budget_dashboard_cockpit_is_monthly_and_excludes_candidates_transfers_and_2025rg   +   s    44D$/$5$5!GT66dGT66:::)$i@@@F) 11111'?i''''&>45AAAA&>56(BBBB&>:;xGGGG&>678CCCC&>01W<<<<, 349999  G  G  E  ~F  G  G  G  G  G  G  G  G*+A.z:>PPPPP'(((($%l3x??????r   c                   t                      }t          |          \  }}}t          ||||           t          |d          }t	          fd|D                       }|d         dk    sJ |d         dk    sJ |d         d	k    sJ |d
         dk    sJ |d         dk    sJ t          |d                   dk    sJ |d         d         d         dk    sJ dt          |          vsJ d S )N2026yearc              3  4   K   | ]}|d          k    |V  dS )r*   N )r[   rr2   s     r   r]   z_test_budget_status_rows_are_operational_category_control_with_monthly_detail.<locals>.<genexpr>G   s2      @@!q'74'?'?A'?'?'?'?@@r   rM   category_controlbudget_monthr'   budget_yearz1200.00actual_current_monthrB   actual_year_to_datez200.00monthly_analysis      
actual_chfrF   )r   r5   rI   r   nextlenr6   )re   r   r1   r3   r4   rowsfood_rowr2   s          @r   Ltest_budget_status_rows_are_operational_category_control_with_monthly_detailr|   @   s<    44D$/$5$5!GT66dGT66:::(F;;;D@@@@t@@@@@HI"44444N#x////M"i////*+x7777)*h6666x*+,,2222&'*<8HDDDD3x==((((((r   c                   t                      }t          |          \  }}}}t          |||||           t          |d          }|d         dk    sJ |d         dk    sJ |d         dk    sJ |d         d	u sJ |d
         sJ |d         d         d         dk    sJ |d         d         d         dk    sJ |d         d         d         dk    sJ |d         d         d         dk    sJ |d         d         d         dk    sJ dt	          |          vsJ dt	          |          vsJ dt	          |          vsJ d S )Nri   rj   rM   plan_vs_reality_analysisrk   chart_libraryz
native-svgempty_stateFbudget_vs_actual_by_categorytop_overrunsr   r_   r   cashflow_by_monthrv   rL   rK   net_cashflow_chfrS   category_donuttrend_by_monthcumulative_net_chfz60.00rZ   rY   rF   )r   r5   rI   r
   r6   rd   s          r   :test_budget_vs_actual_analysis_is_separate_chart_viewmodelr   R   s   44D$/$5$5!GT66dGT66:::*4f===F) :::::&>V####/"l2222- E))))01111.!!$Z04FFFFF%&q)'2i????%&q)*<=IIII"#A&z26HHHHH"#A&';<GGGG3v;;&&&&3v;;&&&&3v;;&&&&&&r   N)
r1   r6   r2   r6   r3   r6   r4   r6   r7   r8   )r7   r8   )
__future__r   'jarvis_finance.services.budget_accountsr   )jarvis_finance.services.budget_categoriesr   $jarvis_finance.services.budget_plansr   +jarvis_finance.services.budget_transactionsr   'jarvis_finance.services.budget_overviewr   +jarvis_finance.services.budget_analytics_v2r	   r
   jarvis_finance.storage.databaser   !jarvis_finance.storage.migrationsr   r   r5   rI   rg   r|   r   rm   r   r   <module>r      s)   " " " " " " Q Q Q Q Q Q M M M M M M I I I I I I R R R R R R Q Q Q Q Q Q s s s s s s s s : : : : : : > > > > > >  ) ) )
 
 
 
@ @ @ @*) ) ) )$' ' ' ' ' 'r   