Add noupdate boolean on ir.model.data

Don't update translation for records that have noupdate for issue1273
This commit is contained in:
Cédric Krier committed 2009-11-05 14:09:04 +01:00
1 parent ea9622d076
commit 53489ba4e4
3 files changed
+16 -7

No files matched your search

+4
View File
@@ -278,6 +278,7 @@ class ModelData(ModelSQL, ModelView):
date_init = fields.DateTime('Init Date')
values = fields.Text('Values')
inherit = fields.Boolean('Inherit')
noupdate = fields.Boolean('No Update')
def __init__(self):
super(ModelData, self).__init__()
@@ -292,6 +293,9 @@ class ModelData(ModelSQL, ModelView):
def default_inherit(self, cursor, user, context=None):
return False
def default_noupdate(self, cursor, user, context=None):
return False
def get_id(self, cursor, user, module, fs_id):
"""
Return for an fs_id the corresponding db_id.
+9 -6
View File
@@ -383,11 +383,11 @@ class Translation(ModelSQL, ModelView, Cacheable):
model_data_ids = model_data_obj.search(cursor, user, [
('module', '=', module),
], context=context)
fs_id2db_id = {}
fs_id2model_data = {}
for model_data in model_data_obj.browse(cursor, user, model_data_ids,
context=context):
fs_id2db_id.setdefault(model_data.model, {})
fs_id2db_id[model_data.model][model_data.fs_id] = model_data.db_id
fs_id2model_data.setdefault(model_data.model, {})
fs_id2model_data[model_data.model][model_data.fs_id] = model_data
translation_ids = []
reader = csv.reader(datas)
@@ -420,10 +420,13 @@ class Translation(ModelSQL, ModelView, Cacheable):
src = row[3].decode('utf-8')
value = row[4].decode('utf-8')
fuzzy = bool(int(row[5]))
noupdate = False
model = name.split(',')[0]
if model in fs_id2db_id:
res_id = fs_id2db_id[model].get(res_id, res_id)
if model in fs_id2model_data and res_id in fs_id2model_data[model]:
model_data = fs_id2model_data[model][res_id]
res_id = model_data.db_id
noupdate = model_data.noupdate
try:
res_id = int(res_id)
@@ -456,7 +459,7 @@ class Translation(ModelSQL, ModelView, Cacheable):
if translation.value != value \
or translation.fuzzy != fuzzy:
ids2.append(translation.id)
if ids2:
if ids2 and not noupdate:
self.write(cursor, 0, ids2, {
'value': value,
'fuzzy': fuzzy,
+3 -1
View File
@@ -449,7 +449,7 @@ class TrytondXmlHandler(sax.handler.ContentHandler):
self.taghandler.startElement(name, attributes)
elif name == "data":
self.noupdate = attributes.get("noupdate", False)
self.noupdate = bool(int(attributes.get("noupdate", '0')))
elif name == "tryton":
pass
@@ -899,6 +899,7 @@ class TrytondXmlHandler(sax.handler.ContentHandler):
'db_id': inherit_db_ids[table],
'values': str(values),
'inherit': True,
'noupdate': self.noupdate,
})
mdata_id = self.modeldata_obj.create(cursor, user, {
@@ -907,6 +908,7 @@ class TrytondXmlHandler(sax.handler.ContentHandler):
'module': module,
'db_id': db_id,
'values': str(values),
'noupdate': self.noupdate,
})
# update fs2db: