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

Proposed by Holger Brunn (Therp)
Status: Needs review
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
Lionel Sausin - Initiatives/Numérigraphe (community) Approve
OpenERP Core Team Pending
Review via email: mp+192878@code.launchpad.net

This proposal supersedes a proposal from 2013-10-10.

To post a comment you must log in.
Revision history for this message
Lionel Sausin - Initiatives/Numérigraphe (ls-initiatives) wrote :

That looks fine

review: Approve

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

Subscribers

People subscribed via source and target branches

to all changes: