
    ܴ
j                        d dl mZ d dlZd dlmc mZ d dlZd dl	m
Z
 d dlmZmZmZmZ d dlmZmZmZmZmZmZmZ d dlmZ d dlmZmZmZ d dlmZ d d	l m!Z! d
 Z"ddZ#ddZ$ddZ%dS )    )annotationsN)confirm_create_budget_account)confirm_category_mergeconfirm_create_categorydelete_empty_categorypreview_category_merges)batch_confirm_safe_candidates*bulk_update_transaction_candidate_categoryignore_transaction_candidatelist_transaction_candidatespreview_safe_auto_candidatesreopen_transaction_candidate%seed_transaction_candidates_from_rows)confirm_budget_plan_item)confirm_budget_transactionlist_budget_transactionsupdate_budget_transaction)connect_memory)apply_migrationsc                 @    t                      } t          |            | S )N)r   r   )conns    V/home/agent/.hermes/repos/FinanceManager/tests/unit/test_budget_phase17_ux_workflow.pydbr      s     DTK    returnNonec                    t                      } t          | dddd          d         }t          | ddd          d         }t          | d	d
ddgdd           t	          |           d         d         }|                     d|f           |                                  t          | |g|d          }ddd}||k    }|st          j	        d|fd||f          dt          j                    v st          j        |          rt          j        |          ndt          j        |          dz  }dd|iz  }t          t          j        |                    d x}}t	          |           d         }	|	d         }
|
|k    }|st          j	        d|fd|
|f          t          j        |
          dt          j                    v st          j        |          rt          j        |          ndd z  }dd|iz  }t          t          j        |                    d x}
}|	d!         }
d}|
|k    }|slt          j	        d|fd"|
|f          t          j        |
          t          j        |          d#z  }d$d%|iz  }t          t          j        |                    d x}
x}}t!          | |d&          }|d'         }
d(}|
|k    }|slt          j	        d|fd"|
|f          t          j        |
          t          j        |          d#z  }d$d%|iz  }t          t          j        |                    d x}
x}}t#          | |d)          }|d'         }
d*d+h}|
|v }|slt          j	        d,|fd-|
|f          t          j        |
          t          j        |          d#z  }d$d%|iz  }t          t          j        |                    d x}
x}}t%          |           }|d.         }
d}|
|k    }|slt          j	        d|fd"|
|f          t          j        |
          t          j        |          d#z  }d$d%|iz  }t          t          j        |                    d x}
x}}t'          | ||g/          }|d0         }
d}|
|k    }|slt          j	        d|fd"|
|f          t          j        |
          t          j        |          d#z  }d$d%|iz  }t          t          j        |                    d x}
x}}d}d1}t)          | ||2          }|sd3d4t          j                    v st          j        t(                    rt          j        t(                    nd4d5t          j                    v st          j        |           rt          j        |           nd5t          j        |          t          j        |          t          j        |          d6z  }t          t          j        |                    d x}x}}d S )7NBudget KontocashCHFnameaccount_typecurrency	entity_idAbosexpenser"   category_typez
2026-01-02zStreaming Aboz12.00)DatumArtikelUmsatzzvisa.csvcredit_card_csv)source_file_labelsource_typer   transaction_candidate_idzUPDATE budget_transaction_candidates SET classification='subscription_auto', requires_review=0, status='pending' WHERE transaction_candidate_id=?z	test bulk)candidate_idscategory_idnote   )updated_countskipped_count==)z%(py0)s == %(py3)sresult)py0py3zassert %(py5)spy5proposed_category_id)z%(py1)s == %(py3)scat)py1r;   amount_originalz%(py1)s == %(py4)sr?   py4assert %(py6)spy6ztest ignorestatusignoredundopendingneeds_review)in)z%(py1)s in %(py4)scount)
account_idr1   confirmed_count	confirmed)transaction_typerF   zVassert %(py7)s
{%(py7)s = %(py0)s(%(py1)s, transaction_type=%(py3)s, status=%(py5)s)
}r   r   )r:   r?   r;   r<   py7)r   r   r   r   r   executecommitr
   
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanationr   r   r   r	   r   )r   accountr>   cidr9   @py_assert2@py_assert1@py_format4@py_format6updated@py_assert0@py_assert3@py_format5@py_format7rG   reopenedpreviewrO   @py_assert4@py_assert6@py_format8s                        r   Gtest_phase17_import_review_bulk_category_ignore_reopen_and_safe_previewrl   !   s?   44D+D>[aot2u2uvv  xC  DG
!$)(T(T
U
UVa
bC)Ow	O	OP$%	    &d
+
+A
./I
JCLL  e  hk  gm  n  n  nKKMMM7SE_bituuuF'(1===6===========6=============6=====6================================)$//2G)*1*c1111111111*c11111*11111111111c11111c111111111111111111111111111$%00%0000000000%00000%0000000000000000000000000000000*4mDDG8)	)	))))))))))	)))))))))	)))))))))))))))))))))))))))+D#v>>HH<)^!<<!<<<<<<<<<<<!<<<<<<<<<<!<<<<<<<<<<<<<<<<<<<<<<<<<<<<*400G7 q q          q         q                           -dwWZV[\\\I&',1,'1,,,,,,,,,,'1,,,,,',,,,1,,,,,,,,,,,,,,,,,,,,,,,,,,,;DY[Y#D9[YYYYYYYYYYYYYYYY#YYYYY#YYYYYYYYYYYYYDYYYYYDYYYYYY9YYYY[YYYYYYYYYYYYYYYYYYYYYYYYYYYYr   c            
     h   t                      } t          | dddd          d         }t          | ddd          d         }t          | |dd	d
