diff --git a/partner_revision/models/res_partner_revision.py b/partner_revision/models/res_partner_revision.py
index 12612284b..08fb8e33c 100644
--- a/partner_revision/models/res_partner_revision.py
+++ b/partner_revision/models/res_partner_revision.py
@@ -38,10 +38,24 @@ class ResPartnerRevision(models.Model):
inverse_name='revision_id',
string='Changes')
date = fields.Datetime(default=fields.Datetime.now)
- # TODO: add a revision state, done when all lines are done or
- # canceled
+ state = fields.Selection(
+ compute='_compute_state',
+ selection=[('draft', 'Pending'),
+ ('done', 'Done')],
+ string='State',
+ store=True,
+ )
note = fields.Text()
+ @api.one
+ @api.depends('change_ids', 'change_ids.state')
+ def _compute_state(self):
+ if all(change.state in ('done', 'cancel') for change
+ in self.mapped('change_ids')):
+ self.state = 'done'
+ else:
+ self.state = 'draft'
+
@api.multi
def apply(self):
self.mapped('change_ids').apply()
@@ -146,7 +160,7 @@ class ResPartnerRevisionChange(models.Model):
selection='_reference_models')
state = fields.Selection(
- selection=[('draft', 'Waiting'),
+ selection=[('draft', 'Pending'),
('done', 'Accepted'),
('cancel', 'Refused'),
],
diff --git a/partner_revision/tests/test_revision_flow.py b/partner_revision/tests/test_revision_flow.py
index b56c370fb..c3d6d209c 100644
--- a/partner_revision/tests/test_revision_flow.py
+++ b/partner_revision/tests/test_revision_flow.py
@@ -71,7 +71,11 @@ class TestRevisionFlow(RevisionMixin, common.TransactionCase):
})
def test_new_revision(self):
- """ Add a new revision on a partner """
+ """ Add a new revision on a partner
+
+ A new revision is created when we write on a partner with
+ ``__revision_rules`` in the context.
+ """
self.partner.with_context(__revision_rules=True).write({
'name': 'Y',
'street': 'street Y',
@@ -181,3 +185,31 @@ class TestRevisionFlow(RevisionMixin, common.TransactionCase):
self.assertEqual(self.partner.name, 'Y')
self.assertEqual(self.partner.street, 'street Y')
self.assertEqual(self.partner.street2, 'street2 Y')
+
+ def test_revision_state_on_done(self):
+ """ Check that revision state becomes done when changes are done """
+ changes = [(self.field_name, 'Y', 'draft')]
+ revision = self._create_revision(self.partner, changes)
+ self.assertEqual(revision.state, 'draft')
+ revision.change_ids.apply()
+ self.assertEqual(revision.state, 'done')
+
+ def test_revision_state_on_cancel(self):
+ """ Check that rev. state becomes done when changes are canceled """
+ changes = [(self.field_name, 'Y', 'draft')]
+ revision = self._create_revision(self.partner, changes)
+ self.assertEqual(revision.state, 'draft')
+ revision.change_ids.cancel()
+ self.assertEqual(revision.state, 'done')
+
+ def test_revision_state(self):
+ """ Check that revision state becomes done with multiple changes """
+ changes = [
+ (self.field_name, 'Y', 'draft'),
+ (self.field_street, 'street Y', 'draft'),
+ (self.field_street2, 'street2 Y', 'draft'),
+ ]
+ revision = self._create_revision(self.partner, changes)
+ self.assertEqual(revision.state, 'draft')
+ revision.apply()
+ self.assertEqual(revision.state, 'done')
diff --git a/partner_revision/views/res_partner_revision_views.xml b/partner_revision/views/res_partner_revision_views.xml
index 8d44348e0..c178077e0 100644
--- a/partner_revision/views/res_partner_revision_views.xml
+++ b/partner_revision/views/res_partner_revision_views.xml
@@ -8,6 +8,7 @@
+
@@ -17,6 +18,18 @@
res.partner.revision