Browse Source

[MRG] Solving conflicts

pull/78/head
Maxime Chambreuil 12 years ago
parent
commit
e1227e6791
  1. 35
      dbfilter_from_header/__init__.py
  2. 52
      dbfilter_from_header/__openerp__.py
  3. 1
      email_template_template/__init__.py
  4. 96
      email_template_template/__openerp__.py
  5. 21
      email_template_template/model/__init__.py
  6. 56
      email_template_template/model/email_template.py
  7. 71
      email_template_template/view/email_template.xml
  8. 1
      fetchmail_attach_from_folder/__openerp__.py
  9. 2
      fetchmail_attach_from_folder/model/fetchmail_server.py
  10. 2
      fetchmail_attach_from_folder/security/ir.model.access.csv
  11. 22
      unserialize_field/__init__.py
  12. 46
      unserialize_field/__openerp__.py
  13. 115
      unserialize_field/ir_model_fields.py
  14. 36
      unserialize_field/ir_model_fields.xml
  15. 22
      view_groups_id/__init__.py
  16. 53
      view_groups_id/__openerp__.py
  17. 22
      view_groups_id/model/__init__.py
  18. 55
      view_groups_id/model/ir_ui_view.py
  19. 18
      view_groups_id/view/ir_ui_view.xml

35
dbfilter_from_header/__init__.py

