openerp-community-reviewer team mailing list archive
-
openerp-community-reviewer team
-
Mailing list archive
-
Message #02236
lp:~camptocamp/account-budgeting/7.0-budget-add-allocation-resubmit-mdh into lp:account-budgeting
Matthieu Dietrich @ camptocamp has proposed merging lp:~camptocamp/account-budgeting/7.0-budget-add-allocation-resubmit-mdh into lp:account-budgeting.
Commit message:
Add allocation type on budget item
Requested reviews:
Account Core Editors (account-core-editors)
For more details, see:
https://code.launchpad.net/~camptocamp/account-budgeting/7.0-budget-add-allocation-resubmit-mdh/+merge/199147
Resubmit of lp:~camptocamp/account-budgeting/7.0-budget-migr-add-allocation-nbi , with the latest lp:account-budgeting as base + fixed comments
--
https://code.launchpad.net/~camptocamp/account-budgeting/7.0-budget-add-allocation-resubmit-mdh/+merge/199147
Your team Account Core Editors is requested to review the proposed merge of lp:~camptocamp/account-budgeting/7.0-budget-add-allocation-resubmit-mdh into lp:account-budgeting.
=== modified file 'budget/__openerp__.py'
--- budget/__openerp__.py 2013-06-14 15:29:02 +0000
+++ budget/__openerp__.py 2013-12-16 15:38:12 +0000
@@ -35,6 +35,7 @@
This module is for real advanced budget use, otherwise prefer to use the
OpenERP official one.
""",
+ "complexity": "expert",
"depends": ["base",
"account",
"analytic_multicurrency",
@@ -45,4 +46,4 @@
],
"installable": True,
"application": True,
-}
+ }
=== modified file 'budget/analytic_view.xml'
--- budget/analytic_view.xml 2013-07-18 11:21:49 +0000
+++ budget/analytic_view.xml 2013-12-16 15:38:12 +0000
@@ -10,6 +10,7 @@
<field name="arch" type="xml">
<tree string="Budget Lines">
<field name="analytic_account_id" invisible="1" />
+ <field name="allocation" invisible="1" />
<field name="budget_version_id" />
<field name="budget_item_id" domain="[('type', '=', 'normal')]" />
<field name="name" />
=== modified file 'budget/budget_item.py'
--- budget/budget_item.py 2013-10-29 09:50:40 +0000
+++ budget/budget_item.py 2013-12-16 15:38:12 +0000
@@ -22,6 +22,13 @@
from openerp.osv import fields, orm
+class allocation_type(orm.Model):
+ """Allocation type from budget line"""
+ _name = "budget.allocation.type"
+
+ _columns = {"name": fields.char('Name', required=True,)}
+
+
class budget_item(orm.Model):
""" Budget Item
@@ -63,6 +70,9 @@
string='Type',
required=True),
'sequence': fields.integer('Sequence'),
+ 'allocation_id': fields.many2one('budget.allocation.type',
+ 'Budget Line Allocation Type'),
+
'style': fields.selection([('normal', 'Normal'),
('bold', 'Bold'),
('invisible', 'Invisible')],
=== modified file 'budget/budget_line.py'
--- budget/budget_line.py 2013-10-29 09:55:56 +0000
+++ budget/budget_line.py 2013-12-16 15:38:12 +0000
@@ -18,6 +18,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
+from datetime import datetime
+from operator import attrgetter, itemgetter
+from itertools import imap
from openerp.osv import fields, orm
from openerp.addons import decimal_precision as dp
@@ -32,6 +35,20 @@
_order = 'name ASC'
+ def _get_alloc_rel(self, cr, uid, ids, context=None):
+ item_obj = self.pool['budget.item']
+ line_obj = self.pool['budget.line']
+ item_ids = item_obj.search(cr, uid, [('allocation_id', 'in', ids)],
+ context=context)
+ if item_ids:
+ line_ids = line_obj.search(cr, uid, [('budget_item_id', 'in', item_ids)],
+ context=context)
+ return line_ids
+ return []
+
+ _store_tuple = (lambda self, cr, uid, ids, c={}: ids, ['budget_item_id'], 10)
+ _alloc_store_tuple = (_get_alloc_rel, [], 20)
+
def _get_budget_currency_amount(self, cr, uid, ids, name, arg, context=None):
""" return the line's amount xchanged in the budget's currency """
res = {}
@@ -124,6 +141,15 @@
'Budget Item',
required=True,
ondelete='restrict'),
+ 'allocation': fields.related('budget_item_id',
+ 'allocation_id',
+ 'name',
+ type='char',
+ string='Budget Item Allocation',
+ select=True,
+ readonly=True,
+ store={'budget.line': _store_tuple,
+ 'budget.allocation.type': _alloc_store_tuple}),
'name': fields.char('Description'),
'amount': fields.float('Amount', required=True),
'currency_id': fields.many2one('res.currency',
@@ -290,3 +316,45 @@
context=context)
values['currency_id'] = account.currency_id.id
return {'value': values}
+
+ def _sum_columns(self, cr, uid, res, orderby, context=None):
+ # We want to sum float and int only
+ cols_to_sum = self._get_applicable_cols()
+ r_ids = self.search(cr, uid, res['__domain'], context=context)
+ lines = self.read(cr, uid, r_ids, cols_to_sum, context=context)
+ if lines:
+ # Summing list of dict For details:
+ # http://stackoverflow.com/questions/974678/
+ # faster implementation as mine even if less readable
+ tmp_res = dict((key, sum(imap(itemgetter(key), lines)))
+ for key in cols_to_sum)
+ res.update(tmp_res)
+ return res
+
+ def _get_applicable_cols(self):
+ """Get function columns of numeric types"""
+ col_to_return = []
+ for col, val in self._columns.iteritems():
+ if (isinstance(val, fields.function) and
+ val._type in ('float', 'integer')):
+ col_to_return.append(col)
+ return col_to_return
+
+ def read_group(self, cr, uid, domain, fields, groupby, offset=0,
+ limit=None, context=None, orderby=False):
+ """ Override in order to see useful values in group by allocation.
+ Compute all numeric value"""
+ res = super(budget_line, self).read_group(cr, uid, domain, fields, groupby,
+ offset, limit, context, orderby)
+ for result in res:
+ self._sum_columns(cr, uid, result, orderby, context=context)
+ #order_by looks like
+ # 'col 1 DESC, col2 DESC, col3 DESC'
+ # Naive implementation we decide of the order using the first DESC ASC
+ if orderby:
+ order = [x.split(' ') for x in orderby.split(',')]
+ reverse = True if order[0][1] == 'DESC' else False
+ getter = [x[0] for x in order if x[0]]
+ if getter:
+ res = sorted(res, key=itemgetter(*getter), reverse=reverse)
+ return res
=== modified file 'budget/budget_view.xml'
--- budget/budget_view.xml 2013-07-18 11:21:49 +0000
+++ budget/budget_view.xml 2013-12-16 15:38:12 +0000
@@ -178,6 +178,7 @@
</div>
<group>
<field name="type" select="1" />
+ <field name="allocation_id" />
<field name="parent_id" select="2" />
<field name="active" select="2"/>
</group>
@@ -226,6 +227,7 @@
<field name="name"/>
<field name="code"/>
<field name="type" />
+ <field name="allocation_id" />
<field name="active" />
</tree>
</field>
@@ -267,6 +269,7 @@
<tree string="Budget Lines" editable="top">
<field name="budget_version_id" />
<field name="budget_item_id" domain="[('type', '=', 'normal')]" />
+ <field name="allocation" invisible="True"/>
<field name="name" />
<field name="analytic_account_id"
on_change="onchange_analytic_account_id(analytic_account_id)"/>
@@ -331,6 +334,7 @@
<group string="Group By..." expand="0">
<filter string="Version" context="{'group_by': 'budget_version_id'}" name="group_budget_version_id"/>
<filter string="Item" context="{'group_by': 'budget_item_id'}" name="group_budget_item_id"/>
+ <filter string="Allocation" context="{'group_by': 'allocation'}" name="group_budget_allocation"/>
<filter string="Contract" context="{'group_by': 'analytic_account_id'}" name="group_analytic_account_id"/>
</group>
</search>
@@ -338,6 +342,26 @@
</record>
+ <record id="budget_item_allocation_type_form" model="ir.ui.view">
+ <field name="name">budget item allocation type form</field>
+ <field name="model">budget.allocation.type</field>
+ <field name="arch" type="xml">
+ <form version="7.0" string="Allocation">
+ <field name="name"/>
+ </form>
+ </field>
+ </record>
+
+ <record id="budget_item_allocation_type_list" model="ir.ui.view">
+ <field name="name">budget item allocation type list</field>
+ <field name="model">budget.allocation.type</field>
+ <field name="arch" type="xml">
+ <list version="7.0" string="Allocation">
+ <field name="name"/>
+ </list>
+ </field>
+ </record>
+
<!-- ########################################### -->
<!-- Actions -->
<!-- ########################################### -->
=== modified file 'budget/security/ir.model.access.csv'
--- budget/security/ir.model.access.csv 2013-05-07 09:39:26 +0000
+++ budget/security/ir.model.access.csv 2013-12-16 15:38:12 +0000
@@ -3,3 +3,4 @@
"access_budget_budget","budget.budget","model_budget_budget","account.group_account_manager",1,1,1,1
"access_budget_version","budget.version","model_budget_version","account.group_account_manager",1,1,1,1
"access_budget_line","budget.line","model_budget_line","account.group_account_manager",1,1,1,1
+"access_budget_allocation_type","budget.allocation","model_budget_allocation_type","account.group_account_manager",1,1,1,1
\ No newline at end of file
Follow ups