Browse Source

[ADD] tree_view_record_id module

pull/9/head
david.beal@akretion.com 10 years ago
parent
commit
715f846ebe
  1. 11
      tree_view_record_id/__init__.py
  2. 53
      tree_view_record_id/__openerp__.py
  3. 57
      tree_view_record_id/orm.py

11
tree_view_record_id/__init__.py

@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# licence AGPL version 3 or later
# see licence in __openerp__.py or http://www.gnu.org/licenses/agpl-3.0.txt
# Copyright (C) 2014 Akretion (http://www.akretion.com).
# @author David BEAL <david.beal@akretion.com>
#
##############################################################################
import orm

53
tree_view_record_id/__openerp__.py

@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-
###############################################################################
#
# Copyright (C) 2012-TODAY Akretion <http://www.akretion.com>.
# All Rights Reserved
# @author David BEAL <david.beal@akretion.com>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
{
'name': 'Tree View Record Id',
'version': '0.1',
'category': 'Other modules',
'sequence': 10,
'author': 'Akretion',
'summary': "Add id field to tree views",
'description': """
Add Id field to all non arborescent tree views.
Id field is the primary key of the table (Odoo model).
Arborescent views like 'Products by Category' or 'Chart of accounts' haven't this field included.
""",
'website': 'http://www.akretion.com',
'depends': [
'base',
],
'data': [
],
'demo': [
],
'installable': True,
'auto_install': True,
'application': False,
'images': [
],
'css': [
],
'js': [
],
'qweb': [
],
}

57
tree_view_record_id/orm.py

@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# licence AGPL version 3 or later
# see licence in __openerp__.py or http://www.gnu.org/licenses/agpl-3.0.txt
# Copyright (C) 2014 Akretion (http://www.akretion.com).
# @author David BEAL <david.beal@akretion.com>
#
##############################################################################
from openerp.osv import orm
from lxml import etree
import os
""" procedural code is executed even if the module is not installed
"""
module_name = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
DUMMY_MODEL = 'module.%s.installed' % module_name.replace('_', '.')
class DummyModel(orm.Model):
""" Allow to check if module is installed or not
in fields_view_get method to avoid code execution if not
Only executed if the module is installed
"""
_name = DUMMY_MODEL
fields_view_get_orginal = orm.BaseModel.fields_view_get
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None,
toolbar=False, submenu=False):
res = fields_view_get_orginal(
self, cr, uid, view_id=view_id, view_type=view_type, context=context,
toolbar=toolbar, submenu=submenu)
if view_type == 'tree':
compatible_tree = False
# Tree views with res['field_parent'] different from False
# looks like 'Products by Category'.
# We don't modify these views
# to avoid to break them (js error)
if res.get('field_parent', True) is False:
compatible_tree = True
if compatible_tree and DUMMY_MODEL in self.pool.models.keys():
doc = etree.XML(res['arch'])
if doc.xpath("//tree") and len(doc.xpath("//field[@name='id']")) == 0:
node = doc.xpath("//tree")[0]
node.append(etree.Element("field", name="id", string="Id"))
res['arch'] = etree.tostring(node)
return res
orm.BaseModel.fields_view_get = fields_view_get
Loading…
Cancel
Save