Merge lp:~therp-nl/openobject-addons/trunk_lp1237832 into lp:openobject-addons

Proposed by Holger Brunn (Therp)
Status: Superseded
Proposed branch: lp:~therp-nl/openobject-addons/trunk_lp1237832
Merge into: lp:openobject-addons
Diff against target: 168 lines (+146/-1)
3 files modified
account_budget/account_budget.py (+15/-1)
account_budget/tests/__init__.py (+5/-0)
account_budget/tests/test_child_accounts.py (+126/-0)
To merge this branch: bzr merge lp:~therp-nl/openobject-addons/trunk_lp1237832
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+190310@code.launchpad.net

This proposal has been superseded by a proposal from 2013-10-28.

Commit message

[FIX] recurse into analytic account's children when calculating practical
amount in budgets

To post a comment you must log in.
8941. By Holger Brunn (Therp)

[ADD] test to verify recursing into analytic child accounts

Unmerged revisions

8941. By Holger Brunn (Therp)

[ADD] test to verify recursing into analytic child accounts

8940. By Holger Brunn (Therp)

[FIX] recurse into analytic account's children when calculating practical
amount in budgets

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account_budget/account_budget.py'
2--- account_budget/account_budget.py 2013-04-15 10:23:49 +0000
3+++ account_budget/account_budget.py 2013-10-28 14:12:18 +0000
4@@ -122,7 +122,21 @@
5 if context.has_key('wizard_date_to'):
6 date_to = context['wizard_date_to']
7 if line.analytic_account_id.id:
8- cr.execute("SELECT SUM(amount) FROM account_analytic_line WHERE account_id=%s AND (date "
9+ cr.execute("SELECT SUM(amount) FROM account_analytic_line WHERE account_id in "
10+ """(with recursive account_analytic_account_hierarchy(id)
11+ as
12+ (
13+ select id from account_analytic_account
14+ where id=%s
15+ union all
16+ select account_analytic_account.id from
17+ account_analytic_account
18+ join account_analytic_account_hierarchy
19+ on account_analytic_account.parent_id=
20+ account_analytic_account_hierarchy.id
21+ )"""
22+ "select id from account_analytic_account_hierarchy) "
23+ "AND (date "
24 "between to_date(%s,'yyyy-mm-dd') AND to_date(%s,'yyyy-mm-dd')) AND "
25 "general_account_id=ANY(%s)", (line.analytic_account_id.id, date_from, date_to,acc_ids,))
26 result = cr.fetchone()[0]
27
28=== added directory 'account_budget/tests'
29=== added file 'account_budget/tests/__init__.py'
30--- account_budget/tests/__init__.py 1970-01-01 00:00:00 +0000
31+++ account_budget/tests/__init__.py 2013-10-28 14:12:18 +0000
32@@ -0,0 +1,5 @@
33+from . import test_child_accounts
34+
35+fast_suite = [
36+ test_child_accounts,
37+ ]
38
39=== added file 'account_budget/tests/test_child_accounts.py'
40--- account_budget/tests/test_child_accounts.py 1970-01-01 00:00:00 +0000
41+++ account_budget/tests/test_child_accounts.py 2013-10-28 14:12:18 +0000
42@@ -0,0 +1,126 @@
43+from datetime import datetime
44+from openerp.tests.common import TransactionCase
45+from openerp.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT
46+
47+class TestChildAccounts(TransactionCase):
48+
49+ def setUp(self):
50+ super(TestChildAccounts, self).setUp()
51+ self.budget_model = self.registry('crossovered.budget')
52+ self.budget_post_model = self.registry('account.budget.post')
53+ self.account_model = self.registry('account.account')
54+ self.analytic_account_model = self.registry('account.analytic.account')
55+
56+ def test_child_accounts(self):
57+ '''
58+ Test if an analytic's child account's lines are also counted in a
59+ budget
60+ '''
61+ account_id = self.account_model.create(
62+ self.cr,
63+ self.uid,
64+ {
65+ 'name': 'testaccount',
66+ 'code': 'test42',
67+ 'user_type': self.ref(
68+ 'account.data_account_type_receivable'),
69+ })
70+ analytic_account_id = self.analytic_account_model.create(
71+ self.cr,
72+ self.uid,
73+ {
74+ 'name': 'testaccount',
75+ 'code': 'test42',
76+ })
77+ analytic_account_child_id = self.analytic_account_model.create(
78+ self.cr,
79+ self.uid,
80+ {
81+ 'name': 'testaccount child',
82+ 'code': 'test42.1',
83+ 'parent_id': analytic_account_id,
84+ })
85+ budget_post_id = self.budget_post_model.create(
86+ self.cr,
87+ self.uid,
88+ {
89+ 'name': 'testbudgetpost',
90+ 'code': 'test42',
91+ 'account_ids': [(6, 0, [account_id])],
92+ })
93+ budget_id = self.budget_model.create(
94+ self.cr,
95+ self.uid,
96+ {
97+ 'name': 'testbudget',
98+ 'code': 'test42',
99+ 'date_from': datetime.today().replace(month=1, day=1)\
100+ .strftime(DEFAULT_SERVER_DATETIME_FORMAT),
101+ 'date_to': datetime.today().replace(month=12, day=31)\
102+ .strftime(DEFAULT_SERVER_DATETIME_FORMAT),
103+ 'crossovered_budget_line': [
104+ (
105+ 0, 0,
106+ {
107+ 'general_budget_id': budget_post_id,
108+ 'analytic_account_id': analytic_account_id,
109+ 'date_from': datetime.today()\
110+ .replace(month=1, day=1)\
111+ .strftime(
112+ DEFAULT_SERVER_DATETIME_FORMAT),
113+ 'date_to': datetime.today()\
114+ .replace(month=12, day=31)\
115+ .strftime(
116+ DEFAULT_SERVER_DATETIME_FORMAT),
117+ 'planned_amount': 42,
118+ },
119+ )
120+ ],
121+ })
122+ journal_id = self.registry('account.analytic.journal').search(
123+ self.cr, self.uid, [])[0]
124+
125+ self.analytic_account_model.write(
126+ self.cr,
127+ self.uid,
128+ analytic_account_id,
129+ {
130+ 'line_ids': [
131+ (
132+ 0, 0,
133+ {
134+ 'name': '/',
135+ 'date': datetime.today()\
136+ .strftime(
137+ DEFAULT_SERVER_DATETIME_FORMAT),
138+ 'amount': 42,
139+ 'general_account_id': account_id,
140+ 'journal_id': journal_id,
141+ },
142+ ),
143+ ],
144+ })
145+ self.analytic_account_model.write(
146+ self.cr,
147+ self.uid,
148+ analytic_account_child_id,
149+ {
150+ 'line_ids': [
151+ (
152+ 0, 0,
153+ {
154+ 'name': '/',
155+ 'date': datetime.today()\
156+ .strftime(
157+ DEFAULT_SERVER_DATETIME_FORMAT),
158+ 'amount': 42,
159+ 'general_account_id': account_id,
160+ 'journal_id': journal_id,
161+ },
162+ ),
163+ ],
164+ })
165+
166+
167+ budget = self.budget_model.browse(self.cr, self.uid, budget_id)
168+ assert budget.crossovered_budget_line[0].practical_amount == 84

Subscribers

People subscribed via source and target branches

to all changes: