238
238
def _check_unicity(self, cr, uid, ids, context=None):
241
for account in self.browse(cr, uid, ids, context=context):
242
bad_ids = self.search(cr, uid, [('category', '=', account.category),('|'),('name', '=ilike', account.name),('code', '=ilike', account.code)])
241
for account in self.read(cr, uid, ids, ['category', 'name', 'code'], context=context):
242
bad_ids = self.search(cr, uid, [('category', '=', account.get('category', '')), ('|'), ('name', '=ilike', account.get('name', '')), ('code', '=ilike', account.get('code', ''))])
243
243
if len(bad_ids) and len(bad_ids) > 1:
385
385
default = default.copy()
386
name = '%s(copy)' % account['name'] or ''
386
387
default['code'] = (account['code'] or '') + '(copy)'
387
default['name'] = (account['name'] or '') + '(copy)'
388
default['name'] = name
388
389
default['tuple_destination_summary'] = []
389
390
# code is deleted in copy method in addons
390
391
new_id = super(analytic_account, self).copy(cr, uid, a_id, default, context=context)
391
self.write(cr, uid, new_id, {'code': '%s(copy)' % (account['code'] or '')})
392
# UFTP-83: Add name + context (very important) in order the translation to not display wrong element. This is because context is missing (wrong language)
393
self.write(cr, uid, new_id, {'name': name,'code': '%s(copy)' % (account['code'] or '')}, context=context)
394
trans_obj = self.pool.get('ir.translation')
395
trans_ids = trans_obj.search(cr, uid, [('name', '=', 'account.analytic.account,name'), ('res_id', '=', new_id)])
396
trans_obj.unlink(cr, uid, trans_ids)
394
399
def create(self, cr, uid, vals, context=None):
404
409
Some verifications before analytic account write
411
if isinstance(ids, (int, long)):
406
413
self._check_date(vals, context=context)
407
414
self.set_funding_pool_parent(cr, uid, vals)
408
return super(analytic_account, self).write(cr, uid, ids, vals, context=context)
415
# UFTP-83: Error after duplication, the _constraints is not called with right params. So the _check_unicity gets wrong.
416
if vals.get('name', False):
417
cr.execute('UPDATE account_analytic_account SET name = %s WHERE id IN %s', (vals.get('name'), tuple(ids)))
418
res = super(analytic_account, self).write(cr, uid, ids, vals, context=context)
419
# UFTP-83: Use name as SRC value for translations (to be done after WRITE())
420
if vals.get('name', False):
421
trans_obj = self.pool.get('ir.translation')
422
trans_ids = trans_obj.search(cr, uid, [('name', '=', 'account.analytic.account,name'), ('res_id', 'in', ids)])
424
cr.execute('UPDATE ir_translation SET src = %s WHERE id IN %s', (vals.get('name'), tuple(trans_ids)))
410
427
def unlink(self, cr, uid, ids, context=None):