Holger Brunn
11 years ago
7 changed files with 394 additions and 0 deletions
-
21partner_relations_in_tab/__init__.py
-
52partner_relations_in_tab/__openerp__.py
-
22partner_relations_in_tab/model/__init__.py
-
189partner_relations_in_tab/model/res_partner.py
-
90partner_relations_in_tab/model/res_partner_relation_type.py
-
BINpartner_relations_in_tab/static/src/img/icon.png
-
20partner_relations_in_tab/view/res_partner_relation_type.xml
@ -0,0 +1,21 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# OpenERP, Open Source Management Solution |
||||
|
# This module copyright (C) 2014 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 . import model |
@ -0,0 +1,52 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# OpenERP, Open Source Management Solution |
||||
|
# This module copyright (C) 2014 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": "Show partner relations in own tab", |
||||
|
"version": "1.0", |
||||
|
"author": "Therp BV", |
||||
|
"license": "AGPL-3", |
||||
|
"complexity": "normal", |
||||
|
"description": """ |
||||
|
This module adds the possibility to show certain partner relations in its own |
||||
|
tab instead of the list of all relations. This can be useful if certain |
||||
|
relation types are regularly used and should be overseeable at a glace. |
||||
|
""", |
||||
|
"category": "Customer Relationship Management", |
||||
|
"depends": [ |
||||
|
'partner_relations', |
||||
|
'web_compute_domain_x2many', |
||||
|
], |
||||
|
"data": [ |
||||
|
"view/res_partner_relation_type.xml", |
||||
|
], |
||||
|
"js": [ |
||||
|
], |
||||
|
"css": [ |
||||
|
], |
||||
|
"qweb": [ |
||||
|
], |
||||
|
"auto_install": False, |
||||
|
"installable": True, |
||||
|
"application": False, |
||||
|
"external_dependencies": { |
||||
|
'python': [], |
||||
|
}, |
||||
|
} |
@ -0,0 +1,22 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# OpenERP, Open Source Management Solution |
||||
|
# This module copyright (C) 2014 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 . import res_partner_relation_type |
||||
|
from . import res_partner |
@ -0,0 +1,189 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# OpenERP, Open Source Management Solution |
||||
|
# This module copyright (C) 2014 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 lxml import etree |
||||
|
from openerp.osv.orm import Model, transfer_modifiers_to_node |
||||
|
from openerp.osv import expression |
||||
|
from openerp.tools.translate import _ |
||||
|
|
||||
|
|
||||
|
class ResPartner(Model): |
||||
|
_inherit = 'res.partner' |
||||
|
|
||||
|
def _get_relation_ids( |
||||
|
self, cr, uid, ids, dummy_name, dummy_arg, context=None): |
||||
|
if context is None: |
||||
|
context = {} |
||||
|
|
||||
|
#TODO: do a permission test on returned ids |
||||
|
cr.execute( |
||||
|
'''select r.id, left_partner_id, right_partner_id |
||||
|
from res_partner_relation r |
||||
|
join res_partner_relation_type t |
||||
|
on r.type_id = t.id |
||||
|
where ((left_partner_id in %s and own_tab_left=False) |
||||
|
or (right_partner_id in %s and own_tab_right=False))''' + |
||||
|
' order by ' + self.pool['res.partner.relation']._order, |
||||
|
(tuple(ids), tuple(ids)) |
||||
|
) |
||||
|
result = dict([(i, []) for i in ids]) |
||||
|
for row in cr.fetchall(): |
||||
|
if row[1] in result: |
||||
|
result[row[1]].append(row[0]) |
||||
|
if row[2] in result: |
||||
|
result[row[2]].append(row[0]) |
||||
|
return result |
||||
|
|
||||
|
def _create_relation_type_tab( |
||||
|
self, cr, uid, rel_type, inverse, field_names, context=None): |
||||
|
'''Create an xml node containing the relation's tab to be added to the |
||||
|
view. Add the field(s) created on the form to field_names.''' |
||||
|
name = rel_type.name if not inverse else rel_type.name_inverse |
||||
|
contact_type = rel_type['contact_type_' + |
||||
|
('left' if not inverse else 'right')] |
||||
|
partner_category = rel_type['partner_category_' + |
||||
|
('left' if not inverse |
||||
|
else 'right')] |
||||
|
tab = etree.Element('page') |
||||
|
tab.set('string', name) |
||||
|
|
||||
|
invisible = [('id', '=', False)] |
||||
|
if contact_type: |
||||
|
invisible = expression.OR([ |
||||
|
invisible, |
||||
|
[('is_company', '=', contact_type != 'c')]]) |
||||
|
if partner_category: |
||||
|
invisible = expression.OR([ |
||||
|
invisible, |
||||
|
[('category_id', '!=', partner_category.id)]]) |
||||
|
attrs = { |
||||
|
'invisible': invisible, |
||||
|
} |
||||
|
tab.set('attrs', repr(attrs)) |
||||
|
transfer_modifiers_to_node(attrs, tab) |
||||
|
|
||||
|
field_name = 'relation_ids_own_tab_%s_%s' % ( |
||||
|
rel_type.id, |
||||
|
'left' if not inverse else 'right') |
||||
|
field_names.append(field_name) |
||||
|
this_partner_name = '%s_partner_id' % ( |
||||
|
'left' if not inverse else 'right') |
||||
|
other_partner_name = '%s_partner_id' % ( |
||||
|
'left' if inverse else 'right') |
||||
|
|
||||
|
field = etree.Element( |
||||
|
'field', |
||||
|
name=field_name, |
||||
|
context=('{"default_type_id": %s, "default_%s": id, ' |
||||
|
'"active_test": False}') % ( |
||||
|
rel_type.id, |
||||
|
this_partner_name)) |
||||
|
tab.append(field) |
||||
|
tree = etree.Element('tree', editable='bottom') |
||||
|
field.append(tree) |
||||
|
|
||||
|
onchange_type_values = self.pool['res.partner.relation']\ |
||||
|
.on_change_type_selection_id(cr, uid, None, |
||||
|
rel_type.id * 10 + |
||||
|
(1 if inverse else 0), |
||||
|
context=context) |
||||
|
tree.append(etree.Element( |
||||
|
'field', |
||||
|
string=_('Partner'), |
||||
|
domain=repr( |
||||
|
onchange_type_values['domain']['partner_id_display']), |
||||
|
widget='many2one_clickable', |
||||
|
name=other_partner_name)) |
||||
|
tree.append(etree.Element( |
||||
|
'field', |
||||
|
name='date_start')) |
||||
|
tree.append(etree.Element( |
||||
|
'field', |
||||
|
name='date_end')) |
||||
|
tree.append(etree.Element( |
||||
|
'field', |
||||
|
name='active')) |
||||
|
tree.append(etree.Element('field', name='type_id', |
||||
|
invisible='True')) |
||||
|
tree.append(etree.Element('field', name=this_partner_name, |
||||
|
invisible='True')) |
||||
|
return tab |
||||
|
|
||||
|
def _add_relation_type_tab( |
||||
|
self, cr, uid, rel_type, inverse, field_names, relation_tab, |
||||
|
context=None): |
||||
|
'''add the xml node to the view''' |
||||
|
tab = self._create_relation_type_tab( |
||||
|
cr, uid, rel_type, inverse, field_names, context=context) |
||||
|
relation_tab.addnext(tab) |
||||
|
|
||||
|
def fields_view_get(self, cr, uid, view_id=None, view_type='form', |
||||
|
context=None, toolbar=False, submenu=False): |
||||
|
if context is None: |
||||
|
context = {} |
||||
|
result = super(ResPartner, self).fields_view_get( |
||||
|
cr, uid, view_id=view_id, view_type=view_type, context=context, |
||||
|
toolbar=toolbar, submenu=submenu) |
||||
|
if view_type == 'form' and not context.get('check_view_ids'): |
||||
|
res_partner_relation_type = self.pool['res.partner.relation.type'] |
||||
|
own_tab_types = res_partner_relation_type.browse( |
||||
|
cr, uid, |
||||
|
res_partner_relation_type.search( |
||||
|
cr, uid, |
||||
|
[ |
||||
|
'|', |
||||
|
('own_tab_left', '=', True), |
||||
|
('own_tab_right', '=', True) |
||||
|
], |
||||
|
context=context), |
||||
|
context=context) |
||||
|
view = etree.fromstring(result['arch']) |
||||
|
|
||||
|
relation_tab = view.xpath( |
||||
|
'//field[@name="relation_ids"]/ancestor::page') |
||||
|
if not relation_tab: |
||||
|
return result |
||||
|
relation_tab = relation_tab[0] |
||||
|
|
||||
|
field_names = [] |
||||
|
|
||||
|
if not view.xpath('//field[@name="id"]'): |
||||
|
view.append(etree.Element('field', name='id', |
||||
|
invisible='True')) |
||||
|
field_names.append('id') |
||||
|
|
||||
|
for rel_type in own_tab_types: |
||||
|
if rel_type.own_tab_left: |
||||
|
self._add_relation_type_tab( |
||||
|
cr, uid, rel_type, False, field_names, relation_tab, |
||||
|
context=context) |
||||
|
if rel_type.own_tab_right: |
||||
|
self._add_relation_type_tab( |
||||
|
cr, uid, rel_type, True, field_names, relation_tab, |
||||
|
context=context) |
||||
|
|
||||
|
result['arch'], fields = self\ |
||||
|
._BaseModel__view_look_dom_arch( |
||||
|
cr, uid, view, result['view_id'], context=context) |
||||
|
|
||||
|
for field_name in field_names: |
||||
|
result['fields'][field_name] = fields[field_name] |
||||
|
|
||||
|
return result |
@ -0,0 +1,90 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# OpenERP, Open Source Management Solution |
||||
|
# This module copyright (C) 2014 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 |
||||
|
from openerp import SUPERUSER_ID |
||||
|
|
||||
|
|
||||
|
class ResPartnerRelationType(Model): |
||||
|
_inherit = 'res.partner.relation.type' |
||||
|
|
||||
|
_columns = { |
||||
|
'own_tab_left': fields.boolean('Show in own tab'), |
||||
|
'own_tab_right': fields.boolean('Show in own tab'), |
||||
|
} |
||||
|
|
||||
|
_defaults = { |
||||
|
'own_tab_left': False, |
||||
|
'own_tab_right': False, |
||||
|
} |
||||
|
|
||||
|
def _update_res_partner_fields(self, cr): |
||||
|
field_name_prefix = 'relation_ids_own_tab_' |
||||
|
field_name_format = field_name_prefix + '%s_%s' |
||||
|
res_partner = self.pool['res.partner'] |
||||
|
for field_name in res_partner._columns.copy(): |
||||
|
if field_name.startswith(field_name_prefix): |
||||
|
del res_partner._columns[field_name] |
||||
|
|
||||
|
def add_field(relation, inverse): |
||||
|
field = fields.one2many( |
||||
|
'res.partner.relation', |
||||
|
'%s_partner_id' % ('left' if not inverse else 'right'), |
||||
|
string=relation['name' if not inverse else 'name_inverse'], |
||||
|
domain=[('type_id', '=', relation.id), |
||||
|
'|', |
||||
|
('active', '=', True), |
||||
|
('active', '=', False)]) |
||||
|
field_name = field_name_format % ( |
||||
|
relation.id, |
||||
|
'left' if not inverse else 'right') |
||||
|
res_partner._columns[field_name] = field |
||||
|
|
||||
|
for relation in self.browse( |
||||
|
cr, SUPERUSER_ID, |
||||
|
self.search( |
||||
|
cr, SUPERUSER_ID, |
||||
|
[ |
||||
|
'|', |
||||
|
('own_tab_left', '=', True), |
||||
|
('own_tab_right', '=', True), |
||||
|
])): |
||||
|
if relation.own_tab_left: |
||||
|
add_field(relation, False) |
||||
|
if relation.own_tab_right: |
||||
|
add_field(relation, True) |
||||
|
|
||||
|
def _register_hook(self, cr): |
||||
|
self._update_res_partner_fields(cr) |
||||
|
|
||||
|
def create(self, cr, uid, vals, context=None): |
||||
|
result = super(ResPartnerRelationType, self).create( |
||||
|
cr, uid, vals, context=context) |
||||
|
if vals.get('own_tab_left') or vals.get('own_tab_right'): |
||||
|
self._update_res_partner_fields(cr) |
||||
|
return result |
||||
|
|
||||
|
def write(self, cr, uid, ids, vals, context=None): |
||||
|
result = super(ResPartnerRelationType, self).write( |
||||
|
cr, uid, ids, vals, context=context) |
||||
|
if 'own_tab_left' in vals or 'own_tab_right' in vals: |
||||
|
self._update_res_partner_fields(cr) |
||||
|
return result |
After Width: 90 | Height: 90 | Size: 18 KiB |
@ -0,0 +1,20 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<openerp> |
||||
|
<data> |
||||
|
<record id="form_res_partner_relation_type" model="ir.ui.view"> |
||||
|
<field name="model">res.partner.relation.type</field> |
||||
|
<field name="type">form</field> |
||||
|
<field name="inherit_id" ref="partner_relations.form_res_partner_relation_type" /> |
||||
|
<field name="arch" type="xml"> |
||||
|
<data> |
||||
|
<field name="partner_category_left" position="after"> |
||||
|
<field name="own_tab_left" /> |
||||
|
</field> |
||||
|
<field name="partner_category_right" position="after"> |
||||
|
<field name="own_tab_right" /> |
||||
|
</field> |
||||
|
</data> |
||||
|
</field> |
||||
|
</record> |
||||
|
</data> |
||||
|
</openerp> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue