Browse Source

Add stat button and filters on partners

So the revisions are easier to reach than from the menus
pull/208/head
Guewen Baconnier 9 years ago
parent
commit
d7cbc3c265
  1. 1
      partner_revision/__openerp__.py
  2. 25
      partner_revision/models/res_partner.py
  3. 13
      partner_revision/views/res_partner_revision_views.xml
  4. 42
      partner_revision/views/res_partner_views.xml

1
partner_revision/__openerp__.py

@ -32,6 +32,7 @@
'views/menu.xml', 'views/menu.xml',
'views/res_partner_revision_views.xml', 'views/res_partner_revision_views.xml',
'views/revision_field_rule_views.xml', 'views/revision_field_rule_views.xml',
'views/res_partner_views.xml',
], ],
'test': [], 'test': [],
'installable': True, 'installable': True,

25
partner_revision/models/res_partner.py

@ -29,6 +29,18 @@ class ResPartner(models.Model):
inverse_name='partner_id', inverse_name='partner_id',
string='Revisions', string='Revisions',
readonly=True) readonly=True)
count_pending_revisions = fields.Integer(
string='Pending Revisions',
compute='_count_pending_revisions',
search='_search_count_pending_revisions')
@api.one
@api.depends('revision_ids', 'revision_ids.state')
def _count_pending_revisions(self):
revisions = self.revision_ids.filtered(
lambda rev: rev.state == 'draft' and rev.partner_id == self
)
self.count_pending_revisions = len(revisions)
@api.multi @api.multi
def write(self, values): def write(self, values):
@ -40,3 +52,16 @@ class ResPartner(models.Model):
local_values = revision_model.add_revision(record, values) local_values = revision_model.add_revision(record, values)
super(ResPartner, record).write(local_values) super(ResPartner, record).write(local_values)
return True return True
def _search_count_pending_revisions(self, operator, value):
if operator not in ('=', '!=', '<', '<=', '>', '>=', 'in', 'not in'):
return []
query = ("SELECT p.id "
"FROM res_partner p "
"INNER JOIN res_partner_revision r ON r.partner_id = p.id "
"WHERE r.state = 'draft' "
"GROUP BY p.id "
"HAVING COUNT(r.id) %s %%s ") % operator
self.env.cr.execute(query, (value,))
ids = [row[0] for row in self.env.cr.fetchall()]
return [('id', 'in', ids)]

13
partner_revision/views/res_partner_revision_views.xml

@ -123,6 +123,18 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<search string="Partner Revision"> <search string="Partner Revision">
<field name="partner_id"/> <field name="partner_id"/>
<filter string="Pending" name="draft"
domain="[('state','=','draft')]"/>
<filter string="Done" name="done"
domain="[('state','=','done')]"/>
<group expand="0" string="Group By">
<filter string="Partner"
name="groupby_partner_id"
context="{'group_by': 'partner_id'}"/>
<filter string="State"
name="groupby_state"
context="{'group_by': 'state'}"/>
</group>
</search> </search>
</field> </field>
</record> </record>
@ -133,6 +145,7 @@
<field name="res_model">res.partner.revision</field> <field name="res_model">res.partner.revision</field>
<field name="view_type">form</field> <field name="view_type">form</field>
<field name="view_mode">tree,form</field> <field name="view_mode">tree,form</field>
<field name="context">{'search_default_draft': 1}</field>
<field name="search_view_id" ref="view_res_partner_revision_search"/> <field name="search_view_id" ref="view_res_partner_revision_search"/>
</record> </record>

42
partner_revision/views/res_partner_views.xml

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="0">
<record id="res_partner_view_buttons" model="ir.ui.view">
<field name="name">res.partner.view.buttons</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="priority" eval="18"/>
<field name="groups_id" eval="[(4, ref('partner_revision.group_revision_user'))]"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='buttons']" position="inside">
<button class="oe_inline oe_stat_button"
type="action"
name="%(partner_revision.action_res_partner_revision_view)d"
attrs="{'invisible': [('count_pending_revisions', '=', 0)]}"
context="{'search_default_draft': 1, 'search_default_partner_id': active_id}"
icon="fa-code-fork">
<field string="Pending Revisions"
name="count_pending_revisions"
widget="statinfo"/>
</button>
</xpath>
</field>
</record>
<record id="view_res_partner_filter" model="ir.ui.view">
<field name="name">res.partner.select</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_res_partner_filter" />
<field name="arch" type="xml">
<filter name="customer" position="after">
<separator/>
<filter string="Pending Revisions"
name="pending_revisions"
domain="[('count_pending_revisions', '>', 0)]"/>
</filter>
</field>
</record>
</data>
</openerp>
Loading…
Cancel
Save