Browse Source

Do not create a changeset when both sides are empty

But have a different type (e.g. False and '')
pull/208/head
Guewen Baconnier 9 years ago
parent
commit
cdc73214a3
  1. 5
      partner_changeset/models/res_partner_changeset.py
  2. 2
      partner_changeset/tests/test_changeset_field_type.py
  3. 12
      partner_changeset/tests/test_changeset_flow.py

5
partner_changeset/models/res_partner_changeset.py

@ -421,7 +421,10 @@ class ResPartnerChangesetChange(models.Model):
@api.model
def _has_field_changed(self, record, field, value):
field_def = record._fields[field]
return field_def.convert_to_write(record[field]) != value
current_value = field_def.convert_to_write(record[field])
if not (current_value or value):
return False
return current_value != value
@api.multi
def _convert_value_for_write(self, value):

2
partner_changeset/tests/test_changeset_field_type.py

@ -177,7 +177,7 @@ class TestChangesetFieldType(ChangesetMixin, common.TransactionCase):
""" Add a new changeset on a Binary field is not supported """
with self.assertRaises(NotImplementedError):
self.partner.write({
self.field_binary.name: '',
self.field_binary.name: 'xyz',
})
def test_apply_char(self):

12
partner_changeset/tests/test_changeset_flow.py

@ -87,6 +87,18 @@ class TestChangesetFlow(ChangesetMixin, common.TransactionCase):
[(self.field_street, 'street X', False, 'draft')]
)
def test_no_changeset_empty_value_both_sides(self):
""" No changeset created when both sides have an empty value """
# we have to ensure that even if we write '' to a False field, we won't
# write a changeset
self.partner.with_context(__no_changeset=True).write({
'street': False,
})
self.partner.write({
'street': '',
})
self.assertFalse(self.partner.changeset_ids)
def test_apply_change(self):
""" Apply a changeset change on a partner """
changes = [

Loading…
Cancel
Save