@ -113,7 +113,8 @@ class AccountAgedTrialBalanceWebkit(PartnersOpenInvoicesWebkit):
return RANGES_TITLES
return RANGES_TITLES
def set_context ( self , objects , data , ids , report_type = None ) :
def set_context ( self , objects , data , ids , report_type = None ) :
""" Populate aged_lines, aged_balance, aged_percents attributes
""" Populate aged_lines, aged_lines_by_invoice, aged_balance,
aged_percents attributes
on each account browse record that will be used by mako template
on each account browse record that will be used by mako template
The browse record are store in : attr : `objects`
The browse record are store in : attr : `objects`
@ -134,17 +135,23 @@ class AccountAgedTrialBalanceWebkit(PartnersOpenInvoicesWebkit):
ids ,
ids ,
report_type = report_type
report_type = report_type
)
)
self . localcontext . update ( {
' aging_method ' : data [ ' form ' ] [ ' aging_method ' ]
} )
for acc in self . objects :
for acc in self . objects :
acc . aged_lines = { }
acc . aged_lines = { }
acc . aged_lines_by_invoice = { }
acc . agged_totals = { }
acc . agged_totals = { }
acc . agged_percents = { }
acc . agged_percents = { }
for part_id , partner_lines in acc . ledger_lines . items ( ) :
for part_id , partner_lines in acc . ledger_lines . items ( ) :
aged_lines = self . compute_aged_lines ( part_id ,
partner_aged_lines , invoice_aged_lines = \
self . compute_aged_lines ( part_id ,
partner_lines ,
partner_lines ,
data )
data )
if aged_lines :
acc . aged_lines [ part_id ] = aged_lines
if partner_aged_lines :
acc . aged_lines [ part_id ] = partner_aged_lines
if data [ ' form ' ] [ ' detailed_by_invoice ' ] :
acc . aged_lines_by_invoice [ part_id ] = invoice_aged_lines
acc . aged_totals = totals = self . compute_totals (
acc . aged_totals = totals = self . compute_totals (
acc . aged_lines . values ( ) )
acc . aged_lines . values ( ) )
acc . aged_percents = self . compute_percents ( totals )
acc . aged_percents = self . compute_percents ( totals )
@ -161,26 +168,58 @@ class AccountAgedTrialBalanceWebkit(PartnersOpenInvoicesWebkit):
: param ledger_lines : generated by parent
: param ledger_lines : generated by parent
: class : `.open_invoices.PartnersOpenInvoicesWebkit`
: class : `.open_invoices.PartnersOpenInvoicesWebkit`
: returns : dict of computed aged lines
: returns :
- dict of computed aged lines
eg { ' balance ' : 1000.0 ,
eg { ' balance ' : 1000.0 ,
' aged_lines ' : { ( 90 , 120 ) : 0.0 , . . . }
' aged_lines ' : { ( 90 , 120 ) : 0.0 , . . . }
}
- dict of computed aged lines by invoice
eg { ' SAJ/2015/003 ' : { ' balance: 700.0
' aged_lines ' : { ( 90 , 120 ) : 0.0 , . . . } ,
' SAJ/2015/004 ' : { ' balance: 300.0
' aged_lines ' : { ( 90 , 120 ) : 300.0 , . . . } ,
}
"""
"""
detailed_by_invoice = data [ ' form ' ] [ ' detailed_by_invoice ' ]
aging_method = data [ ' form ' ] [ ' aging_method ' ]
lines_to_age = self . filter_lines ( partner_id , ledger_lines )
lines_to_age = self . filter_lines ( partner_id , ledger_lines )
res = { }
res_by_partner = { }
res_by_invoice = { }
end_date = self . _get_end_date ( data )
end_date = self . _get_end_date ( data )
aged_lines = dict . fromkeys ( RANGES , 0.0 )
partner_ aged_lines = dict . fromkeys ( RANGES , 0.0 )
reconcile_lookup = self . get_reconcile_count_lookup ( lines_to_age )
reconcile_lookup = self . get_reconcile_count_lookup ( lines_to_age )
res [ ' aged_lines ' ] = aged_lines
res_by_partner [ ' aged_lines ' ] = partner_aged_lines
for line in lines_to_age :
for line in lines_to_age :
compute_method = self . get_compute_method ( reconcile_lookup ,
compute_method = self . get_compute_method ( reconcile_lookup ,
partner_id ,
partner_id ,
line )
line ,
aging_method )
delay = compute_method ( line , end_date , ledger_lines )
delay = compute_method ( line , end_date , ledger_lines )
classification = self . classify_line ( partner_id , delay )
classification = self . classify_line ( partner_id , delay )
aged_lines [ classification ] + = line [ ' debit ' ] - line [ ' credit ' ]
self . compute_balance ( res , aged_lines )
return res
amount = line [ ' debit ' ] - line [ ' credit ' ]
partner_aged_lines [ classification ] + = amount
# Populate the aged_lines_by_invoice dictionary if the option has
# been chosen in the wizard
if detailed_by_invoice :
invoice = line [ ' invoice_number ' ]
if invoice not in res_by_invoice :
res_by_invoice [ invoice ] = {
' aged_lines ' : dict . fromkeys ( RANGES , 0.0 ) ,
}
res_by_invoice [ invoice ] [
' aged_lines ' ] [ classification ] + = amount
if detailed_by_invoice :
for invoice in res_by_invoice :
self . compute_balance (
res_by_invoice [ invoice ] ,
res_by_invoice [ invoice ] [ ' aged_lines ' ]
)
self . compute_balance ( res_by_partner , partner_aged_lines )
return res_by_partner , res_by_invoice
def _get_end_date ( self , data ) :
def _get_end_date ( self , data ) :
""" Retrieve end date to be used to compute delay.
""" Retrieve end date to be used to compute delay.
@ -286,7 +325,8 @@ class AccountAgedTrialBalanceWebkit(PartnersOpenInvoicesWebkit):
reference_line ,
reference_line ,
end_date )
end_date )
def get_compute_method ( self , reconcile_lookup , partner_id , line ) :
def get_compute_method ( self , reconcile_lookup , partner_id , line ,
aging_method ) :
""" Get the function that should compute the delay for a given line
""" Get the function that should compute the delay for a given line
: param reconcile_lookup : dict of reconcile group by id and count
: param reconcile_lookup : dict of reconcile group by id and count
@ -300,7 +340,8 @@ class AccountAgedTrialBalanceWebkit(PartnersOpenInvoicesWebkit):
"""
"""
if reconcile_lookup . get ( line [ ' rec_id ' ] , 0.0 ) > 1 :
if reconcile_lookup . get ( line [ ' rec_id ' ] , 0.0 ) > 1 :
return self . compute_delay_from_partial_rec
return self . compute_delay_from_partial_rec
elif line [ ' jtype ' ] in INV_TYPE and line . get ( ' date_maturity ' ) :
elif line [ ' jtype ' ] in INV_TYPE and line . get ( ' date_maturity ' ) \
and aging_method == ' due_date ' :
return self . compute_delay_from_maturity
return self . compute_delay_from_maturity
else :
else :
return self . compute_delay_from_date
return self . compute_delay_from_date