Do not import empty One2Many data

issue11308
review388081002
This commit is contained in:
Cédric Krier
2022-04-04 00:11:26 +02:00
parent c126deaab5
commit 60a6d5f390
4 changed files with 78 additions and 0 deletions
+1
View File
@@ -1,3 +1,4 @@
* Do not import empty One2Many data
* Deduplicate entries in domain inversion's simplify
* Prevent to create and delete singleton
* Allow CORS on root path
+1
View File
@@ -1046,6 +1046,7 @@ class ModelStorage(Model):
i += max2
nbrmax = max(nbrmax, i)
row[field] = []
create = [v for v in create if any(v.values())]
if create:
row[field].append(('create', create))
if write:
+27
View File
@@ -117,6 +117,30 @@ class ImportDataOne2ManyTarget(ModelSQL):
one2many = fields.Many2One('test.import_data.one2many', 'One2Many')
class ImportDataOne2Manies(ModelSQL):
"Import Data One2Manies"
__name__ = 'test.import_data.one2manies'
name = fields.Char("Name")
one2many1 = fields.One2Many(
'test.import_data.one2many1.target', 'one2many', "One2Many 1")
one2many2 = fields.One2Many(
'test.import_data.one2many2.target', 'one2many', "One2Many 2")
class ImportDataOne2Many1Target(ModelSQL):
"Import Data One2Many 1 Target"
__name__ = 'test.import_data.one2many1.target'
name = fields.Char("Name")
one2many = fields.Many2One('test.import_data.one2manies', "One2Many")
class ImportDataOne2Many2Target(ModelSQL):
"Import Data One2Many 2 Target"
__name__ = 'test.import_data.one2many2.target'
name = fields.Char("Name")
one2many = fields.Many2One('test.import_data.one2manies', "One2Many")
class ImportDataBinary(ModelSQL):
"Import Data Binary"
__name__ = 'test.import_data.binary'
@@ -163,6 +187,9 @@ def register(module):
ImportDataMany2ManyRelation,
ImportDataOne2Many,
ImportDataOne2ManyTarget,
ImportDataOne2Manies,
ImportDataOne2Many1Target,
ImportDataOne2Many2Target,
ImportDataReferenceSelection,
ImportDataReference,
ImportDataBinary,
+49
View File
@@ -397,6 +397,55 @@ class ImportDataTestCase(unittest.TestCase):
['', 'Test 2'],
['Test 2', 'Test 1']]), 2)
@with_transaction()
def test_many_one2many(self):
"Test many one2many"
pool = Pool()
One2many = pool.get('test.import_data.one2manies')
self.assertEqual(One2many.import_data(
['name', 'one2many1/name', 'one2many2/name'],
[["Test", "Test 1", "Test 2"],
['', '', "Test 3"]]), 1)
record, = One2many.search([])
self.assertEqual(len(record.one2many1), 1)
self.assertEqual(len(record.one2many2), 2)
@with_transaction()
def test_many_one2many_empty_last(self):
"Test many one2many with empty last"
pool = Pool()
One2many = pool.get('test.import_data.one2manies')
self.assertEqual(One2many.import_data(
['name', 'one2many1/name', 'one2many2/name'],
[["Test", "Test 1", "Test 2"],
['', "Test 3", '']]), 1)
record, = One2many.search([])
self.assertEqual(len(record.one2many1), 2)
self.assertEqual(len(record.one2many2), 1)
@with_transaction()
def test_many_one2many_multiple_empty(self):
"Test many one2many with multiple empty"
pool = Pool()
One2many = pool.get('test.import_data.one2manies')
self.assertEqual(One2many.import_data(
['name', 'one2many1/name', 'one2many2/name'],
[["Test", "Test 1", "Test 2"],
['', "Test 3", ''],
['', '', "Test 4"]]), 1)
record, = One2many.search([])
self.assertEqual(len(record.one2many1), 2)
self.assertEqual(len(record.one2many2), 2)
@with_transaction()
def test_reference(self):
'Test reference'