Skip to content

Commit f4e0e6e

Browse files
committed
Allowed multiple records for the Model method delete
1 parent ba05077 commit f4e0e6e

File tree

3 files changed

+40
-13
lines changed

3 files changed

+40
-13
lines changed

pyodoo/v12/api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,14 @@ def do_update(self,
238238
return results
239239

240240
def do_delete(self,
241-
entity_id: int,
241+
entity_id: Union[int, list[int]],
242242
options: dict[str, Any]) -> bool:
243243
"""
244-
Delete a record in the requested model
244+
Delete one or multiple records in the requested model
245245
246-
:param entity_id: Object ID to delete
246+
:param entity_id: The Object IDs to delete
247247
:param options: Dictionary with options to use
248-
:return: True if the record was deleted
248+
:return: True if the records were deleted
249249
"""
250250
results = self.do_execute(method_name='unlink',
251251
args=[entity_id],

pyodoo/v12/model.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,14 +362,14 @@ def update(self,
362362
return results
363363

364364
def delete(self,
365-
entity_id: int,
365+
entity_id: Union[int, list[int]],
366366
options: dict[str, Any] = None) -> bool:
367367
"""
368-
Delete a row from a model using its ID
368+
Delete one or multiple rows from a model using the object IDs
369369
370-
:param entity_id: The object ID to delete
370+
:param entity_id: The object IDs to delete
371371
:param options: Dictionary with options to use
372-
:return: True if the record was deleted
372+
:return: True if the records were deleted
373373
"""
374374
if options is None:
375375
options = {}

tests/test_contacts.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,8 @@ def test_32_delete(self) -> None:
633633
self.assertIsNotNone(contacts)
634634
self.assertGreater(len(contacts), 0)
635635
# Delete found data
636-
for entity_id in contacts:
636+
if contacts:
637+
entity_id = contacts[0]
637638
try:
638639
results = self.model.delete(entity_id=entity_id)
639640
self.assertTrue(results)
@@ -650,7 +651,33 @@ def test_32_delete(self) -> None:
650651
# We catched a different error, re-raise it
651652
raise error
652653

653-
def test_33_language(self) -> None:
654+
def test_33_delete_many(self) -> None:
655+
"""
656+
Delete the newly created rows.
657+
This test may be skipped in the case there's an active PoS session
658+
as Odoo doesn't allow contacts deletion when there's some active
659+
PoS session
660+
"""
661+
filters = [Filter(field='name',
662+
compare_type=CompareType.CONTAINS,
663+
value=f'{APP_NAME} v.{APP_VERSION}')]
664+
contacts = self.model.search(filters=filters)
665+
# Check if we have results
666+
self.assertIsNotNone(contacts)
667+
# Delete found data
668+
try:
669+
results = self.model.delete(entity_id=contacts)
670+
self.assertTrue(results)
671+
except xmlrpc.client.Fault as error:
672+
if error.faultCode == 2:
673+
# We have an active PoS session running
674+
# It's not possible to delete contacts until it's closed
675+
pass
676+
else:
677+
# We catched a different error, re-raise it
678+
raise error
679+
680+
def test_34_language(self) -> None:
654681
"""
655682
Get the current default language, change and restore it
656683
"""
@@ -667,15 +694,15 @@ def test_33_language(self) -> None:
667694
results = self.model.language
668695
self.assertEqual(results, original_language)
669696

670-
def test_34_get_fields(self) -> None:
697+
def test_35_get_fields(self) -> None:
671698
"""
672699
Get the model fields
673700
"""
674701
results = self.model.get_fields()
675702
# Check if we have results
676703
self.assertIsNotNone(results)
677704

678-
def test_35_get_fields_attributes(self) -> None:
705+
def test_36_get_fields_attributes(self) -> None:
679706
"""
680707
Get the model fields
681708
"""
@@ -688,7 +715,7 @@ def test_35_get_fields_attributes(self) -> None:
688715
self.assertIn('string', field_name)
689716
self.assertIn('type', field_name)
690717

691-
def test_36_get_model(self) -> None:
718+
def test_37_get_model(self) -> None:
692719
"""
693720
Get a new Model object
694721
"""

0 commit comments

Comments
 (0)