Browse Source

Merge pull request #9 from bealdav/7.0-tree-view-id

[ADD] tree_view_record_id module
pull/71/head
Sandy 10 years ago
parent
commit
2981a389d0
  1. 11
      tree_view_record_id/__init__.py
  2. 58
      tree_view_record_id/__openerp__.py
  3. 64
      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

58
tree_view_record_id/__openerp__.py

@ -0,0 +1,58 @@
# -*- 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': "Adds id field to tree views",
'description': """
Adds Id field in all tree views of any modules/models, except:
* Arborescent tree views like 'Products by Category', 'Chart of accounts', etc.
* Tree views (like in wizard 'Change password') built on transient models
which don't have this column in their table.
Id field is the primary key of standard sql tables
defined by the orm (Odoo model).
""",
'website': 'http://www.akretion.com',
'depends': [
'base',
],
'data': [
],
'demo': [
],
'installable': True,
'auto_install': False,
'application': False,
'images': [
],
'css': [
],
'js': [
],
'qweb': [
],
}

64
tree_view_record_id/orm.py

@ -0,0 +1,64 @@
# -*- 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
TRY TO SWITCH to _register_hook() in the model to avoid
execution when not installed in V 8.0 version
"""
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 = res.get('field_parent', True) is 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 '_transient_max_count' in self.pool[res['model']].__dict__.keys():
# model with '_transient_max_count' key are transient model
# transient models haven't 'id' column in mostly case
compatible_tree = False
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