Cédric Krier pushed to branch branch/default at Tryton / Tryton
Commits:
e376f832 by Cédric Krier at 2023-02-18T19:05:26+01:00
Clean translations of resources that do not exist anymore
Closes #2796
- - - - -
1 changed file:
- trytond/trytond/ir/translation.py
Changes:
=====================================
trytond/trytond/ir/translation.py
=====================================
@@ -1378,6 +1378,7 @@
ModelData = pool.get('ir.model.data')
to_delete = []
+ records = defaultdict(lambda: defaultdict(set))
keys = set()
translations = Translation.search([])
for translation in translations:
@@ -1391,6 +1392,19 @@
to_delete.append(translation.id)
else:
keys.add(key)
+ if translation.type == 'model' and translation.res_id >= 0:
+ model_name, _ = translation.name.split(',', 1)
+ records[model_name][translation.res_id].add(translation.id)
+
+ with inactive_records():
+ for model_name, translations in records.items():
+ Model = pool.get(model_name)
+ for sub_ids in grouped_slice(translations.keys()):
+ sub_ids = list(sub_ids)
+ records = Model.search([('id', 'in', sub_ids)])
+ for record_id in set(sub_ids) - set(map(int, records)):
+ to_delete.extend(translations[record_id])
+
# skip translation handled in ir.model.data
models_data = ModelData.search([
('db_id', 'in', to_delete),
View it on Heptapod:
https://foss.heptapod.net/tryton/tryton/-/commit/e376f8322e938350c606b62383c6e0134be3c9d5
--
View it on Heptapod:
https://foss.heptapod.net/tryton/tryton/-/commit/e376f8322e938350c606b62383c6e0134be3c9d5
You're receiving this email because of your account on foss.heptapod.net.