Merge lp:~vauxoo/openobject-addons/trunk-bug_887376-account_move_compute_with_btree-moylop260 into lp:openobject-addons

Proposed by Moisés López - http://www.vauxoo.com
Status: Work in progress
Proposed branch: lp:~vauxoo/openobject-addons/trunk-bug_887376-account_move_compute_with_btree-moylop260
Merge into: lp:openobject-addons
Diff against target: 114 lines (+67/-3) (has conflicts)
1 file modified
account/account.py (+67/-3)
Text conflict in account/account.py
To merge this branch: bzr merge lp:~vauxoo/openobject-addons/trunk-bug_887376-account_move_compute_with_btree-moylop260
Reviewer Review Type Date Requested Status
Fabien (Open ERP) Pending
Nhomar - Vauxoo Pending
Raphaël Valyi - http://www.akretion.com Pending
Cristian Salamea Pending
Amit Parik Pending
OpenERP R&D Addons Team 3 Pending
Ferdinand Pending
qdp (OpenERP) Pending
Olivier Dony (Odoo) Pending
Review via email: mp+89623@code.launchpad.net

This proposal supersedes a proposal from 2011-11-09.

To post a comment you must log in.
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote : Posted in a previous version of this proposal

(Setting branch status to "Work in Progress" to indicate that it still needs to be updated after more people have a chance to review it, given the fact that it contains test code, TODOs, copy of old code, etc.)

Revision history for this message
Moisés López - http://www.vauxoo.com (moylop260) wrote : Posted in a previous version of this proposal

Hola Odony, ok. I will work in depurate the code and parameters TODOs.
We will wait test result

> (Setting branch status to "Work in Progress" to indicate that it still needs
> to be updated after more people have a chance to review it, given the fact
> that it contains test code, TODOs, copy of old code, etc.)

Revision history for this message
Cristian Salamea (ovnicraft) wrote : Posted in a previous version of this proposal

SQL more readable
params = (tuple(children_and_consolidated),) + query_params

Fix to compile the args with '%s %s ' % (params,..)

review: Needs Fixing
Revision history for this message
Moisés López - http://www.vauxoo.com (moylop260) wrote : Posted in a previous version of this proposal

> SQL more readable
> params = (tuple(children_and_consolidated),) + query_params
>
> Fix to compile the args with '%s %s ' % (params,..)

Hola Cristian. I am agree with you.
But I dont change the current logic. only optimization of query.
the form of params is exactly the same sentence of original.

Revision history for this message
Nhomar - Vauxoo (nhomar) : Posted in a previous version of this proposal
review: Approve
Revision history for this message
Nhomar - Vauxoo (nhomar) wrote : Posted in a previous version of this proposal

Hello Oliver.

I'm sorry, i didn't understand before your point about WORK IN PROGRESS!

The intention of this merge in this way IS NOT a proof of concept, we have using it for 6 month in production.

All TODO's are the original ones in the code we JUST optimize the core SQL code.

IOH, the reason because we left both methods is to help to testers to use BOTH methods compare time and over all RESULTS.

Don't you have a real db with real data to tests purpose on your enviroment?, this feature is so so important and we need mae test.

As you can see it is just ONE method for this reason, i don't face problems in for RC1 left both people make tryies and then we take all, do you have my point friend?

Regards!

PS: If you answer me that you can not make merge to RC 1 for this reason i can correct the merge, but i want to make live easyiest to testers.

Regards.

Revision history for this message
Nhomar - Vauxoo (nhomar) wrote : Posted in a previous version of this proposal

Hello All.

Can somebody tell me what original YAML i can use to test this feature.

LEt me explain :

How we test this feature.

I have 1 year of real data:
We have in the Account CHart ALL internal type of accounts (consolidation was the more difficult to test and solve issues)
We KNOW results for financial reports.
We compare MAnually 5 or 6 key accounts (download account move lines and calculate manually on SpreadSheet)
We see results with OLD and with NEW code.

