Skip to content

Commit 725955a

Browse files
committed
[IMP] delete_unused: new option to remove the xmlids
The `delete_unused` is used we want to keep a record that no longer define in the data if it was used. It sometimes happen that its xmlid is reused for another record (which may belong to another model). This new option allow to avoid errors. closes #41 Signed-off-by: Alvaro Fuentes Suarez (afu) <[email protected]>
1 parent 981e94b commit 725955a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/util/records.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,7 @@ def add_ref(ref):
921921

922922
def delete_unused(cr, *xmlids, **kwargs):
923923
deactivate = kwargs.pop("deactivate", False)
924+
keep_xmlids = kwargs.pop("keep_xmlids", True)
924925
if kwargs:
925926
raise TypeError("delete_unused() got an unexpected keyword argument %r" % kwargs.popitem()[0])
926927

@@ -998,6 +999,19 @@ def delete_unused(cr, *xmlids, **kwargs):
998999
if deactivate_ids:
9991000
cr.execute('UPDATE "{}" SET active = false WHERE id IN %s'.format(table), [deactivate_ids])
10001001

1002+
if not keep_xmlids:
1003+
query = """
1004+
WITH xids AS (
1005+
{}
1006+
)
1007+
DELETE
1008+
FROM ir_model_data d
1009+
USING xids x
1010+
WHERE d.module = x.module
1011+
AND d.name = x.name
1012+
"""
1013+
cr.execute(query.format(select_xids))
1014+
10011015
return deleted
10021016

10031017

0 commit comments

Comments
 (0)