
    \j%;                     z    d dl 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  G d	 d
e      Zy)    N)Decimal)TestCase)User)timezone)Member)AccountTransactionAccountHead)getCurrentTaxYearRangec                   H    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)FinancialRollupEngineTestCasec           
      .   t         j                  j                  dd      | _        t        j                  j                  ddd| j                        | _        t        j                  j                  dd	d
dt        d      t        d      d      | _	        y )Ntestaccountantpassword123)usernamepasswordzGeneral Kovil FundRevenueT)nameaccount_type	is_active
created_byzMurugan Swamyu(   முருகன் சுவாமி
9876543210z123 Temple St0.00)r   name_taphoneaddress
annual_taxamount_paidis_family_head)
r   objectscreate_useruserr	   createaccount_headr   r   member)selfs    QC:\applications\kalingar-portal\kalingar-portal\trust-backend\accounting\tests.pysetUpz#FinancialRollupEngineTestCase.setUp   s    LL,,6FQ^,_	 (//66%"yy	 7 
 nn++ >#v , 
    c                    t        t        j                  ddd            \  }}| j                  |t        j                  ddd             | j                  |t        j                  ddd             t        t        j                  ddd            \  }}| j                  |t        j                  ddd             | j                  |t        j                  ddd             t        t        j                  ddd	            \  }}| j                  |t        j                  ddd             | j                  |t        j                  ddd             t        t        j                  ddd
            \  }}| j                  |t        j                  ddd             | j                  |t        j                  ddd             y )Ni                i        
   )r
   datetimedateassertEqual)r%   startends      r&   test_getCurrentTaxYearRangez9FinancialRollupEngineTestCase.test_getCurrentTaxYearRange"   s^    ,HMM$2,FG
sdAq 9:hmmD!R89 ,HMM$1,EF
sdAq 9:hmmD!R89 ,HMM$B,GH
sdAq 9:hmmD!R89 ,HMM$2,FG
sdAq 9:hmmD!R89r(   c           	         t        j                  ddd      }t        j                  j	                  | j
                  dt        d      |d| j                  | j                        }| j                  j                          | j                  | j                  j                  t        d             | j                  | j                  j                  t        d             | j                  | j                  j                  t        d             t        j                  j	                  | j
                  d	t        d
      |d| j                  | j                        }| j                  j                          | j                  | j                  j                  t        d             | j                  | j                  j                  t        d
             | j                  | j                  j                  t        d             y )Nr,   	      DEBIT5000.00Creditr#   transaction_typeamounttransaction_datepayment_moder$   
entered_byr   CREDIT3000.00Cash2000.00)r2   r3   r   r   r"   r#   r   r$   r!   refresh_from_dbr4   r   r   
amount_due)r%   tx_datedebit_tx	credit_txs       r&   "test_debit_credit_rollup_on_createz@FinancialRollupEngineTestCase.test_debit_credit_rollup_on_create9   sy   --a,%--44**$9%$!;;yy 5 
 	##%//1CD00'&/B//1CD '..55**%9%$;;yy 6 
	 	##%//1CD00')2DE//1CDr(   c           	      0   t        j                  ddd      }t        j                  j	                  | j
                  dt        d      |d| j                  | j                        }| j                  j                          | j                  | j                  j                  t        d             t        d      |_        |j                          | j                  j                          | j                  | j                  j                  t        d             y )	Nr,   r9   r:   r;   r<   r=   r>   z7500.00)r2   r3   r   r   r"   r#   r   r$   r!   rH   r4   r   r@   save)r%   rJ   rK   s      r&   !test_recalculation_on_edit_amountz?FinancialRollupEngineTestCase.test_recalculation_on_edit_amount]   s    --a, &--44**$9%$!;;yy 5 
 	##%//1CD "), 	##%//1CDr(   c           	         t        j                  ddd      }t        j                  j	                  | j
                  dt        d      |d| j                  | j                        }| j                  j                          | j                  | j                  j                  t        d             t        j                  ddd	      }t        j                  j	                  | j
                  dt        d
      |d| j                  | j                        }| j                  j                          | j                  | j                  j                  t        d
             t        j                  ddd      |_        t        d      |_        |j                          | j                  j                          | j                  | j                  j                  t        d             ddlm}  || j                  |       | j                  j                          | j                  | j                  j                  t        d             y )Nr,   r*   r+   r;   4000.00r=   r>   r-   r.   6000.00r1   rE   z9000.00r   )recalculate_member_financialsr   )r2   r3   r   r   r"   r#   r   r$   r!   rH   r4   r   rA   r@   rO   accounting.utilsrT   )r%   date_old_yeartx_olddate_new_yeartx_newrT   s         r&   6test_recalculation_on_edit_date_across_fiscal_boundaryzTFinancialRollupEngineTestCase.test_recalculation_on_edit_date_across_fiscal_boundaryw   s    dAr2#++22**$9%*!;;yy 3 
 	##%//1CD !dAq1#++22**$9%*!;;yy 3 
 	##%//1CD #+--a"<	* 	##%//1CD 	C%dkk=A##%//Ar(   c           	         t        j                  ddd      }t        j                  j	                  | j
                  dt        d      |d| j                  | j                        }t        j                  j	                  | j
                  dt        d      |d| j                  | j                        }| j                  j                          | j                  | j                  j                  t        d	             d
