← Back to team overview

openerp-india team mailing list archive

[Bug 1078146] Re: Filter Problems for Financial Report, BS and P&L Reports in OpenERP v6.1

 

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

    _columns = {
        'balance': fields.function(_get_balance, 'Balance', multi='balance'),
        'debit': fields.function(_get_balance, 'Debit', multi='balance'),
        'credit': fields.function(_get_balance, 'Credit', multi="balance"),
    }
account_financial_report()

# FILE: wizard/account_financial_report.py
class accounting_report(osv.osv_memory):
    _inherit = "accounting.report"

    def _build_contexts(self, cr, uid, ids, data, context=None):
        result = super(accounting_report, self)._build_contexts(cr, uid, ids, data, context=context)
        result['state'] = 'target_move' in data['form'] and data['form']['target_move'] or False
        return result

    def _build_comparison_context(self, cr, uid, ids, data, context=None):
        result = super(accounting_report, self)._build_comparison_context(cr, uid, ids, data, context=context)
        result['state'] = 'target_move' in data['form'] and data['form']['target_move'] or False
        return result
accounting_report()
#####

-- 
You received this bug notification because you are a member of OpenERP
Indian Team, which is subscribed to OpenERP Addons.
https://bugs.launchpad.net/bugs/1078146

Title:
  Filter Problems for Financial Report, BS and P&L Reports in OpenERP
  v6.1

Status in OpenERP Addons (modules):
  New

Bug description:
  Target Moves filter in Financial Report, Balance Sheet and Profit &
  Loss (Accounting > Reporting > Legal Reports > Accounting Reports)
  does not work properly. It always print 'all entries' even the value
  of Target Moves is 'all posted entries'. In addition, the period
  filters does not work if the start and end periods are the same.

To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-addons/+bug/1078146/+subscriptions


References