
    nj                     :    d dl mZ d dlmZ d dlmZ d dlmZ d Zy)    )Decimal)transaction)Sum)getCurrentTaxYearRangec                 `   | r|syddl m} ddlm} t	        |      \  }}t        j                         5  |j                  j                         j                  | j                        }|j                  j                  |d||fd	      j                  t        d
            d   xs t        d      }|j                  j                  |d||fd	      j                  t        d
            d   xs t        d      }||_        ||_        |j#                          ddd       y# 1 sw Y   yxY w)z
    Recalculates a member's annual_tax (debit rollup) and amount_paid (credit rollup)
    for the tax year corresponding to the provided date.
    Runs inside a database transaction block with select_for_update for structural integrity.
    Nr   )Member   )AccountTransaction)pkDEBITF)membertransaction_typetransaction_date__range
is_deletedamount)totalr   z0.00CREDIT)members.modelsr   modelsr
   r   r   atomicobjectsselect_for_updategetr   filter	aggregater   r   
annual_taxamount_paidsave)	r   dater   r
   
start_dateend_datemember_to_update
debits_sumcredits_sums	            :/var/www/kalinger_portal/trust-backend/accounting/utils.pyrecalculate_member_financialsr&      s;     &*1$7J				  !>>;;=AAVYYAO (//66#$%/$:	 7 

 )#h-)
(2 E
 6=V_ 	 )0077#%%/$:	 8 

 )#h-)
(2 E
 6=V_ 	 '1#'2$/     s   C'D$$D-N)	decimalr   	django.dbr   django.db.modelsr   members.utilsr   r&        r%   <module>r-      s     !   0& r,   