[V6.0.2]Wrong analytic account calculation

Bug #878286 reported by Emeric HAMON
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Addons (MOVED TO GITHUB)
Invalid
Undecided
Unassigned

Bug Description

When you have several child analytic account. All the analytic accounts between the root one and the last child are not well calculated.

Hereunder the proposal for correction :

file : analytic/analytic.py
replace the two functions in the file by this :
    def _compute_level_tree(self, cr, uid, ids, child_ids, account_root_ids, res, field_names, context=None):
        def recursive_computation(account_id, res):
            currency_obj = self.pool.get('res.currency')
            account = self.browse(cr, uid, account_id)
            for son in account.child_ids:
                res = recursive_computation(son.id, res)
                for field in field_names:
                    if account.currency_id.id == son.currency_id.id or field=='quantity':
                        res[account.id][field] += res[son.id][field]
                    else:
                        res[account.id][field] += currency_obj.compute(cr, uid, son.currency_id.id, account.currency_id.id, res[son.id][field], context=context)
            return res
        for account in self.browse(cr, uid, ids, context=context):
            if account.id in account_root_ids:
                res = recursive_computation(account.id, res)
        return res

    def _debit_credit_bal_qtty(self, cr, uid, ids, name, arg, context=None):
        res = {}
        if context is None:
            context = {}
        child_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)]))
        account_root_ids = tuple(self.search(cr, uid, [('parent_id', '=', '')]))
        for i in child_ids:
            res[i] = {}
            for n in name:
                res[i][n] = 0.0

        if not child_ids:
            return res

        where_date = ''
        where_clause_args = [tuple(child_ids)]
        if context.get('from_date', False):
            where_date += " AND l.date >= %s"
            where_clause_args += [context['from_date']]
        if context.get('to_date', False):
            where_date += " AND l.date <= %s"
            where_clause_args += [context['to_date']]
        cr.execute("""
              SELECT DISTINCT a.id,
                     sum(
                         CASE WHEN l.amount > 0
                         THEN l.amount
                         ELSE 0.0
                         END
                          ) as debit,
                     sum(
                         CASE WHEN l.amount < 0
                         THEN -l.amount
                         ELSE 0.0
                         END
                          ) as credit,
                     COALESCE(SUM(l.amount),0) AS balance,
                     COALESCE(SUM(l.unit_amount),0) AS quantity
              FROM account_analytic_account a
                  LEFT JOIN account_analytic_line l ON (a.id = l.account_id)
              WHERE a.id IN %s
              """ + where_date + """
              GROUP BY a.id""", where_clause_args)
        for ac_id, debit, credit, balance, quantity in cr.fetchall():
   res[ac_id] = {'debit': debit, 'credit': credit, 'balance': balance, 'quantity': quantity}
        return self._compute_level_tree(cr, uid, ids, child_ids, account_root_ids, res, ['debit', 'credit', 'balance', 'quantity'], context)

Revision history for this message
Amit Parik (amit-parik) wrote :

Hello Emeric,

I have analysed your bug report but I am not getting that where you have faced the problem.

I have checked your issue with latest stable 6.0.3 and trunk both, but analytic account's computation are working fine.

So Would you please provide the proper scenario on this where you have faced the problem, also try with the latest version and notify us.

Thanks and waiting for your reply!

Changed in openobject-addons:
status: New → Incomplete
Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for OpenERP Addons because there has been no activity for 60 days.]

Changed in openobject-addons:
status: Incomplete → Expired
Revision history for this message
Amit Parik (amit-parik) wrote :

Hello Emeric,

Would you please try with the latest updated code.

Currently I am closing this issue, If you still face the problem then you can reopen this with more information.

Thanks.

Changed in openobject-addons:
status: Expired → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.