diff --git a/partner_revision/__openerp__.py b/partner_revision/__openerp__.py
index ceaefe310..0ef423979 100644
--- a/partner_revision/__openerp__.py
+++ b/partner_revision/__openerp__.py
@@ -32,6 +32,7 @@
'views/menu.xml',
'views/res_partner_revision_views.xml',
'views/revision_field_rule_views.xml',
+ 'views/res_partner_views.xml',
],
'test': [],
'installable': True,
diff --git a/partner_revision/models/res_partner.py b/partner_revision/models/res_partner.py
index e428fae5f..83fce66f3 100644
--- a/partner_revision/models/res_partner.py
+++ b/partner_revision/models/res_partner.py
@@ -29,6 +29,18 @@ class ResPartner(models.Model):
inverse_name='partner_id',
string='Revisions',
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
def write(self, values):
@@ -40,3 +52,16 @@ class ResPartner(models.Model):
local_values = revision_model.add_revision(record, values)
super(ResPartner, record).write(local_values)
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)]
diff --git a/partner_revision/views/res_partner_revision_views.xml b/partner_revision/views/res_partner_revision_views.xml
index 3e0e7d247..d4df72cec 100644
--- a/partner_revision/views/res_partner_revision_views.xml
+++ b/partner_revision/views/res_partner_revision_views.xml
@@ -123,6 +123,18 @@
+
+
+
+
+
+
@@ -133,6 +145,7 @@
res.partner.revision
form
tree,form
+ {'search_default_draft': 1}
diff --git a/partner_revision/views/res_partner_views.xml b/partner_revision/views/res_partner_views.xml
new file mode 100644
index 000000000..2fb7441b4
--- /dev/null
+++ b/partner_revision/views/res_partner_views.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+ res.partner.view.buttons
+ res.partner
+
+
+
+
+
+
+
+
+
+
+
+ res.partner.select
+ res.partner
+
+
+
+
+
+
+
+
+
+
+