What shoul be the correct YAML to test it!

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote : Posted in a previous version of this proposal
Download full text (3.4 KiB)

On 01/17/2012 03:49 PM, Nhomar Hernandez (Vauxoo) wrote:
> Can somebody tell me what original YAML i can use to test this feature.

There is probably not much to reuse in the existing YAML tests, as none
are specifically designed to verify the most complex cases of
consolidated charts.

Because this patch touches very core accounting features
(credit/debit/balance computation!), it is very sensitive, and proving
that it does not affect the results is the first step towards getting it
merged.

It also bypasses the aggregation logic used by the rest of the system
(get_children_and_..), so its correctness needs to be assessed even more.

> LEt me explain :
>
> How we test this feature.
>
> I have 1 year of real data:
> We have in the Account CHart ALL internal type of accounts (consolidation was the more difficult to test and solve issues)
> We KNOW results for financial reports.
> We compare MAnually 5 or 6 key accounts (download account move lines and calculate manually on SpreadSheet)
> We see results with OLD and with NEW code.
>
> What shoul be the correct YAML to test it!

Ideally OpenERP should already have such test scenarios, but
unfortunately this is not yet the case, so it makes it harder to review
and validate your patch.

A typical scenario for testing your patch would be to inject some sample
data in a separate demo chart of accounts, making sure to cover as much
complicated cases as possible (different consolidation options, multiple
levels of accounts, etc.) and compute the various credit, debit and
balance results for all of them, comparing them against the correct values.

This does not necessarily need to contain huge volumes of data, because
we're not concerned about performance (that is secondary and not the
goal of the scenario), but the correctness of the calculation.

You should probably create a separate chart of account for the purpose
of this test to make sure your results are not impacted by other changes
to demo data.
Actually, it would even be acceptable to create a new demo XML or CSV
file for the definition of that separate chart of accounts and the
related journal entries, which could then be used as the basis for your
tests. In that case your tests would be very simple: just assert the
result of the functions are correct based on the demo data. The tests
only need to pass after a fresh installation of a new DB with demo data.

