Merge lp:~julie-w/unifield-server/US-5224 into lp:unifield-server

Proposed by jftempo
Status: Merged
Merged at revision: 5231
Proposed branch: lp:~julie-w/unifield-server/US-5224
Merge into: lp:unifield-server
Diff against target: 301 lines (+75/-107)
5 files modified
bin/addons/analytic/analytic.py (+0/-7)
bin/addons/analytic_override/analytic_account.py (+51/-55)
bin/addons/base/ir/ir_translation.py (+17/-12)
bin/addons/msf_instance/add_instance.py (+0/-30)
bin/addons/msf_profile/i18n/fr_MF.po (+7/-3)
To merge this branch: bzr merge lp:~julie-w/unifield-server/US-5224
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+362778@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/addons/analytic/analytic.py'
--- bin/addons/analytic/analytic.py 2018-04-03 10:18:51 +0000
+++ bin/addons/analytic/analytic.py 2019-02-06 10:02:24 +0000
@@ -193,13 +193,6 @@
193 (check_currency, 'Error! The currency has to be the same as the currency of the selected company', ['currency_id', 'company_id']),193 (check_currency, 'Error! The currency has to be the same as the currency of the selected company', ['currency_id', 'company_id']),
194 ]194 ]
195195
196 def copy(self, cr, uid, id, default=None, context=None):
197 if not default:
198 default = {}
199 default['code'] = False
200 default['line_ids'] = []
201 return super(account_analytic_account, self).copy(cr, uid, id, default, context=context)
202
203 def on_change_company(self, cr, uid, id, company_id):196 def on_change_company(self, cr, uid, id, company_id):
204 if not company_id:197 if not company_id:
205 return {}198 return {}
206199
=== modified file 'bin/addons/analytic_override/analytic_account.py'
--- bin/addons/analytic_override/analytic_account.py 2018-04-18 08:17:23 +0000
+++ bin/addons/analytic_override/analytic_account.py 2019-02-06 10:02:24 +0000
@@ -235,14 +235,12 @@
235 'for_fx_gain_loss': lambda *a: False,235 'for_fx_gain_loss': lambda *a: False,
236 }236 }
237237
238 def _check_unicity(self, cr, uid, ids, context=None):238 def _check_code_unicity(self, cr, uid, ids, context=None):
239 if not context:239 if not context:
240 context = {}240 context = {}
241 for account in self.read(cr, uid, ids, ['category', 'name', 'code'], context=context):241 for account in self.read(cr, uid, ids, ['category', 'code'], context=context):
242 bad_ids = self.search(cr, uid,242 bad_ids = self.search(cr, uid,
243 [('category', '=', account.get('category', '')),243 [('category', '=', account.get('category', '')),
244 ('|'),
245 ('name', '=ilike', account.get('name', '')),
246 ('code', '=ilike', account.get('code', ''))],244 ('code', '=ilike', account.get('code', ''))],
247 order='NO_ORDER', limit=2)245 order='NO_ORDER', limit=2)
248 if len(bad_ids) and len(bad_ids) > 1:246 if len(bad_ids) and len(bad_ids) > 1:
@@ -291,7 +289,7 @@
291 return True289 return True
292290
293 _constraints = [291 _constraints = [
294 (_check_unicity, 'You cannot have the same code or name between analytic accounts in the same category!', ['code', 'name', 'category']),292 (_check_code_unicity, 'You cannot have the same code between analytic accounts in the same category!', ['code', 'category']),
295 (_check_gain_loss_account_unicity, 'You can only have one account used for FX gain/loss!', ['for_fx_gain_loss']),293 (_check_gain_loss_account_unicity, 'You can only have one account used for FX gain/loss!', ['for_fx_gain_loss']),
296 (_check_gain_loss_account_type, 'You have to use a Normal account type and Cost Center category for FX gain/loss!', ['for_fx_gain_loss']),294 (_check_gain_loss_account_type, 'You have to use a Normal account type and Cost Center category for FX gain/loss!', ['for_fx_gain_loss']),
297 (_check_default_destination, "You can't delete an account which has this destination as default", []),295 (_check_default_destination, "You can't delete an account which has this destination as default", []),
@@ -390,37 +388,62 @@
390 # validate that activation date388 # validate that activation date
391 raise osv.except_osv(_('Warning !'), _('Activation date must be lower than inactivation date!'))389 raise osv.except_osv(_('Warning !'), _('Activation date must be lower than inactivation date!'))
392390
391 def copy_translations(self, cr, uid, old_id, new_id, context=None):
392 """
393 Don't copy translations when duplicating an analytic account, i.e. we will have "name (copy)" in all languages
394 """
395 return True
396
393 def copy(self, cr, uid, a_id, default=None, context=None, done_list=[], local=False):397 def copy(self, cr, uid, a_id, default=None, context=None, done_list=[], local=False):
398 if context is None:
399 context = {}
394 account = self.browse(cr, uid, a_id, context=context)400 account = self.browse(cr, uid, a_id, context=context)
395 if not default:401 if not default:
396 default = {}402 default = {}
397 default = default.copy()403 default = default.copy()
398 name = '%s(copy)' % account['name'] or ''404 name = '%s(copy)' % account['name'] or ''
399 default['code'] = (account['code'] or '') + '(copy)'405 code = '%s(copy)' % account['code'] or ''
400 default['name'] = name406 default['name'] = name
407 default['code'] = code
401 default['child_ids'] = [] # do not copy the child_ids408 default['child_ids'] = [] # do not copy the child_ids
402 default['tuple_destination_summary'] = []409 default['tuple_destination_summary'] = []
403 # code is deleted in copy method in addons410 default['line_ids'] = []
404 new_id = super(analytic_account, self).copy(cr, uid, a_id, default, context=context)411 return super(analytic_account, self).copy(cr, uid, a_id, default, context=context)
405 # UFTP-83: Add name + context (very important) in order the translation to not display wrong element. This is because context is missing (wrong language)412
406 self.write(cr, uid, new_id, {'name': name,'code': '%s(copy)' % (account['code'] or '')}, context=context)413 def _check_name_unicity(self, cr, uid, ids, context=None):
407 trans_obj = self.pool.get('ir.translation')414 """
408 trans_ids = trans_obj.search(cr, uid, [('name', '=',415 Raises an error if the name chosen is already used by an analytic account of the same category
409 'account.analytic.account,name'), ('res_id', '=', new_id),],416 """
410 order='NO_ORDER')417 if context is None:
411 trans_obj.unlink(cr, uid, trans_ids)418 context = {}
412 return new_id419 # no check at sync time (note that there may be some accounts with duplicated names created before US-5224)
420 if not context.get('sync_update_execution', False):
421 if isinstance(ids, (int, long)):
422 ids = [ids]
423 for analytic_acc in self.read(cr, uid, ids, ['category', 'name'], context=context):
424 dom = [('category', '=', analytic_acc.get('category', '')),
425 ('name', '=ilike', analytic_acc.get('name', '')),
426 ('id', '!=', analytic_acc.get('id'))]
427 if self.search_exist(cr, uid, dom, context=context):
428 ir_trans = self.pool.get('ir.translation')
429 trans_ids = ir_trans.search(cr, uid, [('res_id', 'in', ids), ('name', '=', 'account.analytic.account,name')], context=context)
430 if trans_ids:
431 ir_trans.clear_transid(cr, uid, trans_ids, context=context)
432 raise osv.except_osv(_('Warning !'), _('You cannot have the same name between analytic accounts in the same category!'))
433 return True
413434
414 def create(self, cr, uid, vals, context=None):435 def create(self, cr, uid, vals, context=None):
415 """436 """
416 Some verifications before analytic account creation437 Some verifications before analytic account creation
417 """438 """
439 if context is None:
440 context = {}
441 # Check that instance_id is filled in for FP
442 if context.get('from_web', False) or context.get('from_import_menu', False):
443 self.check_fp(cr, uid, vals, to_update=True, context=context)
418 self._check_date(vals)444 self._check_date(vals)
419 self.set_funding_pool_parent(cr, uid, vals)445 self.set_funding_pool_parent(cr, uid, vals)
420 vals = self.remove_inappropriate_links(vals, context=context)446 vals = self.remove_inappropriate_links(vals, context=context)
421 if context is None:
422 context = {}
423
424 # for auto instance creation, fx gain has been stored, need HQ sync + instance sync to get CC447 # for auto instance creation, fx gain has been stored, need HQ sync + instance sync to get CC
425 if context.get('sync_update_execution') and vals.get('code') and vals.get('category') == 'OC':448 if context.get('sync_update_execution') and vals.get('code') and vals.get('category') == 'OC':
426 param = self.pool.get('ir.config_parameter')449 param = self.pool.get('ir.config_parameter')
@@ -428,7 +451,9 @@
428 if init_cc_fx_gain and vals.get('code') == init_cc_fx_gain:451 if init_cc_fx_gain and vals.get('code') == init_cc_fx_gain:
429 vals['for_fx_gain_loss'] = True452 vals['for_fx_gain_loss'] = True
430 param.set_param(cr, 1, 'INIT_CC_FX_GAIN', '')453 param.set_param(cr, 1, 'INIT_CC_FX_GAIN', '')
431 return super(analytic_account, self).create(cr, uid, vals, context=context)454 ids = super(analytic_account, self).create(cr, uid, vals, context=context)
455 self._check_name_unicity(cr, uid, ids, context=context)
456 return ids
432457
433 def write(self, cr, uid, ids, vals, context=None):458 def write(self, cr, uid, ids, vals, context=None):
434 """459 """
@@ -438,47 +463,18 @@
438 return True463 return True
439 if context is None:464 if context is None:
440 context = {}465 context = {}
466 # US-166: Ids needs to always be a list
441 if isinstance(ids, (int, long)):467 if isinstance(ids, (int, long)):
442 ids = [ids]468 ids = [ids]
443 self._check_date(vals)469 self._check_date(vals)
444 self.set_funding_pool_parent(cr, uid, vals)470 self.set_funding_pool_parent(cr, uid, vals)
445 vals = self.remove_inappropriate_links(vals, context=context)471 vals = self.remove_inappropriate_links(vals, context=context)
446
447 ###### US-113: I have moved the block that sql updates on the name causing the problem of sync (touched not update). The block is now moved to after the write
448
449 # US-399: First read the value from the database, and check if vals contains any of these values, use them for unicity check
450 new_values = self.read(cr, uid, ids, ['category', 'name', 'code'], context=context)[0]
451 if vals.get('name', False):
452 new_values['name'] = vals.get('name')
453 if vals.get('category', False):
454 new_values['category'] = vals.get('category')
455 if vals.get('code', False):
456 new_values['code'] = vals.get('code')
457
458 ######################################################
459 # US-399: Now perform the check unicity manually!
460 bad_ids = self.search(cr, uid,
461 [('category', '=', new_values.get('category', '')),
462 ('|'),
463 ('name', '=ilike', new_values.get('name', '')),
464 ('code', '=ilike', new_values.get('code', ''))],
465 order='NO_ORDER', limit=2)
466 if len(bad_ids) and len(bad_ids) > 1:
467 raise osv.except_osv(_('Warning !'), _('You cannot have the same code or name between analytic accounts in the same category!'))
468 ######################################################
469
470 res = super(analytic_account, self).write(cr, uid, ids, vals, context=context)472 res = super(analytic_account, self).write(cr, uid, ids, vals, context=context)
471 # UFTP-83: Error after duplication, the _constraints is not called with right params. So the _check_unicity gets wrong.473 if context.get('from_web', False) or context.get('from_import_menu', False):
472 if vals.get('name', False):474 cat_instance = self.read(cr, uid, ids, ['category', 'instance_id'], context=context)[0]
473 cr.execute('UPDATE account_analytic_account SET name = %s WHERE id IN %s', (vals.get('name'), tuple(ids)))475 if cat_instance:
474 # UFTP-83: Use name as SRC value for translations (to be done after WRITE())476 self.check_fp(cr, uid, cat_instance, context=context)
475 if vals.get('name', False):477 self._check_name_unicity(cr, uid, ids, context=context)
476 trans_obj = self.pool.get('ir.translation')
477 trans_ids = trans_obj.search(cr, uid, [('name', '=',
478 'account.analytic.account,name'), ('res_id', 'in', ids)],
479 order='NO_ORDER')
480 if trans_ids:
481 cr.execute('UPDATE ir_translation SET src = %s WHERE id IN %s', (vals.get('name'), tuple(trans_ids)))
482 return res478 return res
483479
484 def unlink(self, cr, uid, ids, context=None):480 def unlink(self, cr, uid, ids, context=None):
485481
=== modified file 'bin/addons/base/ir/ir_translation.py'
--- bin/addons/base/ir/ir_translation.py 2018-03-28 08:50:44 +0000
+++ bin/addons/base/ir/ir_translation.py 2019-02-06 10:02:24 +0000
@@ -251,12 +251,7 @@
251251
252 ids = super(ir_translation, self).create(cursor, user, vals, context=context)252 ids = super(ir_translation, self).create(cursor, user, vals, context=context)
253 if clear:253 if clear:
254 for trans_obj in self.read(cursor, user, [ids], ['name','type','res_id','src','lang'], context=context):254 self.clear_transid(cursor, user, ids, context=context)
255 self._get_source.clear_cache(cursor.dbname, user, trans_obj['name'], trans_obj['type'], trans_obj['lang'], source=trans_obj['src'])
256 self._get_ids.clear_cache(cursor.dbname, user, trans_obj['name'], trans_obj['type'], trans_obj['lang'], [trans_obj['res_id']])
257 self._get_ids_dict.clear_cache(cursor.dbname, user,
258 trans_obj['name'], trans_obj['type'],
259 trans_obj['lang'], [trans_obj['res_id']])
260 return ids255 return ids
261256
262 def write(self, cursor, user, ids, vals, clear=True, context=None):257 def write(self, cursor, user, ids, vals, clear=True, context=None):
@@ -287,14 +282,24 @@
287 result = super(ir_translation, self).write(cursor, user, ids, vals, context=context)282 result = super(ir_translation, self).write(cursor, user, ids, vals, context=context)
288283
289 if clear:284 if clear:
290 for trans_obj in self.read(cursor, user, ids, ['name','type','res_id','src','lang'], context=context):285 self.clear_transid(cursor, user, ids, context=context)
291 self._get_source.clear_cache(cursor.dbname, user, trans_obj['name'], trans_obj['type'], trans_obj['lang'], source=trans_obj['src'])
292 self._get_ids.clear_cache(cursor.dbname, user, trans_obj['name'], trans_obj['type'], trans_obj['lang'], [trans_obj['res_id']])
293 self._get_ids_dict.clear_cache(cursor.dbname, user,
294 trans_obj['name'], trans_obj['type'],
295 trans_obj['lang'], [trans_obj['res_id']])
296 return result286 return result
297287
288 def clear_transid(self, cr, uid, ids, context=None):
289 """
290 Clears the translation cache
291 """
292 if context is None:
293 context = {}
294 if isinstance(ids, (int, long)):
295 ids = [ids]
296
297 for trans_obj in self.read(cr, uid, ids, ['name','type','res_id','src','lang'], context=context):
298 self._get_source.clear_cache(cr.dbname, uid, trans_obj['name'], trans_obj['type'], trans_obj['lang'], source=trans_obj['src'])
299 self._get_ids.clear_cache(cr.dbname, uid, trans_obj['name'], trans_obj['type'], trans_obj['lang'], [trans_obj['res_id']])
300 self._get_ids_dict.clear_cache(cr.dbname, uid, trans_obj['name'], trans_obj['type'],trans_obj['lang'], [trans_obj['res_id']])
301 return True
302
298 def unlink(self, cursor, user, ids, clear=True, context=None):303 def unlink(self, cursor, user, ids, clear=True, context=None):
299 if context is None:304 if context is None:
300 context = {}305 context = {}
301306
=== modified file 'bin/addons/msf_instance/add_instance.py'
--- bin/addons/msf_instance/add_instance.py 2018-11-15 17:16:13 +0000
+++ bin/addons/msf_instance/add_instance.py 2019-02-06 10:02:24 +0000
@@ -598,36 +598,6 @@
598 raise osv.except_osv(_('Warning'), _('Funding Pools must have a Coordination Proprietary Instance.'))598 raise osv.except_osv(_('Warning'), _('Funding Pools must have a Coordination Proprietary Instance.'))
599 return True599 return True
600600
601 def create(self, cr, uid, vals, context=None):
602 """
603 Check FPs
604 """
605 if context is None:
606 context = {}
607 # Check that instance_id is filled in for FP
608 if context.get('from_web', False) or context.get('from_import_menu', False):
609 self.check_fp(cr, uid, vals, to_update=True, context=context)
610 return super(account_analytic_account, self).create(cr, uid, vals, context=context)
611
612 def write(self, cr, uid, ids, vals, context=None):
613 """
614 Check FPs
615 """
616 if not ids:
617 return True
618 if context is None:
619 context = {}
620
621 # US-166: Ids needs to be always a list
622 if isinstance(ids, (int, long)):
623 ids = [ids]
624
625 res = super(account_analytic_account, self).write(cr, uid, ids, vals, context=context)
626 if context.get('from_web', False) or context.get('from_import_menu', False):
627 cat_instance = self.read(cr, uid, ids, ['category', 'instance_id'], context=context)[0]
628 if cat_instance:
629 self.check_fp(cr, uid, cat_instance, context=context)
630 return res
631601
632account_analytic_account()602account_analytic_account()
633603
634604
=== modified file 'bin/addons/msf_profile/i18n/fr_MF.po'
--- bin/addons/msf_profile/i18n/fr_MF.po 2019-01-30 13:17:55 +0000
+++ bin/addons/msf_profile/i18n/fr_MF.po 2019-02-06 10:02:24 +0000
@@ -63940,10 +63940,14 @@
63940#: constraint:account.analytic.account:063940#: constraint:account.analytic.account:0
63941#: constraint:account.analytic.account:063941#: constraint:account.analytic.account:0
63942#: constraint:account.analytic.account:063942#: constraint:account.analytic.account:0
63943#: code:addons/analytic_override/analytic_account.py:46763943msgid "You cannot have the same code between analytic accounts in the same category!"
63944msgstr "Vous ne pouvez pas avoir le même code entre des comptes analytiques de même catégorie !"
63945
63946#. module: analytic_override
63947#: code:addons/analytic_override/analytic_account.py:417
63944#, python-format63948#, python-format
63945msgid "You cannot have the same code or name between analytic accounts in the same category!"63949msgid "You cannot have the same name between analytic accounts in the same category!"
63946msgstr "Vous ne pouvez pas avoir le même code ou nom entre des comptes analytiques de même catégorie!"63950msgstr "Vous ne pouvez pas avoir le même nom entre des comptes analytiques de même catégorie !"
6394763951
63948#. module: msf_tools63952#. module: msf_tools
63949#: code:addons/msf_tools/automated_export.py:20063953#: code:addons/msf_tools/automated_export.py:200

Subscribers

People subscribed via source and target branches