|_        |j                          | j                  j                          | j                  | j                  j                  t        d             y )Nr,   r1      r;   z3500.00r=   r>   z1500.00r<   T)r2   r3   r   r   r"   r#   r   r$   r!   rH   r4   r   
is_deletedrO   r%   rJ   tx1tx2s       r&   test_soft_delete_recalculationz<FinancialRollupEngineTestCase.test_soft_delete_recalculation   s   --b!, ((//**$9%$!;;yy 0 
 !((//**$9%$!;;yy 0 
 	##%//1CD 
 	##%//1CDr(   c           	         t        j                  ddd      }t        j                  j	                  | j
                  dt        d      |d| j                  | j                        }t        j                  j	                  | j
                  dt        d      |d| j                  | j                        }| j                  j                          | j                  | j                  j                  t        d	             |j                          | j                  j                          | j                  | j                  j                  t        d             y )
Nr,         r;   rG   r=   r>   rR   rS   )r2   r3   r   r   r"   r#   r   r$   r!   rH   r4   r   deleter^   s       r&   test_hard_delete_recalculationz<FinancialRollupEngineTestCase.test_hard_delete_recalculation   s	   --b"- ((//**$9%$!;;yy 0 
 !((//**$9%$!;;yy 0 
 	##%//1CD 	

 	##%//1CDr(   c                 D   ddl m} ddlm} ddlm} | j                  j                  dt        d      t        j                  ddd	      d
| j                  j                  d} ||      }| j                  |      5  |j                  d       d d d        |j                  j                  dd
d| j                  d| j                         } ||      }| j#                  |j                                |j$                  }| j'                  |d   |       y # 1 sw Y   xY w)Nr   )"AccountTransactionCreateSerializer)TrustAccount)ValidationErrorrD   z1000.00r,   r9   r:   rF   )r#   r?   r@   rA   rB   r$   )dataT)raise_exceptionzMurugan Custodian Accountr   Active)account_namer   associated_entity_typer$   statusr   trust_account)accounting.serializersrh   accounting.modelsri   rest_framework.exceptionsrj   r#   idr   r2   r3   r$   assertRaisesis_validr   r"   r!   
assertTruevalidated_datar4   )	r%   rh   ri   rj   rk   
serializer	trust_accserializer2ry   s	            r&   8test_member_cash_credit_requires_custodian_trust_accountzVFinancialRollupEngineTestCase.test_member_cash_credit_requires_custodian_trust_account   s   M2= !--00 (i( (dAr :"kknn
 8TB
/ 	65	6 !((//4#+;;yy 0 
	 9dC,,./$338)D#	6 	6s   <DDc           
         ddl m} ddlm} dd l}dd l}t        j                  j                  | j                  dt        d      t        j                  ddd      d	| j                  | j                  
      }| j                  t!        |d      xr |j"                  d u        ||      }| j                  |j%                  d             |j'                  dddd      5 }|j)                  d       |j*                  }d d d        	  |      5   ||      }	| j                  |	j%                  d             d d d         |d      5   ||      }
