Browse Source

Add a state on the revision model

pull/208/head
Guewen Baconnier 10 years ago
parent
commit
c6073789f1
  1. 20
      partner_revision/models/res_partner_revision.py
  2. 34
      partner_revision/tests/test_revision_flow.py
  3. 16
      partner_revision/views/res_partner_revision_views.xml

20
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'),
],

34
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')

16
partner_revision/views/res_partner_revision_views.xml

@ -8,6 +8,7 @@
<tree string="Partner Revision">
<field name="partner_id"/>
<field name="date"/>
<field name="state"/>
</tree>
</field>
</record>
@ -17,6 +18,18 @@
<field name="model">res.partner.revision</field>
<field name="arch" type="xml">
<form string="Partner Revision">
<header>
<button name="apply"
string="Apply pending changes" type="object"
class="oe_highlight"
states="draft"/>
<button name="cancel"
string="Reject pending changes" type="object"
class="oe_highlight"
states="draft"/>
<field name="state" widget="statusbar"
statusbar_visible="draft,done"/>
</header>
<sheet string="Partner Revision">
<group>
<field name="partner_id"/>
@ -65,6 +78,8 @@
string="Reject" type="object"
class="oe_highlight"
states="draft"/>
<field name="state" widget="statusbar"
statusbar_visible="draft,done"/>
</header>
<sheet>
<group>
@ -96,7 +111,6 @@
<field name="current_value_reference"/>
<field name="new_value_reference"/>
<field name="state"/>
</group>
</sheet>
</form>

Loading…
Cancel
Save