Add clean translation wizard
This commit is contained in:
1 parent
7ae9d6b1a0
commit
ced77efcd9
2 files changed
+187
-2
No files matched your search
@@ -13,6 +13,7 @@ import csv
|
||||
from trytond.osv import fields, OSV, Cacheable
|
||||
from trytond.wizard import Wizard, WizardOSV
|
||||
from trytond import tools
|
||||
from trytond import pooler
|
||||
|
||||
TRANSLATION_TYPE = [
|
||||
('field', 'Field'),
|
||||
@@ -619,6 +620,156 @@ class ReportTranslationSet(Wizard):
|
||||
ReportTranslationSet()
|
||||
|
||||
|
||||
class TranslationCleanInit(WizardOSV):
|
||||
'Clean translation init'
|
||||
_name = 'ir.translation.clean.init'
|
||||
_description = __doc__
|
||||
|
||||
TranslationCleanInit()
|
||||
|
||||
|
||||
class TranslationCleanStart(WizardOSV):
|
||||
'Clean translation start'
|
||||
_name = 'ir.translation.clean.start'
|
||||
_description = __doc__
|
||||
|
||||
TranslationCleanStart()
|
||||
|
||||
|
||||
class TranslationClean(Wizard):
|
||||
"Clean translation"
|
||||
_name = 'ir.translation.clean'
|
||||
|
||||
states = {
|
||||
'init': {
|
||||
'actions': [],
|
||||
'result': {
|
||||
'type': 'form',
|
||||
'object': 'ir.translation.clean.init',
|
||||
'state': [
|
||||
('end', 'Cancel', 'tryton-cancel'),
|
||||
('start', 'Start', 'tryton-ok', True),
|
||||
],
|
||||
},
|
||||
},
|
||||
'start': {
|
||||
'actions': ['_clean_translation'],
|
||||
'result': {
|
||||
'type': 'form',
|
||||
'object': 'ir.translation.clean.start',
|
||||
'state': [
|
||||
('end', 'Ok', 'tryton-ok', True),
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
def _clean_translation(self, cursor, user, data, context):
|
||||
translation_obj = self.pool.get('ir.translation')
|
||||
pool_wizard = pooler.get_pool_wizard(cursor.dbname)
|
||||
|
||||
offset = 0
|
||||
limit = cursor.IN_MAX
|
||||
while True:
|
||||
to_delete = []
|
||||
translation_ids = translation_obj.search(cursor, user, [],
|
||||
offset=offset, limit=limit, context=context)
|
||||
if not translation_ids:
|
||||
break
|
||||
offset += limit
|
||||
for translation in translation_obj.browse(cursor, user,
|
||||
translation_ids, context=context):
|
||||
if translation.type == 'field':
|
||||
model_name, field_name = translation.name.split(',', 1)
|
||||
if model_name not in self.pool.object_name_list():
|
||||
to_delete.append(translation.id)
|
||||
continue
|
||||
model_obj = self.pool.get(model_name)
|
||||
if field_name not in model_obj._columns:
|
||||
to_delete.append(translation.id)
|
||||
continue
|
||||
elif translation.type == 'model':
|
||||
model_name, _ = translation.name.split(',', 1)
|
||||
if model_name not in self.pool.object_name_list():
|
||||
to_delete.append(translation.id)
|
||||
continue
|
||||
elif translation.type == 'odt':
|
||||
continue
|
||||
elif translation.type == 'selection':
|
||||
model_name, field_name = translation.name.split(',', 1)
|
||||
if model_name not in self.pool.object_name_list():
|
||||
to_delete.append(translation.id)
|
||||
continue
|
||||
model_obj = self.pool.get(model_name)
|
||||
if field_name not in model_obj._columns:
|
||||
to_delete.append(translation.id)
|
||||
continue
|
||||
field = model_obj._columns[field_name]
|
||||
if not hasattr(field, 'selection') or not field.selection:
|
||||
to_delete.append(translation.id)
|
||||
continue
|
||||
if translation.src not in dict(field.selection).values():
|
||||
to_delete.append(translation.id)
|
||||
continue
|
||||
elif translation.type == 'view':
|
||||
continue
|
||||
elif translation.type == 'wizard_button':
|
||||
wizard_name, state_name, button_name = translation.name.split(',', 2)
|
||||
wizard = pool_wizard.get(wizard_name)
|
||||
if not wizard:
|
||||
to_delete.append(translation.id)
|
||||
continue
|
||||
state = wizard.states.get(state_name)
|
||||
if not state:
|
||||
to_delete.append(translation.id)
|
||||
continue
|
||||
find = False
|
||||
for but in state['result']['state']:
|
||||
if but[0] == button_name:
|
||||
find = True
|
||||
if not find:
|
||||
to_delete.append(translation.id)
|
||||
continue
|
||||
elif translation.type == 'help':
|
||||
model_name, field_name = translation.name.split(',', 1)
|
||||
if model_name not in self.pool.object_name_list():
|
||||
to_delete.append(translation.id)
|
||||
continue
|
||||
model_obj = self.pool.get(model_name)
|
||||
if field_name not in model_obj._columns:
|
||||
to_delete.append(translation.id)
|
||||
continue
|
||||
field = model_obj._columns[field_name]
|
||||
if not field.help:
|
||||
to_delete.append(translation.id)
|
||||
continue
|
||||
elif translation.type == 'error':
|
||||
model_name = translation.name
|
||||
if model_name in (
|
||||
'delete_xml_record',
|
||||
'xml_record_desc',
|
||||
'write_xml_record',
|
||||
'delete_workflow_record',
|
||||
):
|
||||
continue
|
||||
if model_name not in self.pool.object_name_list():
|
||||
to_delete.append(translation.id)
|
||||
continue
|
||||
model_obj = self.pool.get(model_name)
|
||||
errors = model_obj._error_messages.values() + \
|
||||
model_obj._sql_error_messages.values()
|
||||
for _, _, error in model_obj._sql_constraints:
|
||||
errors.append(error)
|
||||
if translation.src not in errors:
|
||||
to_delete.append(translation.id)
|
||||
continue
|
||||
|
||||
translation_obj.delete(cursor, user, to_delete, context=context)
|
||||
return {}
|
||||
|
||||
TranslationClean()
|
||||
|
||||
|
||||
class TranslationUpdateInit(WizardOSV):
|
||||
"Update translation - language"
|
||||
_name = 'ir.translation.update.init'
|
||||
|
||||
@@ -139,6 +139,40 @@
|
||||
id="menu_translation_set_report"
|
||||
sequence="10"/>
|
||||
|
||||
<record model="ir.ui.view" id="act_translation_clean_init_view_form">
|
||||
<field name="model">ir.translation.clean.init</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<form string="Clean Translations">
|
||||
<label string="Clean Translations?"/>
|
||||
</form>
|
||||
]]>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="act_translation_clean_start_view_form">
|
||||
<field name="model">ir.translation.clean.start</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<form string="Clean Translations">
|
||||
<label string="Clean Translations Succeed!"/>
|
||||
</form>
|
||||
]]>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.action.wizard" id="act_translation_clean">
|
||||
<field name="name">Clean Translations</field>
|
||||
<field name="wiz_name">ir.translation.clean</field>
|
||||
</record>
|
||||
<menuitem name="Clean Translations"
|
||||
parent="menu_localization"
|
||||
action="act_translation_clean"
|
||||
id="menu_translation_clean"
|
||||
sequence="20"/>
|
||||
|
||||
<record model="ir.ui.view" id="act_translation_update_init_view_form">
|
||||
<field name="model">ir.translation.update.init</field>
|
||||
<field name="type">form</field>
|
||||
@@ -160,7 +194,7 @@
|
||||
parent="menu_localization"
|
||||
action="act_translation_update"
|
||||
id="menu_translation_update"
|
||||
sequence="20"/>
|
||||
sequence="30"/>
|
||||
|
||||
<record model="ir.ui.view" id="act_translation_export_init_view_form">
|
||||
<field name="model">ir.translation.export.init</field>
|
||||
@@ -198,6 +232,6 @@
|
||||
parent="menu_localization"
|
||||
action="act_translation_export"
|
||||
id="menu_translation_export"
|
||||
sequence="30"/>
|
||||
sequence="40"/>
|
||||
</data>
|
||||
</tryton>
|
||||
Reference in new issue
Block a user