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
1=== modified file 'bin/addons/analytic/analytic.py'
2--- bin/addons/analytic/analytic.py 2018-04-03 10:18:51 +0000
3+++ bin/addons/analytic/analytic.py 2019-02-06 10:02:24 +0000
4@@ -193,13 +193,6 @@
5 (check_currency, 'Error! The currency has to be the same as the currency of the selected company', ['currency_id', 'company_id']),
6 ]
7
8- def copy(self, cr, uid, id, default=None, context=None):
9- if not default:
10- default = {}
11- default['code'] = False
12- default['line_ids'] = []
13- return super(account_analytic_account, self).copy(cr, uid, id, default, context=context)
14-
15 def on_change_company(self, cr, uid, id, company_id):
16 if not company_id:
17 return {}
18
19=== modified file 'bin/addons/analytic_override/analytic_account.py'
20--- bin/addons/analytic_override/analytic_account.py 2018-04-18 08:17:23 +0000
21+++ bin/addons/analytic_override/analytic_account.py 2019-02-06 10:02:24 +0000
22@@ -235,14 +235,12 @@
23 'for_fx_gain_loss': lambda *a: False,
24 }
25
26- def _check_unicity(self, cr, uid, ids, context=None):
27+ def _check_code_unicity(self, cr, uid, ids, context=None):
28 if not context:
29 context = {}
30- for account in self.read(cr, uid, ids, ['category', 'name', 'code'], context=context):
31+ for account in self.read(cr, uid, ids, ['category', 'code'], context=context):
32 bad_ids = self.search(cr, uid,
33 [('category', '=', account.get('category', '')),
34- ('|'),
35- ('name', '=ilike', account.get('name', '')),
36 ('code', '=ilike', account.get('code', ''))],
37 order='NO_ORDER', limit=2)
38 if len(bad_ids) and len(bad_ids) > 1:
39@@ -291,7 +289,7 @@
40 return True
41
42 _constraints = [
43- (_check_unicity, 'You cannot have the same code or name between analytic accounts in the same category!', ['code', 'name', 'category']),
44+ (_check_code_unicity, 'You cannot have the same code between analytic accounts in the same category!', ['code', 'category']),
45 (_check_gain_loss_account_unicity, 'You can only have one account used for FX gain/loss!', ['for_fx_gain_loss']),
46 (_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']),
47 (_check_default_destination, "You can't delete an account which has this destination as default", []),
48@@ -390,37 +388,62 @@
49 # validate that activation date
50 raise osv.except_osv(_('Warning !'), _('Activation date must be lower than inactivation date!'))
51
52+ def copy_translations(self, cr, uid, old_id, new_id, context=None):
53+ """
54+ Don't copy translations when duplicating an analytic account, i.e. we will have "name (copy)" in all languages
55+ """
56+ return True
57+
58 def copy(self, cr, uid, a_id, default=None, context=None, done_list=[], local=False):
59+ if context is None:
60+ context = {}
61 account = self.browse(cr, uid, a_id, context=context)
62 if not default:
63 default = {}
64 default = default.copy()
65 name = '%s(copy)' % account['name'] or ''
66- default['code'] = (account['code'] or '') + '(copy)'
67+ code = '%s(copy)' % account['code'] or ''
68 default['name'] = name
69+ default['code'] = code
70 default['child_ids'] = [] # do not copy the child_ids
71 default['tuple_destination_summary'] = []
72- # code is deleted in copy method in addons
73- new_id = super(analytic_account, self).copy(cr, uid, a_id, default, context=context)
74- # UFTP-83: Add name + context (very important) in order the translation to not display wrong element. This is because context is missing (wrong language)
75- self.write(cr, uid, new_id, {'name': name,'code': '%s(copy)' % (account['code'] or '')}, context=context)
76- trans_obj = self.pool.get('ir.translation')
77- trans_ids = trans_obj.search(cr, uid, [('name', '=',
78- 'account.analytic.account,name'), ('res_id', '=', new_id),],
79- order='NO_ORDER')
80- trans_obj.unlink(cr, uid, trans_ids)
81- return new_id
82+ default['line_ids'] = []
83+ return super(analytic_account, self).copy(cr, uid, a_id, default, context=context)
84+
85+ def _check_name_unicity(self, cr, uid, ids, context=None):
86+ """
87+ Raises an error if the name chosen is already used by an analytic account of the same category
88+ """
89+ if context is None:
90+ context = {}
91+ # no check at sync time (note that there may be some accounts with duplicated names created before US-5224)
92+ if not context.get('sync_update_execution', False):
93+ if isinstance(ids, (int, long)):
94+ ids = [ids]
95+ for analytic_acc in self.read(cr, uid, ids, ['category', 'name'], context=context):
96+ dom = [('category', '=', analytic_acc.get('category', '')),
97+ ('name', '=ilike', analytic_acc.get('name', '')),
98+ ('id', '!=', analytic_acc.get('id'))]
99+ if self.search_exist(cr, uid, dom, context=context):
100+ ir_trans = self.pool.get('ir.translation')
101+ trans_ids = ir_trans.search(cr, uid, [('res_id', 'in', ids), ('name', '=', 'account.analytic.account,name')], context=context)
102+ if trans_ids:
103+ ir_trans.clear_transid(cr, uid, trans_ids, context=context)
104+ raise osv.except_osv(_('Warning !'), _('You cannot have the same name between analytic accounts in the same category!'))
105+ return True
106
107 def create(self, cr, uid, vals, context=None):
108 """
109 Some verifications before analytic account creation
110 """
111+ if context is None:
112+ context = {}
113+ # Check that instance_id is filled in for FP
114+ if context.get('from_web', False) or context.get('from_import_menu', False):
115+ self.check_fp(cr, uid, vals, to_update=True, context=context)
116 self._check_date(vals)
117 self.set_funding_pool_parent(cr, uid, vals)
118 vals = self.remove_inappropriate_links(vals, context=context)
119- if context is None:
120- context = {}
121-
122 # for auto instance creation, fx gain has been stored, need HQ sync + instance sync to get CC
123 if context.get('sync_update_execution') and vals.get('code') and vals.get('category') == 'OC':
124 param = self.pool.get('ir.config_parameter')
125@@ -428,7 +451,9 @@
126 if init_cc_fx_gain and vals.get('code') == init_cc_fx_gain:
127 vals['for_fx_gain_loss'] = True
128 param.set_param(cr, 1, 'INIT_CC_FX_GAIN', '')
129- return super(analytic_account, self).create(cr, uid, vals, context=context)
130+ ids = super(analytic_account, self).create(cr, uid, vals, context=context)
131+ self._check_name_unicity(cr, uid, ids, context=context)
132+ return ids
133
134 def write(self, cr, uid, ids, vals, context=None):
135 """
136@@ -438,47 +463,18 @@
137 return True
138 if context is None:
139 context = {}
140+ # US-166: Ids needs to always be a list
141 if isinstance(ids, (int, long)):
142 ids = [ids]
143 self._check_date(vals)
144 self.set_funding_pool_parent(cr, uid, vals)
145 vals = self.remove_inappropriate_links(vals, context=context)
146-
147- ###### 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
148-
149- # US-399: First read the value from the database, and check if vals contains any of these values, use them for unicity check
150- new_values = self.read(cr, uid, ids, ['category', 'name', 'code'], context=context)[0]
151- if vals.get('name', False):
152- new_values['name'] = vals.get('name')
153- if vals.get('category', False):
154- new_values['category'] = vals.get('category')
155- if vals.get('code', False):
156- new_values['code'] = vals.get('code')
157-
158- ######################################################
159- # US-399: Now perform the check unicity manually!
160- bad_ids = self.search(cr, uid,
161- [('category', '=', new_values.get('category', '')),
162- ('|'),
163- ('name', '=ilike', new_values.get('name', '')),
164- ('code', '=ilike', new_values.get('code', ''))],
165- order='NO_ORDER', limit=2)
166- if len(bad_ids) and len(bad_ids) > 1:
167- raise osv.except_osv(_('Warning !'), _('You cannot have the same code or name between analytic accounts in the same category!'))
168- ######################################################
169-
170 res = super(analytic_account, self).write(cr, uid, ids, vals, context=context)
171- # UFTP-83: Error after duplication, the _constraints is not called with right params. So the _check_unicity gets wrong.
172- if vals.get('name', False):
173- cr.execute('UPDATE account_analytic_account SET name = %s WHERE id IN %s', (vals.get('name'), tuple(ids)))
174- # UFTP-83: Use name as SRC value for translations (to be done after WRITE())
175- if vals.get('name', False):
176- trans_obj = self.pool.get('ir.translation')
177- trans_ids = trans_obj.search(cr, uid, [('name', '=',
178- 'account.analytic.account,name'), ('res_id', 'in', ids)],
179- order='NO_ORDER')
180- if trans_ids:
181- cr.execute('UPDATE ir_translation SET src = %s WHERE id IN %s', (vals.get('name'), tuple(trans_ids)))
182+ if context.get('from_web', False) or context.get('from_import_menu', False):
183+ cat_instance = self.read(cr, uid, ids, ['category', 'instance_id'], context=context)[0]
184+ if cat_instance:
185+ self.check_fp(cr, uid, cat_instance, context=context)
186+ self._check_name_unicity(cr, uid, ids, context=context)
187 return res
188
189 def unlink(self, cr, uid, ids, context=None):
190
191=== modified file 'bin/addons/base/ir/ir_translation.py'
192--- bin/addons/base/ir/ir_translation.py 2018-03-28 08:50:44 +0000
193+++ bin/addons/base/ir/ir_translation.py 2019-02-06 10:02:24 +0000
194@@ -251,12 +251,7 @@
195
196 ids = super(ir_translation, self).create(cursor, user, vals, context=context)
197 if clear:
198- for trans_obj in self.read(cursor, user, [ids], ['name','type','res_id','src','lang'], context=context):
199- self._get_source.clear_cache(cursor.dbname, user, trans_obj['name'], trans_obj['type'], trans_obj['lang'], source=trans_obj['src'])
200- self._get_ids.clear_cache(cursor.dbname, user, trans_obj['name'], trans_obj['type'], trans_obj['lang'], [trans_obj['res_id']])
201- self._get_ids_dict.clear_cache(cursor.dbname, user,
202- trans_obj['name'], trans_obj['type'],
203- trans_obj['lang'], [trans_obj['res_id']])
204+ self.clear_transid(cursor, user, ids, context=context)
205 return ids
206
207 def write(self, cursor, user, ids, vals, clear=True, context=None):
208@@ -287,14 +282,24 @@
209 result = super(ir_translation, self).write(cursor, user, ids, vals, context=context)
210
211 if clear:
212- for trans_obj in self.read(cursor, user, ids, ['name','type','res_id','src','lang'], context=context):
213- self._get_source.clear_cache(cursor.dbname, user, trans_obj['name'], trans_obj['type'], trans_obj['lang'], source=trans_obj['src'])
214- self._get_ids.clear_cache(cursor.dbname, user, trans_obj['name'], trans_obj['type'], trans_obj['lang'], [trans_obj['res_id']])
215- self._get_ids_dict.clear_cache(cursor.dbname, user,
216- trans_obj['name'], trans_obj['type'],
217- trans_obj['lang'], [trans_obj['res_id']])
218+ self.clear_transid(cursor, user, ids, context=context)
219 return result
220
221+ def clear_transid(self, cr, uid, ids, context=None):
222+ """
223+ Clears the translation cache
224+ """
225+ if context is None:
226+ context = {}
227+ if isinstance(ids, (int, long)):
228+ ids = [ids]
229+
230+ for trans_obj in self.read(cr, uid, ids, ['name','type','res_id','src','lang'], context=context):
231+ self._get_source.clear_cache(cr.dbname, uid, trans_obj['name'], trans_obj['type'], trans_obj['lang'], source=trans_obj['src'])
232+ self._get_ids.clear_cache(cr.dbname, uid, trans_obj['name'], trans_obj['type'], trans_obj['lang'], [trans_obj['res_id']])
233+ self._get_ids_dict.clear_cache(cr.dbname, uid, trans_obj['name'], trans_obj['type'],trans_obj['lang'], [trans_obj['res_id']])
234+ return True
235+
236 def unlink(self, cursor, user, ids, clear=True, context=None):
237 if context is None:
238 context = {}
239
240=== modified file 'bin/addons/msf_instance/add_instance.py'
241--- bin/addons/msf_instance/add_instance.py 2018-11-15 17:16:13 +0000
242+++ bin/addons/msf_instance/add_instance.py 2019-02-06 10:02:24 +0000
243@@ -598,36 +598,6 @@
244 raise osv.except_osv(_('Warning'), _('Funding Pools must have a Coordination Proprietary Instance.'))
245 return True
246
247- def create(self, cr, uid, vals, context=None):
248- """
249- Check FPs
250- """
251- if context is None:
252- context = {}
253- # Check that instance_id is filled in for FP
254- if context.get('from_web', False) or context.get('from_import_menu', False):
255- self.check_fp(cr, uid, vals, to_update=True, context=context)
256- return super(account_analytic_account, self).create(cr, uid, vals, context=context)
257-
258- def write(self, cr, uid, ids, vals, context=None):
259- """
260- Check FPs
261- """
262- if not ids:
263- return True
264- if context is None:
265- context = {}
266-
267- # US-166: Ids needs to be always a list
268- if isinstance(ids, (int, long)):
269- ids = [ids]
270-
271- res = super(account_analytic_account, self).write(cr, uid, ids, vals, context=context)
272- if context.get('from_web', False) or context.get('from_import_menu', False):
273- cat_instance = self.read(cr, uid, ids, ['category', 'instance_id'], context=context)[0]
274- if cat_instance:
275- self.check_fp(cr, uid, cat_instance, context=context)
276- return res
277
278 account_analytic_account()
279
280
281=== modified file 'bin/addons/msf_profile/i18n/fr_MF.po'
282--- bin/addons/msf_profile/i18n/fr_MF.po 2019-01-30 13:17:55 +0000
283+++ bin/addons/msf_profile/i18n/fr_MF.po 2019-02-06 10:02:24 +0000
284@@ -63940,10 +63940,14 @@
285 #: constraint:account.analytic.account:0
286 #: constraint:account.analytic.account:0
287 #: constraint:account.analytic.account:0
288-#: code:addons/analytic_override/analytic_account.py:467
289+msgid "You cannot have the same code between analytic accounts in the same category!"
290+msgstr "Vous ne pouvez pas avoir le même code entre des comptes analytiques de même catégorie !"
291+
292+#. module: analytic_override
293+#: code:addons/analytic_override/analytic_account.py:417
294 #, python-format
295-msgid "You cannot have the same code or name between analytic accounts in the same category!"
296-msgstr "Vous ne pouvez pas avoir le même code ou nom entre des comptes analytiques de même catégorie!"
297+msgid "You cannot have the same name between analytic accounts in the same category!"
298+msgstr "Vous ne pouvez pas avoir le même nom entre des comptes analytiques de même catégorie !"
299
300 #. module: msf_tools
301 #: code:addons/msf_tools/automated_export.py:200

Subscribers

People subscribed via source and target branches