2009-10-13 05:58:37 +00:00
# -*- coding: utf-8 -*-
2006-12-07 13:41:40 +00:00
##############################################################################
2009-11-30 10:24:22 +00:00
#
2008-11-04 12:48:01 +00:00
# OpenERP, Open Source Management Solution
2010-01-12 09:18:39 +00:00
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
2006-12-07 13:41:40 +00:00
#
2008-11-03 19:18:56 +00:00
# This program is free software: you can redistribute it and/or modify
2009-10-14 11:15:34 +00:00
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
2006-12-07 13:41:40 +00:00
#
2008-11-03 19:18:56 +00:00
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2009-10-14 11:15:34 +00:00
# GNU Affero General Public License for more details.
2006-12-07 13:41:40 +00:00
#
2009-10-14 11:15:34 +00:00
# You should have received a copy of the GNU Affero General Public License
2009-11-30 10:24:22 +00:00
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2006-12-07 13:41:40 +00:00
#
##############################################################################
import time
2008-10-06 09:46:37 +00:00
import re
import datetime
2010-07-27 11:01:43 +00:00
from datetime import timedelta
2010-07-28 06:10:50 +00:00
import copy
2010-07-13 07:35:45 +00:00
import pooler
2006-12-07 13:41:40 +00:00
from report import report_sxw
2010-07-14 12:54:18 +00:00
from common_report_header import common_report_header
2006-12-07 13:41:40 +00:00
2010-07-14 12:54:18 +00:00
class partner_balance ( report_sxw . rml_parse , common_report_header ) :
2010-07-27 11:01:43 +00:00
2010-07-14 04:37:02 +00:00
def __init__ ( self , cr , uid , name , context = None ) :
if context is None :
context = { }
2009-10-09 11:49:00 +00:00
super ( partner_balance , self ) . __init__ ( cr , uid , name , context = context )
2008-10-06 09:46:37 +00:00
self . date_lst = [ ]
2010-07-14 04:37:02 +00:00
self . account_ids = [ ]
2008-07-22 15:11:28 +00:00
self . localcontext . update ( {
' time ' : time ,
' lines ' : self . lines ,
' sum_debit ' : self . _sum_debit ,
' sum_credit ' : self . _sum_credit ,
' sum_litige ' : self . _sum_litige ,
' sum_sdebit ' : self . _sum_sdebit ,
' sum_scredit ' : self . _sum_scredit ,
' solde_debit ' : self . _solde_balance_debit ,
' solde_credit ' : self . _solde_balance_credit ,
' get_currency ' : self . _get_currency ,
2008-10-06 09:46:37 +00:00
' comma_me ' : self . comma_me ,
2010-07-13 07:35:45 +00:00
' get_fiscalyear ' : self . _get_fiscalyear ,
2010-06-29 13:48:46 +00:00
' get_periods ' : self . get_periods ,
2010-07-19 05:44:42 +00:00
' get_journal ' : self . _get_journal ,
2010-07-27 11:01:43 +00:00
' get_filter ' : self . _get_filter ,
2010-07-19 05:44:42 +00:00
' get_account ' : self . _get_account ,
2010-07-19 10:50:07 +00:00
' get_start_date ' : self . _get_start_date ,
' get_end_date ' : self . _get_end_date ,
2010-07-22 05:36:54 +00:00
' get_start_period ' : self . get_start_period ,
2010-07-27 11:01:43 +00:00
' get_end_period ' : self . get_end_period ,
2010-07-22 06:00:46 +00:00
' get_partners ' : self . _get_partners ,
2008-07-22 15:11:28 +00:00
} )
2008-10-06 09:46:37 +00:00
## Compute account list one time
#
# Date Management
#
2010-07-13 07:35:45 +00:00
2010-06-29 13:48:46 +00:00
def get_periods ( self , form ) :
2010-07-14 04:37:02 +00:00
result = ' '
2010-06-29 13:48:46 +00:00
if form . has_key ( ' periods ' ) and form [ ' periods ' ] :
period_ids = form [ ' periods ' ]
per_ids = self . pool . get ( ' account.period ' ) . browse ( self . cr , self . uid , form [ ' periods ' ] )
for r in per_ids :
if r == per_ids [ len ( per_ids ) - 1 ] :
result + = r . name + " . "
else :
result + = r . name + " , "
else :
fy_obj = self . pool . get ( ' account.fiscalyear ' ) . browse ( self . cr , self . uid , form [ ' fiscalyear ' ] )
res = fy_obj . period_ids
len_res = len ( res )
for r in res :
if r == res [ len_res - 1 ] :
2010-07-14 04:37:02 +00:00
result + = r . name + " . "
2010-06-29 13:48:46 +00:00
else :
2010-07-14 04:37:02 +00:00
result + = r . name + " , "
2010-06-29 13:48:46 +00:00
return str ( result and result [ : - 1 ] ) or ' ALL '
2010-07-13 07:35:45 +00:00
2010-06-16 11:51:39 +00:00
def date_range ( self , start , end ) :
2009-01-13 05:47:41 +00:00
if not start or not end :
return [ ]
2008-10-06 09:46:37 +00:00
start = datetime . date . fromtimestamp ( time . mktime ( time . strptime ( start , " % Y- % m- %d " ) ) )
end = datetime . date . fromtimestamp ( time . mktime ( time . strptime ( end , " % Y- % m- %d " ) ) )
full_str_date = [ ]
#
r = ( end + datetime . timedelta ( days = 1 ) - start ) . days
#
date_array = [ start + datetime . timedelta ( days = i ) for i in range ( r ) ]
for date in date_array :
full_str_date . append ( str ( date ) )
return full_str_date
2008-11-04 12:48:01 +00:00
2010-06-16 11:51:39 +00:00
def transform_period_into_date_array ( self , data ) :
2008-10-06 09:46:37 +00:00
## Get All Period Date
#
# If we have no period we will take all perdio in the FiscalYear.
2010-04-21 11:41:18 +00:00
if not data [ ' form ' ] [ ' periods ' ] :
2008-10-06 09:46:37 +00:00
periods_id = self . pool . get ( ' account.period ' ) . search ( self . cr , self . uid , [ ( ' fiscalyear_id ' , ' = ' , data [ ' form ' ] [ ' fiscalyear ' ] ) ] )
else :
2010-04-21 11:41:18 +00:00
periods_id = data [ ' form ' ] [ ' periods ' ]
2008-11-04 12:48:01 +00:00
date_array = [ ]
2008-10-06 09:46:37 +00:00
for period_id in periods_id :
period_obj = self . pool . get ( ' account.period ' ) . browse ( self . cr , self . uid , period_id )
2010-06-16 11:51:39 +00:00
date_array = date_array + self . date_range ( period_obj . date_start , period_obj . date_stop )
2008-10-06 09:46:37 +00:00
self . date_lst = date_array
self . date_lst . sort ( )
2008-11-04 12:48:01 +00:00
2010-06-16 11:51:39 +00:00
def transform_date_into_date_array ( self , data ) :
2010-07-13 07:35:45 +00:00
return_array = self . date_range ( data [ ' form ' ] [ ' date_from ' ] , data [ ' form ' ] [ ' date_to ' ] )
2008-10-06 09:46:37 +00:00
self . date_lst = return_array
self . date_lst . sort ( )
2008-11-04 12:48:01 +00:00
2010-06-16 11:51:39 +00:00
def transform_none_into_date_array ( self , data ) :
2008-10-17 13:04:39 +00:00
sql = " SELECT min(date) as start_date from account_move_line "
self . cr . execute ( sql )
start_date = self . cr . fetchone ( ) [ 0 ]
2008-11-04 12:48:01 +00:00
2008-10-17 13:04:39 +00:00
sql = " SELECT max(date) as start_date from account_move_line "
self . cr . execute ( sql )
stop_date = self . cr . fetchone ( ) [ 0 ]
2008-11-04 12:48:01 +00:00
2008-10-17 13:04:39 +00:00
array = [ ]
2010-06-16 11:51:39 +00:00
array = array + self . date_range ( start_date , stop_date )
2008-10-17 13:04:39 +00:00
self . date_lst = array
self . date_lst . sort ( )
2008-11-04 12:48:01 +00:00
2010-06-16 11:51:39 +00:00
def comma_me ( self , amount ) :
2008-10-06 09:46:37 +00:00
if type ( amount ) is float :
amount = str ( ' %.2f ' % amount )
else :
amount = str ( amount )
if ( amount == ' 0 ' ) :
return ' '
orig = amount
new = re . sub ( " ^(-? \ d+)( \ d {3} ) " , " \ g<1> ' \ g<2> " , amount )
if orig == new :
return new
else :
return self . comma_me ( new )
2008-11-04 12:48:01 +00:00
2010-07-14 04:37:02 +00:00
def set_context ( self , objects , data , ids , report_type = None ) :
2008-10-06 09:46:37 +00:00
# Transformation des date
#
#
2010-07-13 07:35:45 +00:00
if data [ ' form ' ] [ ' filter ' ] == ' filter_no ' :
2008-10-17 13:04:39 +00:00
self . transform_none_into_date_array ( data )
2010-07-13 07:35:45 +00:00
elif data [ ' form ' ] [ ' filter ' ] == ' filter_date ' :
2008-10-06 09:46:37 +00:00
self . transform_date_into_date_array ( data )
2010-07-13 07:35:45 +00:00
elif data [ ' form ' ] [ ' filter ' ] == ' filter_period ' :
2008-10-17 13:04:39 +00:00
self . transform_period_into_date_array ( data )
2008-11-04 12:48:01 +00:00
2008-10-06 09:46:37 +00:00
## Compute Code
#
if ( data [ ' form ' ] [ ' result_selection ' ] == ' customer ' ) :
2010-06-10 13:34:19 +00:00
self . ACCOUNT_TYPE = ( ' receivable ' , )
2008-10-06 09:46:37 +00:00
elif ( data [ ' form ' ] [ ' result_selection ' ] == ' supplier ' ) :
2010-06-10 13:34:19 +00:00
self . ACCOUNT_TYPE = ( ' payable ' , )
2008-10-06 09:46:37 +00:00
else :
2010-06-10 13:34:19 +00:00
self . ACCOUNT_TYPE = ( ' payable ' , ' receivable ' )
2008-10-06 09:46:37 +00:00
#
2008-11-03 12:50:38 +00:00
self . cr . execute ( " SELECT a.id " \
" FROM account_account a " \
" LEFT JOIN account_account_type t " \
" ON (a.type = t.code) " \
2010-07-13 07:35:45 +00:00
# "WHERE a.company_id = %s " \
" WHERE a.type IN %s " \
" AND a.active " , ( self . ACCOUNT_TYPE , ) )
2009-11-30 10:24:22 +00:00
self . account_ids = [ a for ( a , ) in self . cr . fetchall ( ) ]
2010-07-28 11:04:34 +00:00
self . initial_balance = data [ ' form ' ] [ ' initial_balance ' ] # for include initial balance
2010-07-13 07:35:45 +00:00
return super ( partner_balance , self ) . set_context ( objects , data , ids , report_type )
2008-10-06 09:46:37 +00:00
2010-07-27 11:01:43 +00:00
def lines ( self , data ) :
2008-10-06 09:46:37 +00:00
full_account = [ ]
result_tmp = 0.0
2010-06-10 13:34:19 +00:00
if self . date_lst :
2009-01-13 05:47:41 +00:00
self . cr . execute (
" SELECT p.ref,l.account_id,ac.name as account_name,ac.code as code ,p.name, sum(debit) as debit, sum(credit) as credit, " \
" CASE WHEN sum(debit) > sum(credit) " \
" THEN sum(debit) - sum(credit) " \
" ELSE 0 " \
" END AS sdebit, " \
" CASE WHEN sum(debit) < sum(credit) " \
" THEN sum(credit) - sum(debit) " \
" ELSE 0 " \
" END AS scredit, " \
" (SELECT sum(debit-credit) " \
" FROM account_move_line l " \
" WHERE partner_id = p.id " \
2010-06-10 13:34:19 +00:00
" AND l.date IN %s " \
2009-01-13 05:47:41 +00:00
" AND blocked = TRUE " \
" ) AS enlitige " \
" FROM account_move_line l LEFT JOIN res_partner p ON (l.partner_id=p.id) " \
" JOIN account_account ac ON (l.account_id = ac.id) " \
2010-06-10 13:34:19 +00:00
" WHERE ac.type IN %s " \
" AND l.date IN %s " \
2010-07-13 07:35:45 +00:00
# "AND ac.company_id = %s " \
2009-01-13 05:47:41 +00:00
" GROUP BY p.id, p.ref, p.name,l.account_id,ac.name,ac.code " \
2010-06-10 13:34:19 +00:00
" ORDER BY l.account_id,p.name " ,
2010-07-13 07:35:45 +00:00
( tuple ( self . date_lst ) , self . ACCOUNT_TYPE , tuple ( self . date_lst ) ) )
2009-01-13 05:47:41 +00:00
res = self . cr . dictfetchall ( )
2010-07-27 11:01:43 +00:00
#For include intial balance..
2010-07-28 11:04:34 +00:00
if self . initial_balance :
2010-07-27 11:01:43 +00:00
date_init = ( datetime . datetime . strptime ( self . date_lst [ 0 ] , " % Y- % m- %d " ) + timedelta ( days = - 1 ) ) . strftime ( ' % Y- % m- %d ' )
self . cr . execute (
2010-07-28 06:10:50 +00:00
" SELECT ' 1 ' as type, ' ' as ref, l.account_id as account_id, ' ' as account_name, ' ' as code, ' ' as name, sum(debit) as debit, sum(credit) as credit, " \
2010-07-27 11:01:43 +00:00
" CASE WHEN sum(debit) > sum(credit) " \
" THEN sum(debit) - sum(credit) " \
" ELSE 0 " \
" END AS sdebit, " \
" CASE WHEN sum(debit) < sum(credit) " \
" THEN sum(credit) - sum(debit) " \
" ELSE 0 " \
" END AS scredit, " \
" (SELECT sum(debit-credit) " \
" FROM account_move_line l " \
" WHERE partner_id = p.id " \
" AND l.date < %s " \
" AND blocked = TRUE " \
" ) AS enlitige " \
" FROM account_move_line l LEFT JOIN res_partner p ON (l.partner_id=p.id) " \
" JOIN account_account ac ON (l.account_id = ac.id) " \
" WHERE ac.type IN %s " \
" AND l.date < %s " \
" GROUP BY p.id, p.ref, p.name,l.account_id,ac.name,ac.code " \
" ORDER BY l.account_id,p.name " ,
( date_init , self . ACCOUNT_TYPE , date_init ) )
res1 = self . cr . dictfetchall ( )
2010-07-28 06:10:50 +00:00
final_init = { }
2010-07-27 11:01:43 +00:00
res_init = { }
debit = credit = 0
for r in res1 :
2010-07-28 06:10:50 +00:00
if final_init . get ( r [ ' account_id ' ] , False ) :
res_init = final_init [ r [ ' account_id ' ] ]
debit + = final_init [ r [ ' account_id ' ] ] [ ' debit ' ]
credit + = final_init [ r [ ' account_id ' ] ] [ ' credit ' ]
res_init [ ' credit ' ] = credit
res_init [ ' debit ' ] = debit
res_init [ ' type ' ] = 3
res_init [ ' ref ' ] = ' '
res_init [ ' code ' ] = ' '
res_init [ ' name ' ] = ' Initial Balance '
res_init [ ' balance ' ] = debit - credit
res_init [ ' enlitige ' ] = 0.0 # fix me
res_init [ ' account_id ' ] = final_init [ r [ ' account_id ' ] ] [ ' account_id ' ]
else :
res_init = { }
debit = r [ ' debit ' ]
credit = r [ ' credit ' ]
res_init [ ' credit ' ] = credit
res_init [ ' debit ' ] = debit
res_init [ ' type ' ] = 3
res_init [ ' ref ' ] = ' '
res_init [ ' code ' ] = ' '
res_init [ ' name ' ] = ' Initial Balance '
res_init [ ' balance ' ] = debit - credit
res_init [ ' enlitige ' ] = 0.0 # fix me
res_init [ ' account_id ' ] = r [ ' account_id ' ]
final_init [ r [ ' account_id ' ] ] = res_init
2009-01-13 05:47:41 +00:00
for r in res :
full_account . append ( r )
2010-07-28 06:10:50 +00:00
2008-10-06 09:46:37 +00:00
## We will now compute Total
2010-07-27 11:01:43 +00:00
subtotal_row = self . _add_subtotal ( full_account )
2010-07-28 11:04:34 +00:00
if not self . initial_balance :
2010-07-28 06:10:50 +00:00
return subtotal_row
#If include initial balance is selected..
subtotal = copy . deepcopy ( subtotal_row )
init_acnt = [ ]
for row in subtotal_row :
if final_init and row . get ( ' account_id ' , False ) and not row [ ' account_id ' ] in init_acnt :
subtotal . insert ( subtotal . index ( row ) , final_init [ row [ ' account_id ' ] ] )
init_acnt . append ( row [ ' account_id ' ] )
return subtotal
2008-01-11 14:46:53 +00:00
2010-06-16 11:51:39 +00:00
def _add_subtotal ( self , cleanarray ) :
2010-07-27 11:01:43 +00:00
i = 0
2008-10-06 09:46:37 +00:00
completearray = [ ]
tot_debit = 0.0
tot_credit = 0.0
tot_scredit = 0.0
tot_sdebit = 0.0
tot_enlitige = 0.0
for r in cleanarray :
# For the first element we always add the line
# type = 1 is the line is the first of the account
# type = 2 is an other line of the account
if i == 0 :
# We add the first as the header
#
##
new_header = { }
new_header [ ' ref ' ] = ' '
new_header [ ' name ' ] = r [ ' account_name ' ]
new_header [ ' code ' ] = r [ ' code ' ]
2010-07-28 10:08:49 +00:00
new_header [ ' debit ' ] = r [ ' credit ' ] #tot_credit
new_header [ ' credit ' ] = r [ ' debit ' ] #tot_debit
2008-10-15 13:15:46 +00:00
new_header [ ' scredit ' ] = tot_scredit
new_header [ ' sdebit ' ] = tot_sdebit
new_header [ ' enlitige ' ] = tot_enlitige
new_header [ ' balance ' ] = float ( tot_sdebit ) - float ( tot_scredit )
2008-10-06 09:46:37 +00:00
new_header [ ' type ' ] = 3
##
completearray . append ( new_header )
#
r [ ' type ' ] = 1
r [ ' balance ' ] = float ( r [ ' sdebit ' ] ) - float ( r [ ' scredit ' ] )
2008-11-04 12:48:01 +00:00
2008-10-06 09:46:37 +00:00
completearray . append ( r )
#
tot_debit = r [ ' debit ' ]
tot_credit = r [ ' credit ' ]
tot_scredit = r [ ' scredit ' ]
tot_sdebit = r [ ' sdebit ' ]
tot_enlitige = ( r [ ' enlitige ' ] or 0.0 )
#
else :
if cleanarray [ i ] [ ' account_id ' ] < > cleanarray [ i - 1 ] [ ' account_id ' ] :
2008-11-04 12:48:01 +00:00
2008-10-15 13:15:46 +00:00
new_header [ ' debit ' ] = tot_debit
new_header [ ' credit ' ] = tot_credit
new_header [ ' scredit ' ] = tot_scredit
new_header [ ' sdebit ' ] = tot_sdebit
new_header [ ' enlitige ' ] = tot_enlitige
new_header [ ' balance ' ] = float ( tot_sdebit ) - float ( tot_scredit )
new_header [ ' type ' ] = 3
2008-11-04 12:48:01 +00:00
# we reset the counter
2008-10-06 09:46:37 +00:00
tot_debit = r [ ' debit ' ]
tot_credit = r [ ' credit ' ]
tot_scredit = r [ ' scredit ' ]
tot_sdebit = r [ ' sdebit ' ]
tot_enlitige = ( r [ ' enlitige ' ] or 0.0 )
#
##
new_header = { }
new_header [ ' ref ' ] = ' '
new_header [ ' name ' ] = r [ ' account_name ' ]
new_header [ ' code ' ] = r [ ' code ' ]
2008-10-15 13:15:46 +00:00
new_header [ ' debit ' ] = tot_debit
new_header [ ' credit ' ] = tot_credit
new_header [ ' scredit ' ] = tot_scredit
new_header [ ' sdebit ' ] = tot_sdebit
new_header [ ' enlitige ' ] = tot_enlitige
new_header [ ' balance ' ] = float ( tot_sdebit ) - float ( tot_scredit )
2008-10-06 09:46:37 +00:00
new_header [ ' type ' ] = 3
2010-06-29 13:48:46 +00:00
##get_fiscalyear
2008-10-06 09:46:37 +00:00
##
2008-11-06 11:22:44 +00:00
2008-10-06 09:46:37 +00:00
completearray . append ( new_header )
2008-11-04 12:48:01 +00:00
##
2008-10-06 09:46:37 +00:00
#
r [ ' type ' ] = 1
#
r [ ' balance ' ] = float ( r [ ' sdebit ' ] ) - float ( r [ ' scredit ' ] )
2008-11-04 12:48:01 +00:00
2008-10-06 09:46:37 +00:00
completearray . append ( r )
2008-11-04 12:48:01 +00:00
2008-10-06 09:46:37 +00:00
if cleanarray [ i ] [ ' account_id ' ] == cleanarray [ i - 1 ] [ ' account_id ' ] :
2008-11-04 12:48:01 +00:00
# we reset the counter
new_header [ ' debit ' ] = tot_debit
new_header [ ' credit ' ] = tot_credit
new_header [ ' scredit ' ] = tot_scredit
new_header [ ' sdebit ' ] = tot_sdebit
new_header [ ' enlitige ' ] = tot_enlitige
new_header [ ' balance ' ] = float ( tot_sdebit ) - float ( tot_scredit )
new_header [ ' type ' ] = 3
2008-10-06 09:46:37 +00:00
tot_debit = tot_debit + r [ ' debit ' ]
tot_credit = tot_credit + r [ ' credit ' ]
tot_scredit = tot_scredit + r [ ' scredit ' ]
tot_sdebit = tot_sdebit + r [ ' sdebit ' ]
tot_enlitige = tot_enlitige + ( r [ ' enlitige ' ] or 0.0 )
2008-11-04 12:48:01 +00:00
new_header [ ' debit ' ] = tot_debit
new_header [ ' credit ' ] = tot_credit
new_header [ ' scredit ' ] = tot_scredit
new_header [ ' sdebit ' ] = tot_sdebit
new_header [ ' enlitige ' ] = tot_enlitige
new_header [ ' balance ' ] = float ( tot_sdebit ) - float ( tot_scredit )
2008-10-06 09:46:37 +00:00
#
r [ ' type ' ] = 2
#
r [ ' balance ' ] = float ( r [ ' sdebit ' ] ) - float ( r [ ' scredit ' ] )
#
2008-11-06 11:22:44 +00:00
2008-10-06 09:46:37 +00:00
completearray . append ( r )
2008-11-04 12:48:01 +00:00
2008-10-06 09:46:37 +00:00
i = i + 1
return completearray
2010-06-16 11:51:39 +00:00
def _sum_debit ( self , data ) :
2008-07-22 15:11:28 +00:00
if not self . ids :
return 0.0
account_move_line_obj = pooler . get_pool ( self . cr . dbname ) . get ( ' account.move.line ' )
2008-10-06 09:46:37 +00:00
result_tmp = 0.0
2009-01-13 05:47:41 +00:00
temp_res = 0.0
2010-06-10 13:34:19 +00:00
if self . date_lst :
2009-01-13 05:47:41 +00:00
self . cr . execute (
" SELECT sum(debit) " \
" FROM account_move_line AS l " \
2010-06-10 13:34:19 +00:00
" WHERE l.account_id IN %s " \
" AND l.date IN %s " ,
( tuple ( self . account_ids ) , tuple ( self . date_lst ) ) )
2009-01-13 05:47:41 +00:00
temp_res = float ( self . cr . fetchone ( ) [ 0 ] or 0.0 )
2010-07-28 11:04:34 +00:00
# if self.initial_balance:
2010-07-28 06:10:50 +00:00
# date_init = (datetime.datetime.strptime(self.date_lst[0], "%Y-%m-%d") + timedelta(days=-1)).strftime('%Y-%m-%d')
# self.cr.execute(
# "SELECT sum(debit) " \
# "FROM account_move_line AS l " \
# "WHERE l.account_id IN %s" \
# "AND l.date < %s",
# (tuple(self.account_ids), date_init,))
# temp_res += float(self.cr.fetchone()[0] or 0.0)
2009-01-13 05:47:41 +00:00
result_tmp = result_tmp + temp_res
2008-10-06 09:46:37 +00:00
return result_tmp
2008-01-11 14:46:53 +00:00
2010-06-16 11:51:39 +00:00
def _sum_credit ( self , data ) :
2008-07-22 15:11:28 +00:00
if not self . ids :
return 0.0
2008-10-06 09:46:37 +00:00
result_tmp = 0.0
2009-01-13 05:47:41 +00:00
temp_res = 0.0
2010-06-10 13:34:19 +00:00
if self . date_lst :
2009-01-13 05:47:41 +00:00
self . cr . execute (
" SELECT sum(credit) " \
" FROM account_move_line AS l " \
2010-06-10 13:34:19 +00:00
" WHERE l.account_id IN %s " \
" AND l.date IN %s " ,
( tuple ( self . account_ids ) , tuple ( self . date_lst ) , ) )
2009-01-13 05:47:41 +00:00
temp_res = float ( self . cr . fetchone ( ) [ 0 ] or 0.0 )
2010-07-28 11:04:34 +00:00
# if self.initial_balance:
2010-07-28 06:10:50 +00:00
# date_init = (datetime.datetime.strptime(self.date_lst[0], "%Y-%m-%d") + timedelta(days=-1)).strftime('%Y-%m-%d')
# self.cr.execute(
# "SELECT sum(credit) " \
# "FROM account_move_line AS l " \
# "WHERE l.account_id IN %s" \
# "AND l.date < %s",
# (tuple(self.account_ids), date_init,))
# temp_res += float(self.cr.fetchone()[0] or 0.0)
2010-07-27 11:01:43 +00:00
result_tmp = result_tmp + temp_res
return result_tmp
2006-12-07 13:41:40 +00:00
2010-06-16 11:51:39 +00:00
def _sum_litige ( self , data ) :
2008-07-22 15:11:28 +00:00
if not self . ids :
return 0.0
2008-10-06 09:46:37 +00:00
result_tmp = 0.0
2009-01-13 05:47:41 +00:00
temp_res = 0.0
2010-06-10 13:34:19 +00:00
if self . date_lst :
2009-01-13 05:47:41 +00:00
self . cr . execute (
" SELECT sum(debit-credit) " \
" FROM account_move_line AS l " \
2010-06-10 13:34:19 +00:00
" WHERE l.account_id IN %s " \
" AND l.date IN %s " \
" AND l.blocked=TRUE " ,
( tuple ( self . account_ids ) , tuple ( self . date_lst ) , ) )
2009-01-13 05:47:41 +00:00
temp_res = float ( self . cr . fetchone ( ) [ 0 ] or 0.0 )
2010-07-28 11:04:34 +00:00
# if self.initial_balance:
2010-07-28 06:10:50 +00:00
# date_init = (datetime.datetime.strptime(self.date_lst[0], "%Y-%m-%d") + timedelta(days=-1)).strftime('%Y-%m-%d')
# self.cr.execute(
# "SELECT sum(debit-credit) " \
# "FROM account_move_line AS l " \
# "WHERE l.account_id IN %s" \
# "AND l.date < %s",
# (tuple(self.account_ids), date_init,))
# temp_res += float(self.cr.fetchone()[0] or 0.0)
2010-07-14 04:37:02 +00:00
return result_tmp + temp_res
2008-01-11 14:46:53 +00:00
2010-06-16 11:51:39 +00:00
def _sum_sdebit ( self , data ) :
2008-07-22 15:11:28 +00:00
if not self . ids :
return 0.0
2008-10-06 09:46:37 +00:00
result_tmp = 0.0
2009-01-13 05:47:41 +00:00
a = 0.0
2010-06-10 13:34:19 +00:00
if self . date_lst :
2009-01-13 05:47:41 +00:00
self . cr . execute (
" SELECT CASE WHEN sum(debit) > sum(credit) " \
" THEN sum(debit) - sum(credit) " \
" ELSE 0 " \
" END " \
" FROM account_move_line AS l " \
2010-06-10 13:34:19 +00:00
" WHERE l.account_id IN %s " \
" AND l.date IN %s " \
" GROUP BY l.partner_id " ,
( tuple ( self . account_ids ) , tuple ( self . date_lst ) , ) )
2009-01-13 05:47:41 +00:00
a = self . cr . fetchone ( ) [ 0 ]
2008-11-04 12:48:01 +00:00
2009-01-13 05:47:41 +00:00
if self . cr . fetchone ( ) != None :
result_tmp = result_tmp + ( a or 0.0 )
else :
result_tmp = 0.0
2008-11-04 12:48:01 +00:00
return result_tmp
2008-01-11 14:46:53 +00:00
2010-06-16 11:51:39 +00:00
def _sum_scredit ( self , data ) :
2008-07-22 15:11:28 +00:00
if not self . ids :
return 0.0
2008-10-06 09:46:37 +00:00
result_tmp = 0.0
2009-01-13 05:47:41 +00:00
a = 0.0
2010-06-10 13:34:19 +00:00
if self . date_lst :
2009-01-13 05:47:41 +00:00
self . cr . execute (
" SELECT CASE WHEN sum(debit) < sum(credit) " \
" THEN sum(credit) - sum(debit) " \
" ELSE 0 " \
" END " \
" FROM account_move_line AS l " \
2010-06-10 13:34:19 +00:00
" WHERE l.account_id IN %s " \
" AND l.date IN %s " \
" GROUP BY l.partner_id " ,
( tuple ( self . account_ids ) , tuple ( self . date_lst ) , ) )
2009-01-13 05:47:41 +00:00
a = self . cr . fetchone ( ) [ 0 ] or 0.0
if self . cr . fetchone ( ) != None :
result_tmp = result_tmp + ( a or 0.0 )
2009-03-17 10:58:22 +00:00
2009-01-13 05:47:41 +00:00
else :
result_tmp = 0.0
2008-10-06 09:46:37 +00:00
return result_tmp
2008-11-04 12:48:01 +00:00
2010-06-16 11:51:39 +00:00
def _solde_balance_debit ( self , data ) :
2008-10-06 09:46:37 +00:00
debit , credit = self . _sum_debit ( data ) , self . _sum_credit ( data )
2008-07-22 15:11:28 +00:00
return debit > credit and debit - credit
2008-11-04 12:48:01 +00:00
2010-06-16 11:51:39 +00:00
def _solde_balance_credit ( self , data ) :
2008-10-06 09:46:37 +00:00
debit , credit = self . _sum_debit ( data ) , self . _sum_credit ( data )
2008-07-22 15:11:28 +00:00
return credit > debit and credit - debit
2007-07-10 15:24:54 +00:00
2010-07-22 06:00:46 +00:00
def _get_partners ( self , data ) :
if data [ ' form ' ] [ ' result_selection ' ] == ' customer ' :
return ' Receivable Accounts '
elif data [ ' form ' ] [ ' result_selection ' ] == ' supplier ' :
return ' Payable Accounts '
elif data [ ' form ' ] [ ' result_selection ' ] == ' customer_supplier ' :
return ' Receivable and Payable Accounts '
return ' '
2010-07-19 05:44:42 +00:00
report_sxw . report_sxw ( ' report.account.partner.balance ' , ' res.partner ' , ' account/report/partner_balance.rml ' , parser = partner_balance , header = " internal " )
2009-04-09 10:02:19 +00:00
2010-07-14 04:37:02 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: