Skip to content

Commit

Permalink
[FIX] warning create method in batch
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Rogos committed Jul 19, 2023
1 parent 6fd31e0 commit bde9c43
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
15 changes: 8 additions & 7 deletions base_revision/models/base_revision.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,14 @@ def copy_revision_with_context(self):
self.write(self._prepare_revision_data(new_revision))
return new_revision

@api.model
def create(self, values):
rec = super().create(values)
if "unrevisioned_name" not in values:
name_field = self._context.get("revision_name_field", "name")
rec.write({"unrevisioned_name": rec[name_field]})
return rec
@api.model_create_multi
def create(self, vals_list):
records = super().create(vals_list)
name_field = self._context.get("revision_name_field", "name")
for rec, values in zip(records, vals_list):
if "unrevisioned_name" not in values:
rec.write({"unrevisioned_name": rec[name_field]})
return records

def create_revision(self):
revision_ids = []
Expand Down
10 changes: 10 additions & 0 deletions base_revision/tests/test_base_revision.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,13 @@ def test_simple_copy(self):
tester_3 = tester_2.copy({"name": "TEST0002"})
# Check the 'Reference' of the copied tester
self.assertEqual(tester_3.name, tester_3.unrevisioned_name)

def test_create_multiple(self):
"""Check copy process"""
# Create a tester
tester_2 = self.revision_model.create(
[{"name": "TEST0001"}, {"name": "TEST0002"}]
)
# Check the 'Order Reference' of the tester
for tester in tester_2:
self.assertEqual(tester.name, tester.unrevisioned_name)

0 comments on commit bde9c43

Please sign in to comment.