I've created my module to fix these bugs. Here are some parts of the module. Thanks!
#####
# PROBLEM: there is an error when start and end periods are the same.
# SOLUTION: In build_ctx_periods, return the period_from_id with a list
# FILE: account.py
class account_period(osv.osv):
_inherit = "account.period"
# FIXED: There is an error if the start and end periods are the same.
def build_ctx_periods(self, cr, uid, period_from_id, period_to_id):
if period_from_id == period_to_id:
return [period_from_id]
return super(account_period, self).build_ctx_periods(cr, uid, period_from_id=period_from_id, period_to_id=period_to_id)
account_period()
#####
#####
# PROBLEM: Target Moves filter functionality does not work in Financial Report, BS and P&L.
# SOLUTION: Include Target Moves in context.
# FILE: account_financial_report.py
class account_financial_report(osv.osv):
_inherit = "account.financial.report"
def _get_balance(self, cr, uid, ids, field_names, args, context=None):
account_obj = self.pool.get('account.account')
res = {}
for report in self.browse(cr, uid, ids, context=context):
if report.id in res: continue res[report.id] = dict((fn, 0.0) for fn in field_names)
if report.type == 'accounts':
# it's the sum of the linked accounts
### Use browse method to include context account_ids = []
for a in report.account_ids: account_ids.append(a.id)
for b in account_obj.browse(cr, uid, account_ids, context=context): for field in field_names: res[report.id][field] += getattr(b, field)
###
elif report.type == 'account_type':
# it's the sum the leaf accounts with such an account type report_types = [x.id for x in report.account_type_ids] account_ids = account_obj.search(cr, uid, [('user_type','in', report_types), ('type','!=','view')], context=context)
for a in account_obj.browse(cr, uid, account_ids, context=context): for field in field_names: res[report.id][field] += getattr(a, field)
elif report.type == 'account_report' and report.account_report_id:
# it's the amount of the linked report res2 = self._get_balance(cr, uid, [report.account_report_id.id], field_names, False, context=context)
for key, value in res2.items(): for field in field_names: res[report.id][field] += value[field]
elif report.type == 'sum':
# it's the sum of the children of this account.report res2 = self._get_balance(cr, uid, [rec.id for rec in report.children_ids], field_names, False, context=context)
for key, value in res2.items(): for field in field_names: res[report.id][field] += value[field]
return res
I've created my module to fix these bugs. Here are some parts of the module. Thanks!
#####
# PROBLEM: there is an error when start and end periods are the same.
# SOLUTION: In build_ctx_periods, return the period_from_id with a list
# FILE: account.py period( osv.osv) :
class account_
_inherit = "account.period"
# FIXED: There is an error if the start and end periods are the same. periods( self, cr, uid, period_from_id, period_to_id): period, self).build_ ctx_periods( cr, uid, period_ from_id= period_ from_id, period_ to_id=period_ to_id)
def build_ctx_
if period_from_id == period_to_id:
return [period_from_id]
return super(account_
account_period()
#####
#####
# PROBLEM: Target Moves filter functionality does not work in Financial Report, BS and P&L.
# SOLUTION: Include Target Moves in context.
# FILE: account_ financial_ report. py financial_ report( osv.osv) : financial. report"
class account_
_inherit = "account.
def _get_balance(self, cr, uid, ids, field_names, args, context=None): get('account. account' )
continue
res[ report. id] = dict((fn, 0.0) for fn in field_names)
account_ ids = []
account_ ids.append( a.id) obj.browse( cr, uid, account_ids, context=context):
for field in field_names:
res[ report. id][field] += getattr(b, field)
report_ types = [x.id for x in report. account_ type_ids]
account_ ids = account_ obj.search( cr, uid, [('user_type','in', report_types), ('type' ,'!=',' view')] , context=context) obj.browse( cr, uid, account_ids, context=context):
for field in field_names:
res[ report. id][field] += getattr(a, field) account_ report_ id:
res2 = self._get_ balance( cr, uid, [report. account_ report_ id.id], field_names, False, context=context)
for field in field_names:
res[ report. id][field] += value[field]
res2 = self._get_ balance( cr, uid, [rec.id for rec in report. children_ ids], field_names, False, context=context)
for field in field_names:
res[ report. id][field] += value[field]
account_obj = self.pool.
res = {}
for report in self.browse(cr, uid, ids, context=context):
if report.id in res:
if report.type == 'accounts':
# it's the sum of the linked accounts
### Use browse method to include context
for a in report.account_ids:
for b in account_
###
elif report.type == 'account_type':
# it's the sum the leaf accounts with such an account type
for a in account_
elif report.type == 'account_report' and report.
# it's the amount of the linked report
for key, value in res2.items():
elif report.type == 'sum':
# it's the sum of the children of this account.report
for key, value in res2.items():
return res
_columns = { function( _get_balance, 'Balance', multi='balance'), function( _get_balance, 'Debit', multi='balance'), function( _get_balance, 'Credit', multi="balance"), financial_ report( )
'balance': fields.
'debit': fields.
'credit': fields.
}
account_
# FILE: wizard/ account_ financial_ report. py report( osv.osv_ memory) :
class accounting_
_inherit = "accounting.report"
def _build_ contexts( self, cr, uid, ids, data, context=None): g_report, self)._ build_contexts( cr, uid, ids, data, context=context)
result[ 'state' ] = 'target_move' in data['form'] and data['form' ]['target_ move'] or False
result = super(accountin
return result
def _build_ comparison_ context( self, cr, uid, ids, data, context=None): g_report, self)._ build_compariso n_context( cr, uid, ids, data, context=context)
result[ 'state' ] = 'target_move' in data['form'] and data['form' ]['target_ move'] or False
result = super(accountin
return result
accounting_report()
#####