This may sound like a lot of work but if you have existing test data you
can perhaps grab a small sample of it, anonymize it and use it as demo
data for the tests? You don't need a lot of data, just enough data to be
representative of the most complicated cases of aggregation (again, we
don't care about the volume).

The good thing about this is that these tests would also become core
accounting tests and used to better validate the core OpenERP Accounting
in the future, in addition to confirming the correctness of the new
algorithm.
Of course the tests should first pass without your patch, and then
continue passing after your patch is applied, confirming that it did not
affect the result, while still improving a lot the performance!

This is critical because if your algorithm works it...

Read more...

Unmerged revisions

6356. By Moisés López - http://www.vauxoo.com

[MERGE] Merge from btree changes

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account/account.py'
2--- account/account.py 2013-12-09 10:50:31 +0000
3+++ account/account.py 2014-01-15 15:52:11 +0000
4@@ -269,9 +269,10 @@
5 return ids2 + ids3
6
7 def __compute(self, cr, uid, ids, field_names, arg=None, context=None,
8- query='', query_params=()):
9+ query='', query_params=()):
10 """ compute the balance, debit and/or credit for the provided
11 account ids
12+
13 Arguments:
14 `ids`: account ids
15 `field_names`: the fields to compute (a list of any of
16@@ -282,6 +283,7 @@
17 (__compute will handle their escaping) as a
18 tuple
19 """
20+<<<<<<< TREE
21 mapping = {
22 'balance': "COALESCE(SUM(l.debit),0) - COALESCE(SUM(l.credit), 0) as balance",
23 'debit': "COALESCE(SUM(l.debit), 0) as debit",
24@@ -292,10 +294,22 @@
25 #get all the necessary accounts
26 children_and_consolidated = self._get_children_and_consol(cr, uid, ids, context=context)
27 #compute for each account the balance/debit/credit from the move lines
28+=======
29+>>>>>>> MERGE-SOURCE
30 accounts = {}
31- res = {}
32- null_result = dict((fn, 0.0) for fn in field_names)
33+ aml_query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
34+
35+ wheres = [""]
36+ if query.strip():
37+ wheres.append(query.strip())
38+ if aml_query.strip():
39+ wheres.append(aml_query.strip())
40+ filters = " AND ".join(wheres)
41+ self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
42+ 'Filters: %s'%filters)
43+ children_and_consolidated = ids
44 if children_and_consolidated:
45+<<<<<<< TREE
46 aml_query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
47
48 wheres = [""]
49@@ -317,8 +331,48 @@
50 " WHERE l.account_id IN %s " \
51 + filters +
52 " GROUP BY l.account_id")
53+=======
54+ request= '''SELECT *, debit-credit AS balance
55+ FROM (
56+ SELECT account_child_and_consolidated.parent_id AS id,
57+ SUM( COALESCE(l.debit,0) ) AS debit, SUM( COALESCE(l.credit,0) ) AS credit,
58+ COALESCE(SUM(l.amount_currency), 0) as foreign_balance
59+ FROM (
60+ SELECT account_child_vw.parent_id, COALESCE( account_consolidated_vw.child_id, account_child_vw.child_id) AS child_id
61+ FROM (
62+ SELECT aa_tree_1.id AS parent_id, aa_tree_2.id AS child_id
63+ FROM account_account aa_tree_1
64+ LEFT OUTER JOIN account_account aa_tree_2
65+ ON aa_tree_2.parent_left
66+ BETWEEN aa_tree_1.parent_left AND aa_tree_1.parent_right
67+ ) account_child_vw
68+ LEFT OUTER JOIN
69+ (
70+ SELECT aa_tree_1.id AS parent_id, aa_tree_4.id AS child_id
71+ FROM account_account_consol_rel
72+ INNER JOIN account_account aa_tree_1
73+ ON aa_tree_1.id = account_account_consol_rel.child_id
74+ INNER JOIN account_account aa_tree_2
75+ ON aa_tree_2.id = account_account_consol_rel.parent_id
76+ LEFT OUTER JOIN account_account aa_tree_3
77+ ON aa_tree_3.parent_left
78+ BETWEEN aa_tree_1.parent_left AND aa_tree_1.parent_right
79+ LEFT OUTER JOIN account_account aa_tree_4
80+ ON aa_tree_4.parent_left
81+ BETWEEN aa_tree_2.parent_left AND aa_tree_2.parent_right
82+ ) account_consolidated_vw
83+ ON account_child_vw.child_id = account_consolidated_vw.parent_id
84+ ) account_child_and_consolidated
85+ LEFT OUTER JOIN account_move_line l
86+ ON l.account_id = account_child_and_consolidated.child_id
87+ ''' \
88+ 'WHERE account_child_and_consolidated.parent_id IN %s ' \
89+ + filters + \
90+ 'GROUP BY account_child_and_consolidated.parent_id ) subvw'
91+>>>>>>> MERGE-SOURCE
92 params = (tuple(children_and_consolidated),) + query_params
93 cr.execute(request, params)
94+<<<<<<< TREE
95
96 for row in cr.dictfetchall():
97 accounts[row['id']] = row
98@@ -361,6 +415,16 @@
99 else:
100 for id in ids:
101 res[id] = null_result
102+=======
103+ self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
104+ 'Status: %s'%cr.statusmessage)
105+ for res1 in cr.dictfetchall():
106+ accounts[res1['id']] = res1
107+ res = {}
108+ for id in ids:
109+ for field_name in field_names:
110+ res.setdefault(id, {})[field_name] = accounts.get(id, {}).get(field_name, 0.0)
111+>>>>>>> MERGE-SOURCE
112 return res
113
114 def _get_company_currency(self, cr, uid, ids, field_name, arg, context=None):

Subscribers

People subscribed via source and target branches

to all changes: