Merge lp:~camptocamp/account-budgeting/7.0-budget-add-allocation-resubmit-mdh into lp:~account-core-editors/account-budgeting/7.0

Proposed by Matthieu Dietrich @ camptocamp
Status: Merged
Approved by: Yannick Vaucher @ Camptocamp
Approved revision: 79
Merged at revision: 73
Proposed branch: lp:~camptocamp/account-budgeting/7.0-budget-add-allocation-resubmit-mdh
Merge into: lp:~account-core-editors/account-budgeting/7.0
Diff against target: 242 lines (+121/-1)
6 files modified
budget/__openerp__.py (+2/-1)
budget/analytic_view.xml (+1/-0)
budget/budget_item.py (+12/-0)
budget/budget_line.py (+81/-0)
budget/budget_view.xml (+24/-0)
budget/security/ir.model.access.csv (+1/-0)
To merge this branch: bzr merge lp:~camptocamp/account-budgeting/7.0-budget-add-allocation-resubmit-mdh
Reviewer Review Type Date Requested Status
Guewen Baconnier @ Camptocamp code review Approve
Yannick Vaucher @ Camptocamp code review, no tests Approve
Review via email: mp+199147@code.launchpad.net

Commit message

Add allocation type on budget item

Description of the change

To post a comment you must log in.
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

budget_line.py|21 col 1| F401 'datetime' imported but unused
budget_line.py|22 col 1| F401 'attrgetter' imported but unused

_sum_columns could get a better doc string to explain it updates the res dict parameter

l.146 extra space at "col 1" in comment it wouldn't work with split in the next list comprehension
BTW can't orderby accept string as "col1, col2 ASC, col3 DESC, col4" ?

l.150 ? :o)
Plus it will fail with an "out of range" exception with a groupby on which ASC or DESC is not defined

What about?
reverse = len(order[0]) == 2 and order[0][1] == 'DESC'

As if not specified means "ASC"

review: Needs Fixing (code review, no tests)
74. By Nicolas Bessi - Camptocamp

[FIX] unused import + add some defensivness in order guessing

Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

Just committed import fixing and a defensiveness of code

75. By Nicolas Bessi - Camptocamp

[FIX] ensure order is set

76. By Nicolas Bessi - Camptocamp

[IMP] docstring

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

Thanks for the fixes

LGTM

review: Approve (code review, no tests)
77. By Guewen Baconnier @ Camptocamp

[CHG] expand the _columns so the diff will be cleaner if a field is added

78. By Guewen Baconnier @ Camptocamp

[FIX] no mutable in default arguments

79. By Guewen Baconnier @ Camptocamp

[IMP] spacing, docstrings, long line

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Pushed a few changes. LGTM
Thanks

