← Back to team overview

c2c-oerpscenario team mailing list archive

Re: [Bug 783670] Re: account - level - wrong computation

 

On 05/17/2011 04:10 PM, Ferdinand @ Camptocamp wrote:
> ad 1) for my chart of account the levels are not correct
> 
> I dropped the level field to let it recalculate, but it's still wrong.

Alright, after looking at the ORM code, it's because of another issue:
this is an integer field and OpenERP treats NULLs as zero for integer
fields, so it assumes the field value is already computed for the parent
indeed.
In addition, OpenERP function fields are meant to be computed in batch
and not lazily through recursion, so this approach does not work.

> may be it's due to my poor understanding of python and what (not)
> happens in detail, but this code seems not to be called recursively, I
> am missing a while.... condition

A recursive function is simply a function that calls itself, directly or
indirectly [1]. This is the case here because "obj.level" is a call that
will perform read() on the "level" column of the given browse_record,
which in turn is supposed to access the _get_level() function that
computes the value. And so on if the parent has a parent..
However, as you've noticed, it fails to properly compute the level
because the call to obtain the parent's level is not properly handled
(for the reasons explained above).

So you're right, we need to fix the computation, and I think the
suggested approach from comment #1, with a query based on "parent_left"
should work efficiently enough.

Thank you for the follow-up!

[1] http://en.wikipedia.org/wiki/Recursion_(computer_science)

-- 
You received this bug notification because you are a member of C2C
OERPScenario, which is subscribed to the OpenERP Project Group.
https://bugs.launchpad.net/bugs/783670

Title:
  account - level - wrong computation

Status in OpenERP Modules (addons):
  Confirmed

Bug description:
  account/account.py

  def _get_level

  currently the calculated level (except level 1) is very much random,
  depending on the sequence of processed records

  2 issues:
  1) IMHO the function makes the wrong assumption that the level of the parent account is already calculated, which is not necessarily the case
  2) the level (stored=True) of all childs must be recalculated if the level of a parent changes. IMHO this would also solve issue 1).
  change of structure may be done any time manually.


References