ddd          d         }d}d}d}t	          | |||          }|sddt          j                    v st          j        t                    rt          j	        t                    nddt          j                    v st          j        |           rt          j	        |           ndt          j	        |          t          j	        |          t          j	        |          t          j	        |          dz  }t          t          j        |                    d x}x}x}}t          | ||dgdd           d}d}	d}
t	          | |||	|
          }|s7ddt          j                    v st          j        t                    rt          j	        t                    nddt          j                    v st          j        |           rt          j	        |           ndt          j	        |          dt          j                    v st          j        |          rt          j	        |          ndt          j	        |	          t          j	        |
          t          j	        |          dz  }t          t          j        |                    d x}x}	x}
}t          j        t                    5  t          | |ddi           d d d            d S # 1 swxY w Y   d S )Nr   r   r    r!   r%   Haushaltr'   r(   z
2026-02-03z
Merchant Xz42.00)rM   rP   transaction_datedescriptionr@   currency_originalrO   __uncategorized)rP   rF   r2   zkassert %(py9)s
{%(py9)s = %(py0)s(%(py1)s, transaction_type=%(py3)s, status=%(py5)s, category_id=%(py7)s)
}r   r   )r:   r?   r;   r<   rQ   py9Reviewphase17)r2   	tag_nameschange_noteMerchant)rP   r2   tagsearchzzassert %(py10)s
{%(py10)s = %(py0)s(%(py1)s, transaction_type=%(py3)s, category_id=%(py4)s, tag=%(py6)s, search=%(py8)s)
}r>   )r:   r?   r;   rC   rE   py8py10r@   z99.00)r   r   r   r   r   rV   rW   rT   rX   rY   rZ   r[   r   pytestraises	Exception)r   r\   r>   txr^   ri   rj   @py_assert8@py_format10@py_assert5@py_assert7@py_assert9@py_format11s                r   >test_phase17_effective_expenses_filters_and_no_amount_mutationr   A   s   44D+D>[aot2u2uvv  xC  DG
!$i(X(X
Y
YZe
fC	#DV_  vB  S_  t{  RW  +X  +X  
Y  
Y  Ze  
fB;Dx[xfwx#D9[fwxxxxxxxxxxxxxxxx#xxxxx#xxxxxxxxxxxxxDxxxxxDxxxxxx9xxxx[xxxxfwxxxxxxxxxxxxxxxxxxxxxxxxxxxxdB8*en(o(oppp;Dw[cwlvw#D9RU[clvwwwwwwwwwwwwwwww#wwwww#wwwwwwwwwwwwwDwwwwwDwwwwww9wwwwwwwwwwwRUwwwwwRUwwwwww[cwwwwlvwwwwwwwwwwwwwwwwwwwwwwwwwwww	y	!	! J J!$->,HIIIJ J J J J J J J J J J J J J J J J Js   L''L+.L+c                 	   t                      } t          | dddd          d         }t          | ddd          d         }t          | |          d	         }d
}||k    }|slt	          j        d|fd||f          t	          j        |          t	          j        |          dz  }dd|iz  }t          t	          j        |                    d x}x}}t          | ddd          d         t          | ddd          d         }t          | dd|d          d         t          | |dddddd           t          | dddddd           t          |           }	fd|	d         D             }
t          |
          }|sdd t          j                    v st	          j        t                    rt	          j        t                    nd t	          j        |
          t	          j        |          d!z  }t          t	          j        |                    d x}
}t!          | gd"d#          }|d$         }d%}||k    }|slt	          j        d|fd||f          t	          j        |          t	          j        |          dz  }dd|iz  }t          t	          j        |                    d x}x}}|d&         }d%}||k    }|slt	          j        d|fd||f          t	          j        |          t	          j        |          dz  }dd|iz  }t          t	          j        |                    d x}x}}t#          | '          }|sd(d)t          j                    v st	          j        t"                    rt	          j        t"                    nd)d*t          j                    v st	          j        |           rt	          j        |           nd*d+t          j                    v st	          j                  rt	          j                  nd+t	          j        |          d,z  }t          t	          j        |                    d }|                     d-f                                          d.         }d.}||k    }|slt	          j        d|fd||f          t	          j        |          t	          j        |          dz  }dd|iz  }t          t	          j        |                    d x}x}}d S )/Nr   r   r    r!   r%   Leerr'   r(   rF   deletedr7   rA   rB   rD   rE   VersicherungenzLegacy Parentversicherungen)r"   r)   parent_category_idz
2026-01-10Policez10.00)rM   rP   ro   rp   r@   rq   r2   z2026-01Planmonthlymanual)
plan_monthr2   r"   monthly_amount_chfcadencer/   c              3  @   K   | ]}|d          v p	|d         v V  dS )target_category_idsource_category_idsN ).0ssourcetargets     r   	<genexpr>zVtest_phase17_category_tree_delete_empty_archive_non_empty_and_merge.<locals>.<genexpr>Y   s?      ww[\v/00VFa@U>V4Vwwwwwwr   suggestionsz,assert %(py4)s
{%(py4)s = %(py0)s(%(py2)s)
}any)r:   py2rC   z
test merge)r   r   r3   moved_transactionsr4   moved_budget_plans)r2   zAassert %(py4)s
{%(py4)s = %(py0)s(%(py1)s, category_id=%(py2)s)
}r   r   r   )r:   r?   r   rC   z;SELECT is_active FROM budget_categories WHERE category_id=?r   )r   r   r   r   rT   rU   rY   rZ   r[   r   r   r   r   rV   rW   rX   r   r   rR   fetchone)r   r\   emptyrc   rd   r^   re   rf   parentrh   r_   r9   r   r   s               @@r   Ctest_phase17_category_tree_delete_empty_archive_non_empty_and_merger   M   s   44D+D>[aot2u2uvv  xC  DG#D6I*V*VWWXcdE u--h7D9D79DDDDDDDDDD79DDDDD7DDDD9DDDDDDDDDDDDDDDDDDDDDDDDDDD$T4DW`+a+abbcnoF$TOV_+`+`aabmnF$T4DW`x~++  A  A  BM  NFtGQZp|  NV  kr  IN  _e  &f  &f  g  g  gT)F\b  {B  OX  iq  $r  $r  s  s  s%d++Gwwwww`ghu`vwwww3wwwwwwwwwwwwwwww3wwwww3wwwwwwwwwwwwwwwwwwwwwwwwwwwwwww#Dag`hr~**  A  AF&',1,'1,,,,,,,,,,'1,,,,,',,,,1,,,,,,,,,,,,,,,,,,,,,,,,,,,&',1,'1,,,,,,,,,,'1,,,,,',,,,1,,,,,,,,,,,,,,,,,,,,,,,,,,,#Df================#=====#=============D=====D=============f=====f========================<<UX^W`aajjllmnotsttostttttttttttosttttttottttsttttttttttttttttttttttttttttttr   )r   r   )&
__future__r   builtinsrV   _pytest.assertion.rewrite	assertionrewriterT   r}   'jarvis_finance.services.budget_accountsr   )jarvis_finance.services.budget_categoriesr   r   r   r   &jarvis_finance.services.budget_importsr	   r
   r   r   r   r   r   $jarvis_finance.services.budget_plansr   +jarvis_finance.services.budget_transactionsr   r   r   jarvis_finance.storage.databaser   !jarvis_finance.storage.migrationsr   r   rl   r   r   r   r   r   <module>r      s   " " " " " "               Q Q Q Q Q Q                             J I I I I I H  H  H  H  H  H  H  H  H  H : : : : : : > > > > > >  Z Z Z Z@	J 	J 	J 	Ju u u u u ur   