review: Approve (code review)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'budget/__openerp__.py'
2--- budget/__openerp__.py 2013-06-14 15:29:02 +0000
3+++ budget/__openerp__.py 2013-12-19 09:04:52 +0000
4@@ -35,6 +35,7 @@
5 This module is for real advanced budget use, otherwise prefer to use the
6 OpenERP official one.
7 """,
8+ "complexity": "expert",
9 "depends": ["base",
10 "account",
11 "analytic_multicurrency",
12@@ -45,4 +46,4 @@
13 ],
14 "installable": True,
15 "application": True,
16-}
17+ }
18
19=== modified file 'budget/analytic_view.xml'
20--- budget/analytic_view.xml 2013-07-18 11:21:49 +0000
21+++ budget/analytic_view.xml 2013-12-19 09:04:52 +0000
22@@ -10,6 +10,7 @@
23 <field name="arch" type="xml">
24 <tree string="Budget Lines">
25 <field name="analytic_account_id" invisible="1" />
26+ <field name="allocation" invisible="1" />
27 <field name="budget_version_id" />
28 <field name="budget_item_id" domain="[('type', '=', 'normal')]" />
29 <field name="name" />
30
31=== modified file 'budget/budget_item.py'
32--- budget/budget_item.py 2013-10-29 09:50:40 +0000
33+++ budget/budget_item.py 2013-12-19 09:04:52 +0000
34@@ -22,6 +22,15 @@
35 from openerp.osv import fields, orm
36
37
38+class allocation_type(orm.Model):
39+ """Allocation type from budget line"""
40+ _name = "budget.allocation.type"
41+
42+ _columns = {
43+ 'name': fields.char('Name', required=True),
44+ }
45+
46+
47 class budget_item(orm.Model):
48 """ Budget Item
49
50@@ -63,6 +72,9 @@
51 string='Type',
52 required=True),
53 'sequence': fields.integer('Sequence'),
54+ 'allocation_id': fields.many2one('budget.allocation.type',
55+ 'Budget Line Allocation Type'),
56+
57 'style': fields.selection([('normal', 'Normal'),
58 ('bold', 'Bold'),
59 ('invisible', 'Invisible')],
60
61=== modified file 'budget/budget_line.py'
62--- budget/budget_line.py 2013-10-29 09:55:56 +0000
63+++ budget/budget_line.py 2013-12-19 09:04:52 +0000
64@@ -18,6 +18,8 @@
65 # along with this program. If not, see <http://www.gnu.org/licenses/>.
66 #
67 ##############################################################################
68+from operator import itemgetter
69+from itertools import imap
70 from openerp.osv import fields, orm
71 from openerp.addons import decimal_precision as dp
72
73@@ -32,6 +34,22 @@
74
75 _order = 'name ASC'
76
77+ def _get_alloc_rel(self, cr, uid, ids, context=None):
78+ item_obj = self.pool['budget.item']
79+ line_obj = self.pool['budget.line']
80+ item_ids = item_obj.search(cr, uid, [('allocation_id', 'in', ids)],
81+ context=context)
82+ if item_ids:
83+ line_ids = line_obj.search(cr, uid,
84+ [('budget_item_id', 'in', item_ids)],
85+ context=context)
86+ return line_ids
87+ return []
88+
89+ _store_tuple = (lambda self, cr, uid, ids, c=None: ids,
90+ ['budget_item_id'], 10)
91+ _alloc_store_tuple = (_get_alloc_rel, [], 20)
92+
93 def _get_budget_currency_amount(self, cr, uid, ids, name, arg, context=None):
94 """ return the line's amount xchanged in the budget's currency """
95 res = {}
96@@ -124,6 +142,15 @@
97 'Budget Item',
98 required=True,
99 ondelete='restrict'),
100+ 'allocation': fields.related('budget_item_id',
101+ 'allocation_id',
102+ 'name',
103+ type='char',
104+ string='Budget Item Allocation',
105+ select=True,
106+ readonly=True,
107+ store={'budget.line': _store_tuple,
108+ 'budget.allocation.type': _alloc_store_tuple}),
109 'name': fields.char('Description'),
110 'amount': fields.float('Amount', required=True),
111 'currency_id': fields.many2one('res.currency',
112@@ -290,3 +317,57 @@
113 context=context)
114 values['currency_id'] = account.currency_id.id
115 return {'value': values}
116+
117+ def _sum_columns(self, cr, uid, res, orderby, context=None):
118+ """ Compute sum of columns showed by the group by
119+
120+ :param res: standard group by result
121+ :param orderby: order by string sent by webclient
122+ :returns: updated dict with missing sums of int and float
123+
124+ """
125+ # We want to sum float and int only
126+ cols_to_sum = self._get_applicable_cols()
127+ r_ids = self.search(cr, uid, res['__domain'], context=context)
128+ lines = self.read(cr, uid, r_ids, cols_to_sum, context=context)
129+ if lines:
130+ # Summing list of dict For details:
131+ # http://stackoverflow.com/questions/974678/
132+ # faster implementation as mine even if less readable
133+ tmp_res = dict((key, sum(imap(itemgetter(key), lines)))
134+ for key in cols_to_sum)
135+ res.update(tmp_res)
136+ return res
137+
138+ def _get_applicable_cols(self):
139+ """ Get function columns of numeric types """
140+ col_to_return = []
141+ for col, val in self._columns.iteritems():
142+ if (isinstance(val, fields.function) and
143+ val._type in ('float', 'integer')):
144+ col_to_return.append(col)
145+ return col_to_return
146+
147+ def read_group(self, cr, uid, domain, fields, groupby, offset=0,
148+ limit=None, context=None, orderby=False):
149+ """ Override in order to see useful values in group by allocation.
150+
151+ Compute all numerical values.
152+
153+ """
154+ res = super(budget_line, self).read_group(cr, uid, domain, fields, groupby,
155+ offset, limit, context, orderby)
156+ for result in res:
157+ self._sum_columns(cr, uid, result, orderby, context=context)
158+ # order_by looks like
159+ # 'col1 DESC, col2 DESC, col3 DESC'
160+ # Naive implementation we decide of the order using the first DESC ASC
161+ if orderby:
162+ order = [x.split(' ') for x in orderby.split(',')]
163+ reverse = False
164+ if order and len(order[0]) > 1:
165+ reverse = (order[0][1] == 'DESC')
166+ getter = [x[0] for x in order if x[0]]
167+ if getter:
168+ res = sorted(res, key=itemgetter(*getter), reverse=reverse)
169+ return res
170
171=== modified file 'budget/budget_view.xml'
172--- budget/budget_view.xml 2013-07-18 11:21:49 +0000
173+++ budget/budget_view.xml 2013-12-19 09:04:52 +0000
174@@ -178,6 +178,7 @@
175 </div>
176 <group>
177 <field name="type" select="1" />
178+ <field name="allocation_id" />
179 <field name="parent_id" select="2" />
180 <field name="active" select="2"/>
181 </group>
182@@ -226,6 +227,7 @@
183 <field name="name"/>
184 <field name="code"/>
185 <field name="type" />
186+ <field name="allocation_id" />
187 <field name="active" />
188 </tree>
189 </field>
190@@ -267,6 +269,7 @@
191 <tree string="Budget Lines" editable="top">
192 <field name="budget_version_id" />
193 <field name="budget_item_id" domain="[('type', '=', 'normal')]" />
194+ <field name="allocation" invisible="True"/>
195 <field name="name" />
196 <field name="analytic_account_id"
197 on_change="onchange_analytic_account_id(analytic_account_id)"/>
198@@ -331,6 +334,7 @@
199 <group string="Group By..." expand="0">
200 <filter string="Version" context="{'group_by': 'budget_version_id'}" name="group_budget_version_id"/>
201 <filter string="Item" context="{'group_by': 'budget_item_id'}" name="group_budget_item_id"/>
202+ <filter string="Allocation" context="{'group_by': 'allocation'}" name="group_budget_allocation"/>
203 <filter string="Contract" context="{'group_by': 'analytic_account_id'}" name="group_analytic_account_id"/>
204 </group>
205 </search>
206@@ -338,6 +342,26 @@
207 </record>
208
209
210+ <record id="budget_item_allocation_type_form" model="ir.ui.view">
211+ <field name="name">budget item allocation type form</field>
212+ <field name="model">budget.allocation.type</field>
213+ <field name="arch" type="xml">
214+ <form version="7.0" string="Allocation">
215+ <field name="name"/>
216+ </form>
217+ </field>
218+ </record>
219+
220+ <record id="budget_item_allocation_type_list" model="ir.ui.view">
221+ <field name="name">budget item allocation type list</field>
222+ <field name="model">budget.allocation.type</field>
223+ <field name="arch" type="xml">
224+ <list version="7.0" string="Allocation">
225+ <field name="name"/>
226+ </list>
227+ </field>
228+ </record>
229+
230 <!-- ########################################### -->
231 <!-- Actions -->
232 <!-- ########################################### -->
233
234=== modified file 'budget/security/ir.model.access.csv'
235--- budget/security/ir.model.access.csv 2013-05-07 09:39:26 +0000
236+++ budget/security/ir.model.access.csv 2013-12-19 09:04:52 +0000
237@@ -3,3 +3,4 @@
238 "access_budget_budget","budget.budget","model_budget_budget","account.group_account_manager",1,1,1,1
239 "access_budget_version","budget.version","model_budget_version","account.group_account_manager",1,1,1,1
240 "access_budget_line","budget.line","model_budget_line","account.group_account_manager",1,1,1,1
241+"access_budget_allocation_type","budget.allocation","model_budget_allocation_type","account.group_account_manager",1,1,1,1
242\ No newline at end of file

Subscribers

People subscribed via source and target branches