Let default value of copy converted for the type of field
The default value of copy is expected to be the same format as for the default methods. So the value for xxx2Many fields must be converted. issue6818 review37751002
This commit is contained in:
1 parent
3446e5c2c0
commit
a17386e970
2 files changed
+36
-1
No files matched your search
@@ -285,7 +285,7 @@ class ModelStorage(Model):
|
||||
|
||||
if field_name in default:
|
||||
data[field_name] = default[field_name]
|
||||
elif (isinstance(cls._fields[field_name], fields.Function)
|
||||
if (isinstance(cls._fields[field_name], fields.Function)
|
||||
and not isinstance(
|
||||
cls._fields[field_name], fields.MultiValue)):
|
||||
del data[field_name]
|
||||
|
||||
@@ -44,6 +44,24 @@ class CopyTestCase(unittest.TestCase):
|
||||
self.assertEqual([x.name for x in one2many.one2many],
|
||||
[x.name for x in one2many_copy.one2many])
|
||||
|
||||
@with_transaction()
|
||||
def test_one2many_default(self):
|
||||
"Test copy one2many with default"
|
||||
pool = Pool()
|
||||
One2many = pool.get('test.copy.one2many')
|
||||
Target = pool.get('test.copy.one2many.target')
|
||||
|
||||
record = One2many(name="Test")
|
||||
record.save()
|
||||
target = Target(name="Target")
|
||||
target.save()
|
||||
|
||||
record_copy, = One2many.copy(
|
||||
[record], default={'one2many': [target.id]})
|
||||
|
||||
self.assertListEqual(
|
||||
[x.name for x in record_copy.one2many], [target.name])
|
||||
|
||||
@with_transaction()
|
||||
def test_many2many(self):
|
||||
'Test copy many2many'
|
||||
@@ -74,6 +92,23 @@ class CopyTestCase(unittest.TestCase):
|
||||
self.assertEqual([x.name for x in many2many.many2many],
|
||||
[x.name for x in many2many_copy.many2many])
|
||||
|
||||
@with_transaction()
|
||||
def test_many2many_default(self):
|
||||
"Test copy many2many with default"
|
||||
pool = Pool()
|
||||
Many2many = pool.get('test.copy.many2many')
|
||||
Target = pool.get('test.copy.many2many.target')
|
||||
|
||||
record = Many2many(name="Test")
|
||||
record.save()
|
||||
target = Target(name="Target")
|
||||
target.save()
|
||||
|
||||
record_copy, = Many2many.copy(
|
||||
[record], default={'many2many': [target.id]})
|
||||
|
||||
self.assertSequenceEqual(record_copy.many2many, [target])
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromTestCase(CopyTestCase)
|
||||
Reference in new issue
Block a user