[FIX] models: inherited fields must be copied iff their original field is copied
This fixes a bug introduced by commit f650522bbf
(related fields should not be copied by default). Inherited fields are a
particular case, and given the implementation of copy(), they must be copied if
their original field is copied.
The test on copy() in test_orm has been modified to show the bug.
This commit is contained in:
parent
9d167ea7b3
commit
3a44d84b0f
|
@ -220,17 +220,27 @@ class TestInherits(common.TransactionCase):
|
|||
@mute_logger('openerp.models')
|
||||
def test_copy(self):
|
||||
""" copying a user should automatically copy its partner, too """
|
||||
foo_id = self.user.create(self.cr, UID, {'name': 'Foo', 'login': 'foo', 'password': 'foo'})
|
||||
foo_id = self.user.create(self.cr, UID, {
|
||||
'name': 'Foo',
|
||||
'login': 'foo',
|
||||
'password': 'foo',
|
||||
'supplier': True,
|
||||
})
|
||||
foo_before, = self.user.read(self.cr, UID, [foo_id])
|
||||
del foo_before['__last_update']
|
||||
bar_id = self.user.copy(self.cr, UID, foo_id, {'login': 'bar', 'password': 'bar'})
|
||||
bar_id = self.user.copy(self.cr, UID, foo_id, {
|
||||
'login': 'bar',
|
||||
'password': 'bar',
|
||||
})
|
||||
foo_after, = self.user.read(self.cr, UID, [foo_id])
|
||||
del foo_after['__last_update']
|
||||
|
||||
self.assertEqual(foo_before, foo_after)
|
||||
|
||||
foo, bar = self.user.browse(self.cr, UID, [foo_id, bar_id])
|
||||
self.assertEqual(bar.name, 'Foo (copy)')
|
||||
self.assertEqual(bar.login, 'bar')
|
||||
self.assertEqual(foo.supplier, bar.supplier)
|
||||
self.assertNotEqual(foo.id, bar.id)
|
||||
self.assertNotEqual(foo.partner_id.id, bar.partner_id.id)
|
||||
|
||||
|
|
|
@ -2862,10 +2862,15 @@ class BaseModel(object):
|
|||
for parent_model, parent_field in cls._inherits.iteritems():
|
||||
parent = cls.pool[parent_model]
|
||||
for name, field in parent._fields.iteritems():
|
||||
# inherited fields are implemented as related fields, with the
|
||||
# following specific properties:
|
||||
# - reading inherited fields should not bypass access rights
|
||||
# - copy inherited fields iff their original field is copied
|
||||
fields[name] = field.new(
|
||||
inherited=True,
|
||||
related=(parent_field, name),
|
||||
related_sudo=False,
|
||||
copy=field.copy,
|
||||
)
|
||||
|
||||
# add inherited fields that are not redefined locally
|
||||
|
|
Loading…
Reference in New Issue