@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2013 Therp BV (<http://therp.nl>).
#
# 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/>.
#
##############################################################################
import re
from openerp.addons.web.controllers.main import Database
from openerp.addons.web.common.http import jsonrequest
get_list_org = Database.get_list.__closure__[0].cell_contents
@jsonrequest
def get_list(self, req):
db_filter = req.httprequest.environ.get('HTTP_X_OPENERP_DBFILTER', '.*')
dbs = get_list_org(self, req)
return {'db_list': [db for db in
dbs.get('db_list', [])
if re.match(db_filter, db)]}
Database.get_list = get_list

52
dbfilter_from_header/__openerp__.py

@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2013 Therp BV (<http://therp.nl>).
#
# 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" : "dbfilter_from_header",
"version" : "1.0",
"author" : "Therp BV",
"complexity": "normal",
"description": """
This addon lets you pass a dbfilter as a HTTP header.
This is interesting for setups where database names can't be mapped to
proxied host names.
In nginx, use
proxy_set_header X-OpenERP-dbfilter [your filter];
The addon has to be loaded as server-wide module.
""",
"category" : "Tools",
"depends" : [
'web',
],
"data" : [
],
"js": [
],
"css": [
],
"auto_install": False,
"installable": True,
"external_dependencies" : {
'python' : [],
},
}

1
email_template_template/__init__.py

@ -0,0 +1 @@
import model

96
email_template_template/__openerp__.py

@ -0,0 +1,96 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2012 Therp BV (<http://therp.nl>).
#
# 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": "Templates for email templates",
"version": "1.0",
"author": "Therp BV",
"category": 'Tools',
'complexity': "expert",
"description": """If an organisation's email layout is a bit more
complicated, changes can be tedious when having to do that across several email
templates. So this addon allows to define templates for mails that is referenced
by other mail templates.
This way we can put the layout parts into the template template and only content
in the other templates. Changing the layout is then only a matter of changing
the template template.
Usage:
Create an email template with the related document model 'Email Templates'. Now
most of the fields gray out and you can only edit body_text and body_html. Be
sure to use ${body_text} and ${body_html} respectively in your template
template.
Then select this newly created template templates in one of your actual
templates.
For example, create a template template
-----
Example Corp logo
Example Corp header
${object.body_text} <- this gets evaluated to the body_text of a template using this template template
Example Corp
Example street 42
Example city
Example Corp footer
-----
Then in your template you write
-----
Dear ${object.partner_id.name},
Your order has been booked on date ${object.date} for a total amount of ${object.sum}.
-----
And it will be evaluated to
-----
Example Corp logo
Example Corp header
Dear Jane Doe,
Your order has been booked on date 04/17/2013 for a total amount of 42.
Example Corp
Example street 42
Example city
Example Corp footer
-----
Given the way evaluation works internally (body_text of the template template is evaluated two times, first with the instance of email.template of your own template, then with the object your template refers to), you can do some trickery if you know that a template template is always used with the same kind of model (that is, models that have the same field name):
In your template template:
------
Dear ${'${object.name}'}, <-- gets evaluated to "${object.name}" in the first step, then to the content of object.name
${object.body_html}
Best,
Example Corp
------""",
'website': 'http://therp.nl',
'images': [],
'depends': ['email_template'],
'data': [
'view/email_template.xml',
],
"license": 'AGPL-3',
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

21
email_template_template/model/__init__.py

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2012 Therp BV (<http://therp.nl>).
#
# 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/>.
#
##############################################################################
import email_template

56
email_template_template/model/email_template.py

@ -0,0 +1,56 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2012 Therp BV (<http://therp.nl>).
#
# 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/>.
#
##############################################################################
from openerp.osv.orm import Model
from openerp.osv import fields
class email_template(Model):
_inherit = 'email.template'
def _get_is_template_template(self, cr, uid, ids, fields_name, arg,
context=None):
cr.execute('''select
id, (select count(*) > 0 from email_template e
where email_template_id=email_template.id)
from email_template
where id in %s''', (tuple(ids),))
return dict(cr.fetchall())
_columns = {
'email_template_id': fields.many2one('email.template', 'Template'),
'is_template_template': fields.function(
_get_is_template_template, type='boolean',
string='Is a template template'),
}
def get_email_template(self, cr, uid, template_id=False, record_id=None,
context=None):
this = super(email_template, self).get_email_template(
cr, uid, template_id, record_id, context)
if this.email_template_id and not this.is_template_template:
for field in ['body_html', 'body_text']:
if this[field] and this.email_template_id[field]:
this._data[this.id][field] = self.render_template(
cr, uid, this.email_template_id[field],
this.email_template_id.model,
this.id, this._context)
return this

71
email_template_template/view/email_template.xml

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="email_template_form" model="ir.ui.view">
<field name="name">email.template.form</field>
<field name="model">email.template</field>
<field name="inherit_id" ref="email_template.email_template_form" />
<field name="type">form</field>
<field name="arch" type="xml">
<data>
<field name="name" position="after">
<field name="is_template_template" invisible="1" />
<field name="email_template_id" domain="[('email_template_id', '=', False), ('model_id', '=', %(email_template.model_email_template)s)]"
attrs="{'readonly': [('is_template_template','=',True), ('email_template_id','=',False)]}"
context="{'default_model_id': %(email_template.model_email_template)s}"
/>
</field>
<field name="model_id" position="attributes">
<attribute name="attrs">
{'readonly': [('is_template_template','=',True)]}
</attribute>
</field>
<field name="email_from" position="attributes">
<attribute name="required">0</attribute>
<attribute name="attrs">
{'readonly': ['|',('is_template_template','=',True),('model_id', '=', %(email_template.model_email_template)s)]}
</attribute>
</field>
<field name="email_to" position="attributes">
<attribute name="required">0</attribute>
<attribute name="attrs">
{'readonly': ['|',('is_template_template','=',True),('model_id', '=', %(email_template.model_email_template)s)]}
</attribute>
</field>
<field name="email_cc" position="attributes">
<attribute name="attrs">
{'readonly': ['|',('is_template_template','=',True),('model_id', '=', %(email_template.model_email_template)s)]}
</attribute>
</field>
<field name="email_bcc" position="attributes">
<attribute name="attrs">
{'readonly': ['|',('is_template_template','=',True),('model_id', '=', %(email_template.model_email_template)s)]}
</attribute>
</field>
<field name="reply_to" position="attributes">
<attribute name="attrs">
{'readonly': ['|',('is_template_template','=',True),('model_id', '=', %(email_template.model_email_template)s)]}
</attribute>
</field>
<field name="lang" position="attributes">
<attribute name="attrs">
{'readonly': ['|',('is_template_template','=',True),('model_id', '=', %(email_template.model_email_template)s)]}
</attribute>
</field>
<field name="user_signature" position="attributes">
<attribute name="attrs">
{'readonly': ['|',('is_template_template','=',True),('model_id', '=', %(email_template.model_email_template)s)]}
</attribute>
</field>
<field name="subject" position="attributes">
<attribute name="required">0</attribute>
<attribute name="attrs">
{'readonly': ['|',('is_template_template','=',True),('model_id', '=', %(email_template.model_email_template)s)]}
</attribute>
</field>
</data>
</field>
</record>
</data>
</openerp>

1
fetchmail_attach_from_folder/__openerp__.py

@ -37,6 +37,7 @@
'data': [ 'data': [
'view/fetchmail_server.xml', 'view/fetchmail_server.xml',
'wizard/attach_mail_manually.xml', 'wizard/attach_mail_manually.xml',
'security/ir.model.access.csv',
], ],
'js': [], 'js': [],
'installable': True, 'installable': True,

2
fetchmail_attach_from_folder/model/fetchmail_server.py

@ -241,8 +241,6 @@ class fetchmail_server(Model):
raise except_orm( raise except_orm(
_('Error'), _('Mailbox %s not found!') % _('Error'), _('Mailbox %s not found!') %
folder.path) folder.path)
folder.get_algorithm().search_matches(
cr, uid, folder, browse_null(), '')
connection.close() connection.close()
this.write({'state': 'done'}) this.write({'state': 'done'})

2
fetchmail_attach_from_folder/security/ir.model.access.csv

@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_model_fetchmail_server_folder,fetchmail.server.folder,model_fetchmail_server_folder,base.group_system,1,1,1,1

22
unserialize_field/__init__.py

@ -0,0 +1,22 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2013 Therp BV (<http://therp.nl>)
# All Rights Reserved
#
# 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/>.
#
##############################################################################
import ir_model_fields

46
unserialize_field/__openerp__.py

@ -0,0 +1,46 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2013 Therp BV (<http://therp.nl>)
# All Rights Reserved
#
# 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': 'Make database fields from fields that live in serialized fields',
'version': '1.0',
'description': """
Sparse, or serialized fields do not live as a column in the database table.
Instead, their values are stored in JSON arrays in a separate field. As a
result, these fields cannot be searched or sorted by.
If such a sparse field is created as 'manual', this module can unserialize
the field. Its field definition and values will then be migrated to a
proper database column. A real life use case where you encounter many
of such fields is the Magento-OpenERP connector.
For technical reasons, many2many and one2many fields are not supported.
""",
'author': 'Therp BV',
'website': 'http://www.therp.nl',
'version': '1.0',
"category": "Tools",
"depends": ['base'],
"data": ['ir_model_fields.xml'],
'installable': True,
'active': False,
}

115
unserialize_field/ir_model_fields.py

@ -0,0 +1,115 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2013 Therp BV (<http://therp.nl>)
# All Rights Reserved
#
# 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/>.
#
##############################################################################
from openerp.osv import orm
from openerp.tools.translate import _
class ir_model_fields(orm.Model):
_inherit = 'ir.model.fields'
def action_unserialize_field(self, cr, uid, ids, context=None):
step = 1000
offset = 0
# Prevent _auto_init to commit the transaction
# before the data is migrated safely
commit_org = cr.commit
cr.commit = lambda *args: None
try:
for this in self.browse(cr, uid, ids, context=context):
pool_obj = self.pool.get(this.model_id.model)
self.create_database_column(cr, uid, pool_obj, this.name,
context=context)
while True:
ids = pool_obj.search(
cr, uid,
[(this.serialization_field_id.name, '!=', '{}')],
offset=offset*step, limit=step, context=context)
if not ids:
break
for data in pool_obj.read(cr, uid, ids,
[this.serialization_field_id.name],
context=context):
self.unserialize_field(cr, uid, pool_obj, data,
this.serialization_field_id.name,
this.name, context=context)
offset += 1
finally:
cr.commit = commit_org
return True
def create_database_column(self, cr, uid, pool_obj, field_name,
context=None):
old = pool_obj._columns[field_name]
if not old.manual:
raise orm.except_orm(
_('Error'),
_('This operation can only be performed on manual fields'))
if old._type == 'many2many':
# Cross table name length of manually created many2many
# fields can easily become too large. Although it would
# probably work if the table name length was within bounds,
# this scenario has not been tested because of this limitation.
raise orm.except_orm(
_("Error"),
_("Many2many fields are not supported. See "
"https://bugs.launchpad.net/openobject-server/+bug/1174078 "
"for more information"))
if old._type == 'one2many':
# How to get a safe field name for the relation field
# on the target model?
raise orm.except_orm(
_("Error"),
_("One2many fields are not handled yet"))
# ORM prohibits to change the 'storing system' of the field
cr.execute("""
UPDATE ir_model_fields
SET serialization_field_id = NULL
WHERE name = %s and model = %s
""", (field_name, pool_obj._name))
del pool_obj._columns[field_name]
pool_obj.__init__(self.pool, cr)
pool_obj._auto_init(cr, {'update_custom_fields': True})
def unserialize_field(self, cr, uid, pool_obj, read_record,
serialization_field_name, field_name,
context=None):
serialized_values = read_record[serialization_field_name]
if not field_name in serialized_values:
return False
value = serialized_values.pop(field_name)
if pool_obj._columns[field_name]._type in ('many2many', 'one2many'):
value = [(6, 0, value)]
return pool_obj.write(
cr, uid, read_record['id'],
{
field_name: value,
serialization_field_name: serialized_values,
},
context=context)

36
unserialize_field/ir_model_fields.xml

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_model_fields_form" model="ir.ui.view">
<field name="type">form</field>
<field name="model">ir.model.fields</field>
<field name="inherit_id" ref="base.view_model_fields_form" />
<field name="arch" type="xml">
<data>
<field name="serialization_field_id" position="after">
<button type="object" name="action_unserialize_field"
string="Unserialize field" colspan="4"
attrs="{'invisible': ['|', ('serialization_field_id','=',False), ('state', '!=', 'manual')]}"
/>
</field>
</data>
</field>
</record>
<record id="view_model_form" model="ir.ui.view">
<field name="type">form</field>
<field name="model">ir.model</field>
<field name="inherit_id" ref="base.view_model_form" />
<field name="arch" type="xml">
<data>
<field name="serialization_field_id" position="after">
<button type="object" name="action_unserialize_field"
string="Unserialize field" colspan="4"
attrs="{'invisible': ['|', ('serialization_field_id','=',False), ('state', '!=', 'manual')]}"
/>
</field>
</data>
</field>
</record>
</data>
</openerp>

22
view_groups_id/__init__.py

@ -0,0 +1,22 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2013 Therp BV (<http://therp.nl>)
# All Rights Reserved
#
# 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/>.
#
##############################################################################
import model

53
view_groups_id/__openerp__.py

@ -0,0 +1,53 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2013 Therp BV (<http://therp.nl>)
# All Rights Reserved
#
# 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': 'group_ids for ir.ui.view',
'version': '1.0',
'description': """This addon is a backport of OpenERP 7.0's groups_id for
views.
The greatness lies in the fact that with that, you can have specific
inherited views for specific groups, so you can radically change a view
for some groups without having to redefine any of the window actions
involved.
Using it for 6.1 modules instead of fields_view_get hacks and the like
also lowers the effort it takes to port the module in question to 7.0
""",
'author': ['Therp BV', 'OpenERP SA'],
'website': 'http://www.therp.nl',
"category": "Dependency",
"depends": [
'base',
],
'css': [
],
'data': [
'view/ir_ui_view.xml',
],
'js': [
],
'installable': True,
'active': False,
'certificate': '',
}

22
view_groups_id/model/__init__.py

@ -0,0 +1,22 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2013 Therp BV (<http://therp.nl>)
# All Rights Reserved
#
# 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/>.
#
##############################################################################
import ir_ui_view

55
view_groups_id/model/ir_ui_view.py

@ -0,0 +1,55 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2013 Therp BV (<http://therp.nl>)
#
# Code snippets from openobject-server 7.0
# (C) 2004-2012 OpenERP S.A. (<http://openerp.com>)
#
#
# All Rights Reserved
#
# 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/>.
#
##############################################################################
from openerp.osv.orm import Model
from openerp.osv import fields
from openerp import SUPERUSER_ID
class ir_ui_view(Model):
_inherit = 'ir.ui.view'
_columns = {
'groups_id': fields.many2many(
'res.groups', 'ir_ui_view_group_rel', 'view_id', 'group_id',
string='Groups', help="If this field is empty, the view "
"applies to all users. Otherwise, the view applies to the "
"users of those groups only."),
}
def get_inheriting_views_arch(self, cr, uid, view_id, model, context=None):
user_groups = frozenset(self.pool.get('res.users').browse(
cr, SUPERUSER_ID, uid, context).groups_id)
view_ids = [v[1] for v in
super(ir_ui_view, self).get_inheriting_views_arch(
cr, uid, view_id, model, context=context)]
# filter views based on user groups
return [(view.arch, view.id)
for view in self.browse(cr, SUPERUSER_ID, view_ids, context)
if not (view.groups_id and
user_groups.isdisjoint(view.groups_id))]

18
view_groups_id/view/ir_ui_view.xml

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_view_form" model="ir.ui.view">
<field name="model">ir.ui.view</field>
<field name="inherit_id" ref="base.view_view_form" />
<field name="arch" type="xml">
<data>
<notebook position="inside">
<page string="Groups">
<field name="groups_id" nolabel="1" />
</page>
</notebook>
</data>
</field>
</record>
</data>
</openerp>
Loading…
Cancel
Save