Browse Source

Replace Table with smart button

pull/103/head
Sandy Carter 10 years ago
parent
commit
d1c7606b8e
  1. 2
      partner_relations/__openerp__.py
  2. 30
      partner_relations/model/res_partner.py
  3. 113
      partner_relations/view/res_partner.xml
  4. 90
      partner_relations/view/res_partner_relation.xml

2
partner_relations/__openerp__.py

@ -75,8 +75,8 @@ date.""",
],
"data": [
"view/res_partner_relation_all.xml",
'view/res_partner.xml',
'view/res_partner_relation.xml',
'view/res_partner.xml',
'view/res_partner_relation_type.xml',
'view/menu.xml',
'security/ir.model.access.csv',

30
partner_relations/model/res_partner.py

@ -20,15 +20,26 @@
#
##############################################################################
import time
from openerp.osv import orm, fields
from openerp import osv, models, fields, exceptions, api
from openerp.osv.expression import is_leaf, AND, OR, FALSE_LEAF
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT
from openerp.tools.translate import _
class ResPartner(orm.Model):
class ResPartner(models.Model):
_inherit = 'res.partner'
relation_count = fields.Integer(
'Relation Count',
compute="_count_relations"
)
@api.one
@api.depends("relation_ids")
def _count_relations(self):
"""Count the number of relations this partner has for Smart Button"""
self.relation_count = len(self.relation_ids)
def _get_relation_ids_select(self, cr, uid, ids, field_name, arg,
context=None):
'''return the partners' relations as tuple
@ -91,8 +102,7 @@ class ResPartner(orm.Model):
if isinstance(arg, tuple) and arg[0] == name:
if arg[1] not in ['=', '!=', 'like', 'not like', 'ilike',
'not ilike', 'in', 'not in']:
raise orm.except_orm(
_('Error'),
raise exceptions.ValidationError(
_('Unsupported search operand "%s"') % arg[1])
relation_type_selection_ids = []
@ -199,7 +209,7 @@ class ResPartner(orm.Model):
return result
_columns = {
'relation_ids': fields.function(
'relation_ids': osv.fields.function(
lambda self, *args, **kwargs: self._get_relation_ids(
*args, **kwargs),
fnct_inv=_set_relation_ids,
@ -207,33 +217,33 @@ class ResPartner(orm.Model):
string='Relations',
selectable=False,
),
'relation_all_ids': fields.one2many(
'relation_all_ids': osv.fields.one2many(
'res.partner.relation.all', 'this_partner_id',
string='All relations with current partner',
auto_join=True,
selectable=False,
),
'search_relation_id': fields.function(
'search_relation_id': osv.fields.function(
lambda self, cr, uid, ids, *args: dict([
(i, False) for i in ids]),
fnct_search=_search_relation_id,
string='Has relation of type',
type='many2one', obj='res.partner.relation.type.selection'
),
'search_relation_partner_id': fields.function(
'search_relation_partner_id': osv.fields.function(
lambda self, cr, uid, ids, *args: dict([
(i, False) for i in ids]),
fnct_search=_search_related_partner_id,
string='Has relation with',
type='many2one', obj='res.partner'
),
'search_relation_date': fields.function(
'search_relation_date': osv.fields.function(
lambda self, cr, uid, ids, *args: dict([
(i, False) for i in ids]),
fnct_search=_search_relation_date,
string='Relation valid', type='date'
),
'search_relation_partner_category_id': fields.function(
'search_relation_partner_category_id': osv.fields.function(
lambda self, cr, uid, ids, *args: dict([
(i, False) for i in ids]),
fnct_search=_search_related_partner_category_id,

113
partner_relations/view/res_partner.xml

@ -23,103 +23,22 @@
<field name="inherit_id" ref="base.view_partner_form" />
<field name="model">res.partner</field>
<field type="xml" name="arch">
<data>
<xpath expr="//sheet/notebook" position="inside">
<page string="Relations">
<field
name="relation_ids"
context="{
'active_model': 'res.partner',
'active_id': id, 'active_ids': [id],
'active_test': False,
}"
>
<tree
colors="gray:is_relation_expired==True or not active;blue:is_relation_future==True"
>
<field
name="type_selection_id"
required="True"
context="{
'parent_model': 'res.partner',
'parent_id': parent.id,
}"
domain="[
'|',
('contact_type_this', '=', parent.is_company and 'c' or 'p'),
('contact_type_this', '=', False),
('search_partner_category_this', '=', parent.category_id),
]
"
options="{'create': false, 'create_edit': false}"
on_change="on_change_type_selection_id(type_selection_id)"
/>
<field name="type_id" invisible="True" />
<field
name="partner_id_display"
required="True"
attrs="{
'readonly': [('type_selection_id','=',False)],
}"
options="{'create': false, 'create_edit': false}"
/>
<field name="date_start" />
<field name="date_end" />
<field name="active" />
<field
name="is_relation_expired"
invisible="True"
/>
<field
name="is_relation_future"
invisible="True"
/>
</tree>
<form>
<field
name="type_selection_id"
required="True"
context="{
'parent_model': 'res.partner',
'parent_id': parent.id,
}"
domain="[
'|',
('contact_type_this', '=', parent.is_company and 'c' or 'p'),
('contact_type_this', '=', False),
('search_partner_category_this', '=', parent.category_id),
]
"
options="{'create': false, 'create_edit': false}"
on_change="on_change_type_selection_id(type_selection_id)"
/>
<field name="type_id" invisible="True" />
<field
name="partner_id_display"
required="True"
attrs="{
'readonly': [('type_selection_id','=',False)],
}"
options="{'create': false, 'create_edit': false}"
/>
<field name="date_start" />
<field name="date_end" />
<field name="active" />
<field
name="is_relation_expired"
invisible="True"
/>
<field
name="is_relation_future"
invisible="True"
/>
</form>
</field>
</page>
</xpath>
</data>
<xpath expr="//div[@name='buttons']" position="inside">
<button class="oe_inline oe_stat_button"
type="action"
context="{
'search_default_left_partner_id': active_id,
'default_left_partner_id': active_id,
'active_model': 'res.partner',
'active_id': id,
'active_ids': [id],
'active_test': False,
}"
name="%(action_res_partner_relation)d"
icon="fa-users">
<field string="Relations" name="relation_count" widget="statinfo"/>
</button>
</xpath>
</field>
</record>

90
partner_relations/view/res_partner_relation.xml

@ -1,9 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="form_res_partner_relation" model="ir.ui.view">
<field name="model">res.partner.relation</field>
<field type="xml" name="arch">
<form version="7.0" string="Partner relation">
<form string="Partner Relation">
<sheet>
<field name="left_partner_id" />
<field name="type_id" />
@ -12,6 +14,60 @@
</form>
</field>
</record>
<record id="tree_res_partner_relation" model="ir.ui.view">
<field name="model">res.partner.relation</field>
<field name="arch" type="xml">
<tree
string="Partner Relations"
colors="gray:is_relation_expired==True or not active;blue:is_relation_future==True"
editable="bottom"
>
<field
name="left_partner_id"
attrs="{
'readonly': [('type_selection_id','=',False)],
}"
options="{'create': false, 'create_edit': false}"
/>
<field
name="type_selection_id"
requiread="True"
context="{
'parent_model': 'res.partner',
'parent_id': parent.id,
}"
domain="[
'|',
('contact_type_this', '=', parent.is_company and 'c' or 'p'),
('contact_type_this', '=', False),
('search_partner_category_this', '=', parent.category_id),
]"
options="{'create': false, 'create_edit': false}"
on_change="on_change_type_selection_id(type_selection_id)"
/>
<field
name="right_partner_id"
attrs="{
'readonly': [('type_selection_id','=',False)],
}"
options="{'create': false, 'create_edit': false}"
/>
<field name="date_start" />
<field name="date_end" />
<field name="active" />
<field
name="is_relation_expired"
invisible="True"
/>
<field
name="is_relation_future"
invisible="True"
/>
</tree>
</field>
</record>
<record id="action_show_right_relation_partners" model="ir.actions.server">
<field name="sequence" eval="5"/>
<field name="state">code</field>
@ -21,6 +77,7 @@
<field name="condition">True</field>
<field name="name">Show partners</field>
</record>
<record id="action_show_right_relation_partners_value" model="ir.values">
<field name="name">Show partners</field>
<field name="key">action</field>
@ -29,5 +86,36 @@
<field name="value" eval="'ir.actions.server,%d' % ref('partner_relations.action_show_right_relation_partners')" />
</record>
<record id="search_res_partner_relation" model="ir.ui.view">
<field name="model">res.partner.relation</field>
<field name="arch" type="xml">
<search string="Search Relations">
<field name="left_partner_id"/>
<field name="right_partner_id"/>
<field name="type_id"/>
<group expand="0" string="Group By">
<filter string="Source Partner" context="{'group_by':'left_partner_id'}"/>
<filter string="Destination Partner" context="{'group_by':'right_partner_id'}"/>
<filter string="Relationship Type" context="{'group_by':'type_id'}"/>
</group>
</search>
</field>
</record>
<record id="action_res_partner_relation" model="ir.actions.act_window">
<field name="name">Relations</field>
<field name="res_model">res.partner.relation</field>
<field name="view_type">form</field>
<field name="view_mode">tree</field>
<field name="view_id" ref="tree_res_partner_relation"/>
<field name="search_view_id" ref="search_res_partner_relation"/>
<field name="context">{"search_default_left_partner_id": active_id}</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Record and track your partners' relations. Relations may be linked to other partners with a type either directly or inversely.
</p>
</field>
</record>
</data>
</openerp>
Loading…
Cancel
Save