| j                  |
j%                  d             d d d        |j,                  j/                  |      r|j1                  |       y y # 1 sw Y   xY w# 1 sw Y   }xY w# 1 sw Y   OxY w# |j,                  j/                        r|j1                  |       w w xY w)Nr   )generate_receipt_pdf)override_settingsrD   rG   r,   r9   r:   r=   r>   receipts   %PDFz.htmlFwzutf-8)suffixre   modeencodinga?  
            <html>
            <body>
                <h1>Custom Receipt</h1>
                <p>Number: {{ receipt_no }}</p>
                <p>Name: {{ name }}</p>
                <p>Amount: {{ amount }}</p>
                <img src="{{ custodian_signature }}" />
            </body>
            </html>
            )ACTIVE_RECEIPT_TEMPLATEz/invalid/path/error.html)accounting.receipt_generatorr   django.testr   tempfileosr   r   r"   r#   r   r2   r3   r$   r!   rx   hasattrr   
startswithNamedTemporaryFilewriter   pathexistsremove)r%   r   r   r   r   tx	pdf_bytestf	temp_pathpdf_bytes_custompdf_bytes_fallbacks              r&   -test_receipt_pdf_generation_html_and_fallbackzKFinancialRollupEngineTestCase.test_receipt_pdf_generation_html_and_fallback  s   E1  ''..**%9%%]]4B7!;;yy / 
 	I.I2::T3IJ ),		,,W56 ((CZa(b 	 fhHH 
 
 I	 	%"9E F#7#;  0 ; ;G DEF
 #;UV H%9"%=" 2 = =g FGH
 ww~~i(		)$ )3	  	 F F
H H
 ww~~i(		)$ )sH   F(	G )F48G 	)G 2G (F14F=9G  G	G /G;c                    ddl m} ddlm} ddlm} dd l}d| j                  _        | j                  j                           |       }|j                  | j                          |d      }|j                  |      }| j                  |j                  d       | j                  d	|j                         | j                  d
|j                         | j                  d|j                         |j!                  |d	di      }| j                  |j                  d       |j!                  |dddd      }	| j                  |	j                  d       |j!                  |d	di      }
| j                  |
j                  d       |j                  |      }| j                  |j                  d	   d       | j                  |j                  d   d       |j"                  j%                  |j&                  dd      }|j"                  j)                  |      r|j+                  |       |j"                  j%                  |j&                  dd      }|j"                  j)                  |      r|j+                  |       y y )Nr   )	APIClient)reverse)settingsT)r!   zsystem-settings   active_receipt_template	templatestemplate_contentznonexistent.htmli  save_template_contentztest_temp.htmlz<html><body>Test</body></html>)actiontemplate_namecontent
accountingzsystem_settings.json)rest_framework.testr   django.urlsr   django.confr   r   r!   is_staffrO   force_authenticategetr4   status_codeassertInrk   postr   joinBASE_DIRr   r   )r%   r   r   r   r   clienturlresponseresponse_badresponse_saveresponse_okresponse_aftertemp_file_pathsettings_file_paths                 r&   test_system_settings_endpointz;FinancialRollupEngineTestCase.test_system_settings_endpointC  s	   1'( "				!!tyy!1 '(::c?--s3/?k8==1((--8 {{3)BDV(WX1137 C--7*
 
 	22C8 kk#(ACS'TU00#6  C,,-FGIYZ,,-?@Bbc h&7&7GWX77>>.)IIn%WW\\(*;*;\Kab77>>,-II() .r(   N)__name__
__module____qualname__r'   r7   rM   rP   rZ   ra   rf   r}   r   r    r(   r&   r   r   
   s@    
.:."EHE41BfEBE@!EF3%j0*r(   r   )r2   decimalr   r   r   django.contrib.auth.modelsr   django.utilsr   members.modelsr   rs   r   r	   members.utilsr
   r   r   r(   r&   <module>r      s+        + ! ! = 0i*H i*r(   