allow the translation of the constraints

bzr revid: christophe@tinyerp.com-20080715134226-c6ncgg2xrwnbce5c
This commit is contained in:
Christophe Simonis 2008-07-15 15:42:26 +02:00
parent 207a34b367
commit d309f8fee5
3 changed files with 18 additions and 11 deletions

View File

@ -43,6 +43,7 @@ TRANSLATION_TYPE = [
('xsl', 'XSL'),
('help', 'Help'),
('code', 'Code'),
('constraint', 'Constraint'),
]
class ir_translation(osv.osv, Cacheable):

View File

@ -625,14 +625,17 @@ class orm_template(object):
def read(self, cr, user, ids, fields=None, context=None, load='_classic_read'):
raise _('The read method is not implemented on this object !')
def _validate(self, cr, uid, ids):
def _validate(self, cr, uid, ids, context=None):
context = context or {}
lng = context.get('lang', False) or 'en_US'
trans = self.pool.get('ir.translation')
field_error = []
field_err_str = []
for field in self._constraints:
if not field[0](self, cr, uid, ids):
if len(field)>1:
field_error+=field[2]
field_err_str.append(field[1])
for constraint in self._constraints:
fun, msg, fields = constraint
if not fun(self, cr, uid, ids):
field_error += fields
field_err_str.append( trans._get_source(cr, uid, self._name, 'constraint', lng, source=msg) )
if len(field_err_str):
cr.rollback()
raise except_orm('ValidateError', ('\n'.join(field_err_str), ','.join(field_error)))
@ -1141,7 +1144,7 @@ class orm_memory(orm_template):
self.datas[id_new]['internal.date_access'] = time.time()
for field in upd_todo:
self._columns[field].set_memory(cr, self, id_new, field, vals[field], user, context)
self._validate(cr, user, [id_new])
self._validate(cr, user, [id_new], context)
wf_service = netsvc.LocalService("workflow")
wf_service.trg_write(user, self._name, id_new, cr)
self.clear()
@ -1167,7 +1170,7 @@ class orm_memory(orm_template):
self.datas[id_new]['internal.date_access'] = time.time()
for field in upd_todo:
self._columns[field].set_memory(cr, self, id_new, field, vals[field], user, context)
self._validate(cr, user, [id_new])
self._validate(cr, user, [id_new], context)
wf_service = netsvc.LocalService("workflow")
wf_service.trg_create(user, self._name, id_new, cr)
self.clear()
@ -2010,7 +2013,7 @@ class orm(orm_template):
v[val]=vals[val]
self.pool.get(table).write(cr, user, nids, v, context)
self._validate(cr, user, ids)
self._validate(cr, user, ids, context)
if context.has_key('read_delta'):
del context['read_delta']
@ -2122,7 +2125,7 @@ class orm(orm_template):
for field in upd_todo:
self._columns[field].set(cr, self, id_new, field, vals[field], user, context)
self._validate(cr, user, [id_new])
self._validate(cr, user, [id_new], context)
wf_service = netsvc.LocalService("workflow")
wf_service.trg_create(user, self._name, id_new, cr)

View File

@ -239,7 +239,10 @@ def trans_generate(lang, modules, dbname=None):
if fname:
logger.notifyChannel("init", netsvc.LOG_WARNING, "couldn't export translation for report %s %s %s" % (name, report_type, fname))
for constraint in pool.get(model)._constraints:
msg = constraint[1]
push_translation(module, 'constraint', model, 0, msg.encode('utf8'))
for field_name,field_def in pool.get(model)._columns.items():
if field_def.translate:
name = model + "," + field_name