accelerating openerp accounting

Upload: daviddiz

Post on 04-Jun-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 Accelerating OpenERP Accounting

    1/27

    Accelerating OpenERP accounting:Precalculated period sums

    Borja Lpez Soilnhttp://!"ami!es

    http://www.kami.es/http://www.kami.es/
  • 8/13/2019 Accelerating OpenERP Accounting

    2/27

    #nde$

    %urrent approach &sum o' entries(

    %urrent approach e$plained!

    Per'ormance anal)sis!

    Proposal: *Precalculated period sums+

    Alternati,e -: Accumulated ,alues using triggers

    Proposed .) erdinand 0assauer &%hricar(

    Alternati,e 1: Period totals using the OR2 Proposed .) Borja L!S! &34eoPolus(

    %urrent approach ,s Precalculated period sums

    http://www.chricar.at/ChriCar/index.htmlhttp://twitter.com/NeoPolushttp://twitter.com/NeoPolushttp://www.chricar.at/ChriCar/index.html
  • 8/13/2019 Accelerating OpenERP Accounting

    3/27

    %urrent approach: Sum o' entries

    %urrentl) each time )ou read thecredit/de.it/.alance o' one account OpenERP has

    to recalculate it 'rom the account entries&mo,e lines(!

    5he magic is done .) the *_query_get()+ method

    o' account.move.line6 that selects the lines toconsider6 and the *__compute()+ method o'account.accountthat does the sums!

  • 8/13/2019 Accelerating OpenERP Accounting

    4/27

    #nside the current approach

    _query_get() filters: .uilds the *78ERE+ parto' the S9L uer) that selects all the accountmo,e lines in,ol,ing a set o' accounts!

    Allos to do comple$ 'ilters6 .ut usuall) loo" li"e*include non;dra't entries 'rom these periods 'or theseaccounts+!

    __compute()sums: uses the 'ilter to uer) 'or

    the sums o' de.it/credit/.alance 'or the currentaccount and its children!

  • 8/13/2019 Accelerating OpenERP Accounting

    5/27

    Sample uer) done .)__compute

    SELECTl.account_id as id,COALESCE(SUM(l.debit), 0) as debit,COALESCE(SUM(l.credit), 0) as credit,COALESCE(SUM(l.debit),0) -COALESCE(SUM(l.credit), 0) as balance

    FROMaccount_move_line l

    WHEREl.account_id ! (2, 3, 4, 5, 6, ...,1648, 1649, 1650, 1651)A!" l.state #$

    %dra&t% A!" l.'eriod_id ! (SELEC id *OMaccount_'eriod +E*E &iscalear_id ! ())A!" l.move_id ! (SELEC id *OM account_move+E*E account_move.state / %'osted%)

    GROUP BYl.account_id

    Account = children > lot o' ids?

  • 8/13/2019 Accelerating OpenERP Accounting

    6/27

    Sample uer) plan

    UE*1 2LA!

    ---------------------------------------------------------------------------------------------------------------------

    as3A44re4ate (cost/56.78..56.75 ro9s/ 9idt3/7)

    -$ !ested Loo' Semi :oin (cost/;5.00..56.7< ro9s/ 9idt3/7)

    :oin ilter= (l.'eriod_id / account_'eriod.id)

    -$ !ested Loo' (cost/;5.00..56.5< ro9s/ 9idt3/ on account_'eriod (cost/0.00..0.

  • 8/13/2019 Accelerating OpenERP Accounting

    7/27

    Per'ormance Anal)sis%urrent approach .ig O -/1

    *Selects all the account mo,e lines+5he uer) comple$it) depends on l6 the

    num.er o' mo,e lines 'or that account and

    &recursi,e( children:O(query)> O(f(l))

    *8as to aggregate the children ,alues+5he comple$it) depends on c6 the num.er o'

    children!O(aggregate)> O(g(c))

  • 8/13/2019 Accelerating OpenERP Accounting

    8/27

    %urrent approach .ig O 1/1

    O(__compute) = O(query) + O(aggregate)

    O(__compute)> O(f(l)) + O(g(c))

    7hat "ind o' 'unctions are fand g

    Lets do some empiric testing &'unnier thanmaths6 isnt it(!!!

  • 8/13/2019 Accelerating OpenERP Accounting

    9/27

    Lets test this chart!!! -/1

    5he o''icial Spanishchart o' accounts6 henempt):

    8as a.out -CDDaccounts!

    8as le,els!

    (to test this chart ofaccounts install thel10n_es module)

  • 8/13/2019 Accelerating OpenERP Accounting

    10/27

    Lets test this chart!!! 1/1

    8o man) accounts.elo each le,el

    Account code 4um.er o'children

    &recursi,e(

    Le,el F GHDDDD&lea' account(

    D

    Le,el G ; GHDD -

    Le,el H ; GHD C

    Le,el 1 ; GH GHLe,el - ; G -I1

    Le,el D F D&root account(

    -CJK

    5o get the .alance o' account *G+ e need to sum the .alance o' -I1 accounts?

  • 8/13/2019 Accelerating OpenERP Accounting

    11/27

    O"6 loo"s li"e the num.er o' children chas a

    lot o' in'luence6 and the num.er o' mo,es l

    has little or zero in'luence6 4(c) $$ &(l)

    Lets split them!!!

  • 8/13/2019 Accelerating OpenERP Accounting

    12/27

    4o it is clear that 4(c)is linear?

    &note: the n o' children gros e$ponentiall)(

    O(4(c))=O(c)

  • 8/13/2019 Accelerating OpenERP Accounting

    13/27

    So6 the in'luence as little6 .ut linear too?

    O(&(l)) = O(l)

  • 8/13/2019 Accelerating OpenERP Accounting

    14/27

    Big O ; %onclusion

    O(__compute) = O(l) + O(c)

    chas an une$pectedl) .ig in'luence on the

    results>M Bad per'ormance on comple$ charts o'accounts?

    cdoes not gro ith time6 .ut ldoes!!!>MOpenERP accounting .ecomes sloer andsloer ith time? &though its not that .ad as e$pected(

  • 8/13/2019 Accelerating OpenERP Accounting

    15/27

    Proposal: Precalculated sums

    OpenERP recalculates the de.it/credit/.alance'rom mo,e lines each time!

    2ost accounting programs store the totals per

    period &or the cumulati,e ,alues( 'or eachaccount! 7h)

    Reading the de.it/credit/.alance .ecomes much'aster!

    !!!and reading is much more data intensi,e thanriting:

    Accounting reports read lots o' times lots o' accounts!

    Accountants onl) update a 'e accounts at a time!

  • 8/13/2019 Accelerating OpenERP Accounting

    16/27

    #ts reall) 'aster

    Precalculated sums per period means:

    O(')uer) &get the de.it/credit/.alance o' eachperiod 'or that account( instead o' O(l)uer)6 ith

    '.eing the num.er o' periods6 ' ## l.@sing opening entries6 or cumulati,e totals6 '.ecomes constant >M O()

    #' aggregated sums &ith children ,alues( are also

    precalculated6 e dont ha,e to do oneO(c)aggregation per read!

    #ts O&-( 'or reading??

    (ut creatingediting entries is a it slo"er)

  • 8/13/2019 Accelerating OpenERP Accounting

    17/27

    Alternati,e -: Accumulated ,aluesusing triggers (

    Proposed .) erdinand 0assauer!

    8o does it or"

    4e o.ject to store the accumulated

    de.it/credit/.alance per account and period &letscall it account.period.sum(!

    5riggers on Postgres $pg%&$( update theaccount_period_sumta.le each time an account

    mo,e line is created/updated/deleted!

    Opening -st 1nd Hrd Gth

    2o,e line ,aluesin period

    GDD =1DD6=D

    =1 ;GDD =16=1DD

    Nalue in ta.le GDD CD CJ 1J DD

  • 8/13/2019 Accelerating OpenERP Accounting

    18/27

    Alternati,e -: Accumulated ,aluesusing triggers #(

    8o does it or"&cont!(

    5he data is calculated accumulating the ,alues 'rompre,ious periods! &erdinand protot)pe reuires an special naming o'periods 'or this(!

    %reates S9L ,ies .ased on the accountaccount_period_sumta.le!

    or reports that sho data aggregated .) period:

    4e reports can .e created that either directl) use theS9L ,ies6 or use the account!period!sum o.ject!

    5he account.account.__compute()method could .ee$tended to optimize ueries &modi'ied to ma"e useo' the account_period_sumhen possi.le( in the

    'uture!

  • 8/13/2019 Accelerating OpenERP Accounting

    19/27

    Alternati,e -: Accumulated ,aluesusing triggers ##(

    0ood points

    5riggers guarantee thatthe data is ala)s ins)nc!&e,en i' some.od) rites directl) tothe data.ase?(

    5riggers are 'ast!

    Protot)pe a,aila.le and

    or"ing?; 'used this methodalready in very iginstallations some 100accountants some millionsmoves "ithout any prolems

    (*erdinand)

    Bad points

  • 8/13/2019 Accelerating OpenERP Accounting

    20/27

    Alternati,e 1: Period totals using theOR2 (

    Proposed .) Borja L!S! &34eoPolus(!

    8o does it or"

    4e o.ject to store the de.it/credit/.alance sums

    per account and period (and state)

    E$tends the account.move.lineopen o.ject toupdate the account.sumo.jects each time a line iscreated/updated/deleted!

    Opening -st 1nd Hrd Gth

    2o,e line ,aluesin period

    GDD =1DD6=D

    =1 ;GDD =16=1DD

    Nalue in ta.le GDD 1D 1 ;GDD 11

    http://twitter.com/NeoPolushttp://twitter.com/NeoPolus
  • 8/13/2019 Accelerating OpenERP Accounting

    21/27

    Alternati,e 1: Period totals using theOR2 #(

    8o does it or"&cont!(

    E$tends account.account.__compute()method tooptimize ueries:

    #' the uer) 'ilters onl) .) period/'iscal )ear/state6 thedata is retrie,ed 'rom the account.sumo.ject!

    #' the uer) 'ilters .) dates6 and one ore more 'iscalperiods are 'ull) included on that range6 the data isretrie,ed 'rom 'or the account.sumo.jects &'or the range

    co,ered .) the periods( plus the account.move.lines&therange not co,ered .) periods(!

    iltering .) e,er) other 'ield &'or e$amplepartner_id(causes a 'all.ac" into the normal__computemethod!

  • 8/13/2019 Accelerating OpenERP Accounting

    22/27

    Alternati,e 1: Period totals using theOR2 ##(

    0ood points

    M Easier to maintain!

    Bad points

  • 8/13/2019 Accelerating OpenERP Accounting

    23/27

    %urrent approach NS Period sums

    %urrent approach

    Pros

    4o redundant data!

    Simpler ueries!

    %ons

    Slo!

    Reports and

    dash.oardcharts/ta.les areper'ormance hungr)!

    Becomes e,en sloerith time!

    Precalculated sums

    Pros

    ast6 ala)s!

  • 8/13/2019 Accelerating OpenERP Accounting

    24/27

    #recalculated sums , -rill do"n navigation

    (hricar prototype) 1/

    #recalculated sums , -rill do"n navigation (hricar prototype) /

  • 8/13/2019 Accelerating OpenERP Accounting

    25/27

    #recalculated sums , -rill do"n navigation (hricar prototype) //

  • 8/13/2019 Accelerating OpenERP Accounting

    26/27

  • 8/13/2019 Accelerating OpenERP Accounting

    27/27

    And one last remar"!!!

    !!!all this is applica.le to the stoc" uantitiescomputation too?