Merge lp:~pedro.baeza/account-financial-tools/7.0-account_chart_update-enhanced into lp:~account-core-editors/account-financial-tools/7.0
- 7.0-account_chart_update-enhanced
- Merge into 7.0
Status: | Merged |
---|---|
Approved by: | Yannick Vaucher @ Camptocamp |
Approved revision: | 170 |
Merged at revision: | 180 |
Proposed branch: | lp:~pedro.baeza/account-financial-tools/7.0-account_chart_update-enhanced |
Merge into: | lp:~account-core-editors/account-financial-tools/7.0 |
Diff against target: |
1736 lines (+461/-413) 3 files modified
account_chart_update/i18n/account_chart_update.pot (+85/-83) account_chart_update/wizard/wizard_chart_update.py (+362/-293) account_chart_update/wizard/wizard_chart_update_view.xml (+14/-37) |
To merge this branch: | bzr merge lp:~pedro.baeza/account-financial-tools/7.0-account_chart_update-enhanced |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Yannick Vaucher @ Camptocamp | code review, no test | Approve | |
PabloCM (community) | usage | Approve | |
Review via email: mp+212074@code.launchpad.net |
Commit message
[FIX] account_
[FIX] account_
[FIX] account_
[FIX] account_
[FIX] account_
[IMP] account_
[IMP] account_
[IMP] account_
[IMP] account_
[IMP] account_
[IMP] account_
Description of the change
This is a lot of improvements and fixes resulted as a test with refactorised l10n_es localization module. Because the diff is very huge, I urge you to just test functionality instead making code review. There is still a lot of v7 conventions that I haven't converted in this code, but I have touched here and there in this way.
This is the list of changes:
- [FIX] Selection of operations to do now is working.
- [FIX] Adapted to work with inherited account chart templates.
- [FIX] Remove required=True for chart_template_id on DB and put on screen to avoid error when removing chart templates.
- [FIX] Change method to compare taxes of fiscal positions to match with the one comparing taxes.
- [FIX] Change method to compare accounts of fiscal positions to match with the one comparing accounts.
- [IMP] Wizard now shows in tree view modification notes.
- [IMP] For new data to be created, it is marked on notes the reason for the creation (just for clarity).
- [IMP] Tabs for operations that are not going to be performed are hidden.
- [IMP] Some PEP8 here and there.
- [IMP] Enhance a little the mapping searches (there's more room to improve).
- [IMP] Now it takes into account name and description for mapping taxes.
Regards.
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote : | # |
Hello thanks,
I see a lot of improvements here.
My remarks:
Why renaming tax_template to tax_templ? Readability counts. And it makes me wish I could auto complete those while reading the code.
It seams strange to me that you removed required=True of chart_template_id
When shouldn't it be required ? Code shouldn't rely on the view code to ensure a field is require.
An empty chart_template_id will raise errors in those methods:
name_get
_map_tax_
_find_tax_codes
_find_accounts
There are some missing context:
l.1332
l.1341
l.1516
l.1646
l.2031
- 168. By Pedro Manuel Baeza
-
Some comments from Yannick's review
Pedro Manuel Baeza (pedro.baeza) wrote : | # |
Hi, Yannick,
Thanks for taking the time to review such a huge change that I have made on the module. I know that there's still a lot to do to comply with all the conventions, but this is a beginning motivated by some requirements not met in it.
I have fixed things you have point about missing contexts.
About tax_template to tax_templ it was to favour PEP8 80 cols restriction, because with that long names was very difficult to fit lines. I think it's still enough readable and I win 3 chars less.
I removed required=True from fill to avoid a strange situation that happens when removing a chart template (a strange user case, but I faced it in one case): if you put this field as required, and you run the wizard, a row is created on the temporary table form the transient model. This table is not clean up until next vacuum. Meanwhile, if you try to remove the chart template that has been selected on the wizard, due to ondelete="cascade" attribute, chart_template_id is emptied on temporary table, but required constraint throws an error, avoiding you to remove this chart template. That's why I have moved required condition to view.
Regards.
Pedro Manuel Baeza (pedro.baeza) wrote : | # |
s/required=True from fill/required=True from wizard
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote : | # |
Ok thanks for the changes.
About the hack for required=true, please add a #FIXME comment if there is no other option. And checking chart_template_id is set in
_map_tax_
_find_tax_codes
_find_accounts
Seams necessary.
To respect PEP8 80 cols I don't feel it is the right way to go. And it creates more diff than necessary. But I won't block it for that.
There are still some issue with PEP8, indentation and length of lines introduced by your changes:
l.1533
l.1903
l.1940
l.2160
l.1351 missing space after comma
- 169. By Pedro Manuel Baeza
-
Last fixes from reviews
- 170. By Pedro Manuel Baeza
-
Translation updated for avoiding conflicts
Pedro Manuel Baeza (pedro.baeza) wrote : | # |
Hi, Yannick, I have updated according your comments, and found that we can avoid to remove required=True putting ondelete="cascade".
Regards.
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote : | # |
Seems fine that way ondelete="cascade" seems also a better choice.
Thanks!
LGTM
Preview Diff
1 | === modified file 'account_chart_update/i18n/account_chart_update.pot' |
2 | --- account_chart_update/i18n/account_chart_update.pot 2013-10-15 14:19:18 +0000 |
3 | +++ account_chart_update/i18n/account_chart_update.pot 2014-05-20 00:05:21 +0000 |
4 | @@ -6,8 +6,8 @@ |
5 | msgstr "" |
6 | "Project-Id-Version: OpenERP Server 7.0\n" |
7 | "Report-Msgid-Bugs-To: \n" |
8 | -"POT-Creation-Date: 2013-10-15 14:01+0000\n" |
9 | -"PO-Revision-Date: 2013-10-15 14:01+0000\n" |
10 | +"POT-Creation-Date: 2014-03-21 00:56+0000\n" |
11 | +"PO-Revision-Date: 2014-03-21 00:56+0000\n" |
12 | "Last-Translator: <>\n" |
13 | "Language-Team: \n" |
14 | "MIME-Version: 1.0\n" |
15 | @@ -26,18 +26,13 @@ |
16 | msgstr "" |
17 | |
18 | #. module: account_chart_update |
19 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:368 |
20 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:382 |
21 | #, python-format |
22 | msgid "The code field is different.\n" |
23 | "" |
24 | msgstr "" |
25 | |
26 | #. module: account_chart_update |
27 | -#: view:wizard.update.charts.accounts:0 |
28 | -msgid "Fiscal position" |
29 | -msgstr "" |
30 | - |
31 | -#. module: account_chart_update |
32 | #: field:wizard.update.charts.accounts,update_children_accounts_parent:0 |
33 | msgid "Update children accounts parent" |
34 | msgstr "" |
35 | @@ -48,22 +43,22 @@ |
36 | msgstr "" |
37 | |
38 | #. module: account_chart_update |
39 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:716 |
40 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:769 |
41 | #, python-format |
42 | msgid "Created tax code %s.\n" |
43 | "" |
44 | msgstr "" |
45 | |
46 | #. module: account_chart_update |
47 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1012 |
48 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1038 |
49 | #, python-format |
50 | msgid "Tax %s: The collected account can not be set.\n" |
51 | "" |
52 | msgstr "" |
53 | |
54 | #. module: account_chart_update |
55 | -#: field:wizard.update.charts.accounts,new_accounts:0 |
56 | -msgid "New accounts" |
57 | +#: view:wizard.update.charts.accounts:0 |
58 | +msgid "or" |
59 | msgstr "" |
60 | |
61 | #. module: account_chart_update |
62 | @@ -80,14 +75,14 @@ |
63 | msgstr "" |
64 | |
65 | #. module: account_chart_update |
66 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1076 |
67 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1102 |
68 | #, python-format |
69 | msgid "Fiscal position %s: The destination tax %s can not be set.\n" |
70 | "" |
71 | msgstr "" |
72 | |
73 | #. module: account_chart_update |
74 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:839 |
75 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:881 |
76 | #, python-format |
77 | msgid "Tax %s: The tax code for the tax refund %s can not be set.\n" |
78 | "" |
79 | @@ -104,7 +99,7 @@ |
80 | msgstr "" |
81 | |
82 | #. module: account_chart_update |
83 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:617 |
84 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:651 |
85 | #, python-format |
86 | msgid "The template has taxes the fiscal position instance does not.\n" |
87 | "" |
88 | @@ -116,11 +111,6 @@ |
89 | msgstr "" |
90 | |
91 | #. module: account_chart_update |
92 | -#: view:wizard.update.charts.accounts:0 |
93 | -msgid "Account" |
94 | -msgstr "" |
95 | - |
96 | -#. module: account_chart_update |
97 | #: field:wizard.update.charts.accounts.account,notes:0 |
98 | #: field:wizard.update.charts.accounts.fiscal.position,notes:0 |
99 | #: field:wizard.update.charts.accounts.tax,notes:0 |
100 | @@ -135,7 +125,7 @@ |
101 | msgstr "" |
102 | |
103 | #. module: account_chart_update |
104 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:371 |
105 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:385 |
106 | #, python-format |
107 | msgid "The info field is different.\n" |
108 | "" |
109 | @@ -147,7 +137,7 @@ |
110 | msgstr "" |
111 | |
112 | #. module: account_chart_update |
113 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:723 |
114 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:776 |
115 | #, python-format |
116 | msgid "Updated tax code %s.\n" |
117 | "" |
118 | @@ -164,22 +154,22 @@ |
119 | msgstr "" |
120 | |
121 | #. module: account_chart_update |
122 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:806 |
123 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:851 |
124 | #, python-format |
125 | msgid "Created tax %s.\n" |
126 | "" |
127 | msgstr "" |
128 | |
129 | #. module: account_chart_update |
130 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:477 |
131 | +#, python-format |
132 | +msgid "The base sign field is different.\n" |
133 | +"" |
134 | +msgstr "" |
135 | + |
136 | +#. module: account_chart_update |
137 | #: code:addons/account_chart_update/wizard/wizard_chart_update.py:459 |
138 | #, python-format |
139 | -msgid "The base sign field is different.\n" |
140 | -"" |
141 | -msgstr "" |
142 | - |
143 | -#. module: account_chart_update |
144 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:441 |
145 | -#, python-format |
146 | msgid "The type field is different.\n" |
147 | "" |
148 | msgstr "" |
149 | @@ -196,14 +186,14 @@ |
150 | msgstr "" |
151 | |
152 | #. module: account_chart_update |
153 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:835 |
154 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:877 |
155 | #, python-format |
156 | msgid "Tax %s: The tax code for the tax %s can not be set.\n" |
157 | "" |
158 | msgstr "" |
159 | |
160 | #. module: account_chart_update |
161 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:612 |
162 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:646 |
163 | #, python-format |
164 | msgid "Tax mapping not found on the fiscal position instance: %s -> %s.\n" |
165 | "" |
166 | @@ -221,11 +211,6 @@ |
167 | |
168 | #. module: account_chart_update |
169 | #: view:wizard.update.charts.accounts:0 |
170 | -msgid "Tax" |
171 | -msgstr "" |
172 | - |
173 | -#. module: account_chart_update |
174 | -#: view:wizard.update.charts.accounts:0 |
175 | msgid "Next" |
176 | msgstr "" |
177 | |
178 | @@ -243,7 +228,7 @@ |
179 | msgstr "" |
180 | |
181 | #. module: account_chart_update |
182 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:435 |
183 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:453 |
184 | #, python-format |
185 | msgid "The sequence field is different.\n" |
186 | "" |
187 | @@ -255,7 +240,7 @@ |
188 | msgstr "" |
189 | |
190 | #. module: account_chart_update |
191 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:630 |
192 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:671 |
193 | #, python-format |
194 | msgid "Account mapping not found on the fiscal position instance: %s -> %s.\n" |
195 | "" |
196 | @@ -280,7 +265,7 @@ |
197 | msgstr "" |
198 | |
199 | #. module: account_chart_update |
200 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:465 |
201 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:483 |
202 | #, python-format |
203 | msgid "The include base amount field is different.\n" |
204 | "" |
205 | @@ -292,7 +277,7 @@ |
206 | msgstr "" |
207 | |
208 | #. module: account_chart_update |
209 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:633 |
210 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:674 |
211 | #, python-format |
212 | msgid "The template has accounts the fiscal position instance does not.\n" |
213 | "" |
214 | @@ -309,7 +294,7 @@ |
215 | msgstr "" |
216 | |
217 | #. module: account_chart_update |
218 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1014 |
219 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1040 |
220 | #, python-format |
221 | msgid "Tax %s: The paid account can not be set.\n" |
222 | "" |
223 | @@ -322,7 +307,7 @@ |
224 | msgstr "" |
225 | |
226 | #. module: account_chart_update |
227 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:941 |
228 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:972 |
229 | #, python-format |
230 | msgid "Exception creating account %s: %s - %s.\n" |
231 | "" |
232 | @@ -334,39 +319,51 @@ |
233 | msgstr "" |
234 | |
235 | #. module: account_chart_update |
236 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:453 |
237 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:471 |
238 | #, python-format |
239 | msgid "The python compute field is different.\n" |
240 | "" |
241 | msgstr "" |
242 | |
243 | #. module: account_chart_update |
244 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:648 |
245 | +#, python-format |
246 | +msgid "None" |
247 | +msgstr "" |
248 | + |
249 | +#. module: account_chart_update |
250 | #: model:ir.model,name:account_chart_update.model_wizard_update_charts_accounts_tax_code |
251 | msgid "wizard.update.charts.accounts.tax.code" |
252 | msgstr "" |
253 | |
254 | #. module: account_chart_update |
255 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1092 |
256 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1124 |
257 | #, python-format |
258 | msgid "Fiscal position %s: The source account %s can not be set.\n" |
259 | "" |
260 | msgstr "" |
261 | |
262 | #. module: account_chart_update |
263 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:833 |
264 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:875 |
265 | #, python-format |
266 | msgid "Tax %s: The tax code for the base %s can not be set.\n" |
267 | "" |
268 | msgstr "" |
269 | |
270 | #. module: account_chart_update |
271 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:952 |
272 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:983 |
273 | #, python-format |
274 | msgid "Exception writing account %s: %s - %s.\n" |
275 | "" |
276 | msgstr "" |
277 | |
278 | #. module: account_chart_update |
279 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:543 |
280 | +#, python-format |
281 | +msgid "Code not found." |
282 | +msgstr "" |
283 | + |
284 | +#. module: account_chart_update |
285 | #: view:wizard.update.charts.accounts:0 |
286 | msgid "Note: Not all the fields are tested for changes, just the main ones" |
287 | msgstr "" |
288 | @@ -377,18 +374,13 @@ |
289 | msgstr "" |
290 | |
291 | #. module: account_chart_update |
292 | -#: view:wizard.update.charts.accounts:0 |
293 | -msgid "or" |
294 | -msgstr "" |
295 | - |
296 | -#. module: account_chart_update |
297 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:250 |
298 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:441 |
299 | #, python-format |
300 | -msgid "Update Chart of Accounts from a Chart Template " |
301 | +msgid "Name or description not found." |
302 | msgstr "" |
303 | |
304 | #. module: account_chart_update |
305 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:531 |
306 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:551 |
307 | #, python-format |
308 | msgid "The name is different.\n" |
309 | "" |
310 | @@ -400,28 +392,28 @@ |
311 | msgstr "" |
312 | |
313 | #. module: account_chart_update |
314 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:736 |
315 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:787 |
316 | #, python-format |
317 | msgid "Tax code %s: The parent tax code %s can not be set.\n" |
318 | "" |
319 | msgstr "" |
320 | |
321 | #. module: account_chart_update |
322 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:438 |
323 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:456 |
324 | #, python-format |
325 | msgid "The amount field is different.\n" |
326 | "" |
327 | msgstr "" |
328 | |
329 | #. module: account_chart_update |
330 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:450 |
331 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:468 |
332 | #, python-format |
333 | msgid "The child depend field is different.\n" |
334 | "" |
335 | msgstr "" |
336 | |
337 | #. module: account_chart_update |
338 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:948 |
339 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:979 |
340 | #, python-format |
341 | msgid "Updated account %s.\n" |
342 | "" |
343 | @@ -438,7 +430,7 @@ |
344 | msgstr "" |
345 | |
346 | #. module: account_chart_update |
347 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:468 |
348 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:486 |
349 | #, python-format |
350 | msgid "The type tax use field is different.\n" |
351 | "" |
352 | @@ -450,14 +442,14 @@ |
353 | msgstr "" |
354 | |
355 | #. module: account_chart_update |
356 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:963 |
357 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:992 |
358 | #, python-format |
359 | msgid "Account %s: The parent account %s can not be set.\n" |
360 | "" |
361 | msgstr "" |
362 | |
363 | #. module: account_chart_update |
364 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:831 |
365 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:873 |
366 | #, python-format |
367 | msgid "Tax %s: The parent tax %s can not be set.\n" |
368 | "" |
369 | @@ -485,21 +477,21 @@ |
370 | msgstr "" |
371 | |
372 | #. module: account_chart_update |
373 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:374 |
374 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:388 |
375 | #, python-format |
376 | msgid "The sign field is different.\n" |
377 | "" |
378 | msgstr "" |
379 | |
380 | #. module: account_chart_update |
381 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:813 |
382 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:858 |
383 | #, python-format |
384 | msgid "Updated tax %s.\n" |
385 | "" |
386 | msgstr "" |
387 | |
388 | #. module: account_chart_update |
389 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:874 |
390 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:914 |
391 | #, python-format |
392 | msgid "Exception setting the parent of account %s children: %s - %s.\n" |
393 | "" |
394 | @@ -531,7 +523,7 @@ |
395 | msgstr "" |
396 | |
397 | #. module: account_chart_update |
398 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1127 |
399 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1173 |
400 | #, python-format |
401 | msgid "Error" |
402 | msgstr "" |
403 | @@ -542,7 +534,7 @@ |
404 | msgstr "" |
405 | |
406 | #. module: account_chart_update |
407 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:534 |
408 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:554 |
409 | #, python-format |
410 | msgid "The type is different.\n" |
411 | "" |
412 | @@ -565,6 +557,11 @@ |
413 | msgstr "" |
414 | |
415 | #. module: account_chart_update |
416 | +#: view:wizard.update.charts.accounts:0 |
417 | +msgid "Close" |
418 | +msgstr "" |
419 | + |
420 | +#. module: account_chart_update |
421 | #: help:wizard.update.charts.accounts,update_tax:0 |
422 | msgid "Existing taxes are updated. Taxes are searched by name." |
423 | msgstr "" |
424 | @@ -575,7 +572,7 @@ |
425 | msgstr "" |
426 | |
427 | #. module: account_chart_update |
428 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:837 |
429 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:879 |
430 | #, python-format |
431 | msgid "Tax %s: The tax code for the base refund %s can not be set.\n" |
432 | "" |
433 | @@ -592,14 +589,14 @@ |
434 | msgstr "" |
435 | |
436 | #. module: account_chart_update |
437 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:462 |
438 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:480 |
439 | #, python-format |
440 | msgid "The tax sign field is different.\n" |
441 | "" |
442 | msgstr "" |
443 | |
444 | #. module: account_chart_update |
445 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1127 |
446 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1173 |
447 | #, python-format |
448 | msgid "One or more errors detected!\n" |
449 | "\n" |
450 | @@ -607,7 +604,7 @@ |
451 | msgstr "" |
452 | |
453 | #. module: account_chart_update |
454 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1094 |
455 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1126 |
456 | #, python-format |
457 | msgid "Fiscal position %s: The destination account %s can not be set.\n" |
458 | "" |
459 | @@ -619,15 +616,15 @@ |
460 | msgstr "" |
461 | |
462 | #. module: account_chart_update |
463 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:444 |
464 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:462 |
465 | #, python-format |
466 | msgid "The applicable type field is different.\n" |
467 | "" |
468 | msgstr "" |
469 | |
470 | #. module: account_chart_update |
471 | -#: view:wizard.update.charts.accounts:0 |
472 | -msgid "Tax code" |
473 | +#: field:wizard.update.charts.accounts,new_accounts:0 |
474 | +msgid "New accounts" |
475 | msgstr "" |
476 | |
477 | #. module: account_chart_update |
478 | @@ -636,10 +633,9 @@ |
479 | msgstr "" |
480 | |
481 | #. module: account_chart_update |
482 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:614 |
483 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:373 |
484 | #, python-format |
485 | -msgid "Tax mapping not found on the fiscal position instance: %s -> None.\n" |
486 | -"" |
487 | +msgid "Name or code not found." |
488 | msgstr "" |
489 | |
490 | #. module: account_chart_update |
491 | @@ -653,7 +649,7 @@ |
492 | msgstr "" |
493 | |
494 | #. module: account_chart_update |
495 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:537 |
496 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:557 |
497 | #, python-format |
498 | msgid "The user type is different.\n" |
499 | "" |
500 | @@ -673,14 +669,14 @@ |
501 | msgstr "" |
502 | |
503 | #. module: account_chart_update |
504 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:540 |
505 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:560 |
506 | #, python-format |
507 | msgid "The reconcile is different.\n" |
508 | "" |
509 | msgstr "" |
510 | |
511 | #. module: account_chart_update |
512 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:447 |
513 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:465 |
514 | #, python-format |
515 | msgid "The domain field is different.\n" |
516 | "" |
517 | @@ -702,14 +698,14 @@ |
518 | msgstr "" |
519 | |
520 | #. module: account_chart_update |
521 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1096 |
522 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1128 |
523 | #, python-format |
524 | msgid "Created or updated fiscal position %s.\n" |
525 | "" |
526 | msgstr "" |
527 | |
528 | #. module: account_chart_update |
529 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1074 |
530 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1100 |
531 | #, python-format |
532 | msgid "Fiscal position %s: The source tax %s can not be set.\n" |
533 | "" |
534 | @@ -726,7 +722,7 @@ |
535 | msgstr "" |
536 | |
537 | #. module: account_chart_update |
538 | -#: code:addons/account_chart_update/wizard/wizard_chart_update.py:937 |
539 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:968 |
540 | #, python-format |
541 | msgid "Created account %s.\n" |
542 | "" |
543 | @@ -738,6 +734,12 @@ |
544 | msgstr "" |
545 | |
546 | #. module: account_chart_update |
547 | +#: code:addons/account_chart_update/wizard/wizard_chart_update.py:616 |
548 | +#, python-format |
549 | +msgid "Name not found." |
550 | +msgstr "" |
551 | + |
552 | +#. module: account_chart_update |
553 | #: help:wizard.update.charts.accounts,continue_on_errors:0 |
554 | msgid "If set, the wizard will continue to the next step even if there are minor errors (for example the parent account of a new account couldn't be set)." |
555 | msgstr "" |
556 | |
557 | === modified file 'account_chart_update/wizard/wizard_chart_update.py' |
558 | --- account_chart_update/wizard/wizard_chart_update.py 2014-01-07 11:48:24 +0000 |
559 | +++ account_chart_update/wizard/wizard_chart_update.py 2014-05-20 00:05:21 +0000 |
560 | @@ -97,7 +97,9 @@ |
561 | ('done', 'Wizard completed') |
562 | ], 'Status', readonly=True), |
563 | 'company_id': fields.many2one('res.company', 'Company', required=True, ondelete='set null'), |
564 | - 'chart_template_id': fields.many2one('account.chart.template', 'Chart Template', required=True, ondelete='set null'), |
565 | + 'chart_template_id': fields.many2one( |
566 | + 'account.chart.template', 'Chart Template', ondelete='cascade', |
567 | + required=True), |
568 | 'code_digits': fields.integer('# of digits', required=True, help="No. of digits to use for account code. Make sure it is the same number as existing accounts."), |
569 | 'lang': fields.selection(_get_lang_selection_options, 'Language', size=5, help="For records searched by name (taxes, tax codes, fiscal positions), the template name will be matched against the record name on this language."), |
570 | 'update_tax_code': fields.boolean('Update tax codes', help="Existing tax codes are updated. Tax codes are searched by name."), |
571 | @@ -242,115 +244,146 @@ |
572 | # Helper methods |
573 | ########################################################################## |
574 | |
575 | - def _map_tax_template(self, cr, uid, wizard, tax_template_mapping, tax_template, context=None): |
576 | + def _map_tax_template(self, cr, uid, wizard, tax_templ_mapping, |
577 | + tax_templ, context=None): |
578 | """ |
579 | Adds a tax template -> tax id to the mapping. |
580 | """ |
581 | - if tax_template and not tax_template_mapping.get(tax_template.id): |
582 | - taxes = self.pool.get('account.tax') |
583 | - tax_ids = taxes.search(cr, uid, [ |
584 | - ('name', '=', tax_template.name), |
585 | - ('company_id', '=', wizard.company_id.id) |
586 | - ], context=context) |
587 | - if tax_ids: |
588 | - tax_template_mapping[tax_template.id] = tax_ids[0] |
589 | + if not tax_templ: |
590 | + return False |
591 | + if tax_templ_mapping.get(tax_templ.id): |
592 | + return tax_templ_mapping[tax_templ.id] |
593 | + # In other case |
594 | + tax_obj = self.pool['account.tax'] |
595 | + criteria = ['|', |
596 | + ('name', '=', tax_templ.name), |
597 | + ('description', '=', tax_templ.name)] |
598 | + if tax_templ.description: |
599 | + criteria = (['|', '|'] + criteria + |
600 | + [('description', '=', tax_templ.description), |
601 | + ('name', '=', tax_templ.description)]) |
602 | + tax_ids = tax_obj.search(cr, uid, criteria, context=context) |
603 | + tax_templ_mapping[tax_templ.id] = tax_ids and tax_ids[0] or False |
604 | + return tax_templ_mapping[tax_templ.id] |
605 | |
606 | - def _map_tax_code_template(self, cr, uid, wizard, tax_code_template_mapping, tax_code_template, context=None): |
607 | + def _map_tax_code_template(self, cr, uid, wizard, |
608 | + tax_code_templ_mapping, tax_code_template, |
609 | + context=None): |
610 | """ |
611 | Adds a tax code template -> tax code id to the mapping. |
612 | """ |
613 | - if tax_code_template and not tax_code_template_mapping.get(tax_code_template.id): |
614 | - tax_codes = self.pool.get('account.tax.code') |
615 | - root_tax_code_id = wizard.chart_template_id.tax_code_root_id.id |
616 | - tax_code_name = (tax_code_template.id == root_tax_code_id) and wizard.company_id.name or tax_code_template.name |
617 | - tax_code_ids = tax_codes.search(cr, uid, [ |
618 | - ('name', '=', tax_code_name), |
619 | - ('company_id', '=', wizard.company_id.id) |
620 | - ]) |
621 | - if not tax_code_ids: |
622 | - # if we could not match no tax code template name, |
623 | - # try to match on tax code template code, if any |
624 | - tax_code_code = tax_code_template.code |
625 | - if tax_code_code: |
626 | - tax_code_ids = tax_codes.search(cr, uid, [ |
627 | - ('code', '=', tax_code_code), |
628 | - ('company_id', '=', wizard.company_id.id) |
629 | - ]) |
630 | - if tax_code_ids: |
631 | - tax_code_template_mapping[ |
632 | - tax_code_template.id] = tax_code_ids[0] |
633 | + if not tax_code_template: |
634 | + return False |
635 | + if not wizard.chart_template_id: |
636 | + return False |
637 | + if tax_code_templ_mapping.get(tax_code_template.id): |
638 | + return tax_code_templ_mapping[tax_code_template.id] |
639 | + # In other case |
640 | + tax_code_obj = self.pool['account.tax.code'] |
641 | + root_tax_code_id = wizard.chart_template_id.tax_code_root_id.id |
642 | + tax_code_name = ((tax_code_template.id == root_tax_code_id) and |
643 | + wizard.company_id.name or tax_code_template.name) |
644 | + tax_code_ids = tax_code_obj.search(cr, uid, [ |
645 | + ('name', '=', tax_code_name), |
646 | + ('company_id', '=', wizard.company_id.id) |
647 | + ], context=context) |
648 | + if not tax_code_ids: |
649 | + # if we could not match no tax code template name, |
650 | + # try to match on tax code template code, if any |
651 | + tax_code_code = tax_code_template.code |
652 | + if tax_code_code: |
653 | + tax_code_ids = tax_code_obj.search(cr, uid, [ |
654 | + ('code', '=', tax_code_code), |
655 | + ('company_id', '=', wizard.company_id.id) |
656 | + ], context=context) |
657 | + tax_code_templ_mapping[tax_code_template.id] = (tax_code_ids and |
658 | + tax_code_ids[0] or |
659 | + False) |
660 | + return tax_code_templ_mapping[tax_code_template.id] |
661 | |
662 | - def _map_account_template(self, cr, uid, wizard, account_template_mapping, account_template, context=None): |
663 | + def _map_account_template(self, cr, uid, wizard, acc_templ_mapping, |
664 | + acc_templ, context=None): |
665 | """ |
666 | Adds an account template -> account id to the mapping |
667 | """ |
668 | - if account_template and not account_template_mapping.get(account_template.id): |
669 | - accounts = self.pool.get('account.account') |
670 | - code = account_template.code or '' |
671 | - if account_template.type != 'view': |
672 | - if len(code) > 0 and len(code) <= wizard.code_digits: |
673 | - code = '%s%s' % ( |
674 | - code, '0' * (wizard.code_digits - len(code))) |
675 | - account_ids = accounts.search(cr, uid, [ |
676 | - ('code', '=', code), |
677 | - ('company_id', '=', wizard.company_id.id) |
678 | - ], context=context) |
679 | - if account_ids: |
680 | - account_template_mapping[account_template.id] = account_ids[0] |
681 | + if not acc_templ: |
682 | + return False |
683 | + if acc_templ_mapping.get(acc_templ.id): |
684 | + return acc_templ_mapping[acc_templ.id] |
685 | + # In other case |
686 | + acc_obj = self.pool['account.account'] |
687 | + code = acc_templ.code or '' |
688 | + if acc_templ.type != 'view': |
689 | + if code and len(code) <= wizard.code_digits: |
690 | + code = '%s%s' % (code, '0' * (wizard.code_digits - len(code))) |
691 | + acc_ids = acc_obj.search(cr, uid, [ |
692 | + ('code', '=', code), |
693 | + ('company_id', '=', wizard.company_id.id) |
694 | + ], context=context) |
695 | + acc_templ_mapping[acc_templ.id] = acc_ids and acc_ids[0] or False |
696 | + return acc_templ_mapping[acc_templ.id] |
697 | |
698 | - def _map_fp_template(self, cr, uid, wizard, fp_template_mapping, fp_template, context=None): |
699 | + def _map_fp_template(self, cr, uid, wizard, fp_templ_mapping, fp_template, context=None): |
700 | """ |
701 | Adds a fiscal position template -> fiscal position id to the mapping. |
702 | """ |
703 | - if fp_template and not fp_template_mapping.get(fp_template.id): |
704 | - fiscalpositions = self.pool.get('account.fiscal.position') |
705 | - fp_ids = fiscalpositions.search(cr, uid, [ |
706 | - ('name', '=', fp_template.name), |
707 | - ('company_id', '=', wizard.company_id.id) |
708 | - ], context=context) |
709 | - if fp_ids: |
710 | - fp_template_mapping[fp_template.id] = fp_ids[0] |
711 | + if not fp_template: |
712 | + return False |
713 | + if fp_templ_mapping.get(fp_template.id): |
714 | + return fp_templ_mapping[fp_template.id] |
715 | + # In other case |
716 | + fp_obj = self.pool['account.fiscal.position'] |
717 | + fp_ids = fp_obj.search(cr, uid, |
718 | + [('name', '=', fp_template.name), |
719 | + ('company_id', '=', wizard.company_id.id)], |
720 | + context=context) |
721 | + fp_templ_mapping[fp_template.id] = fp_ids and fp_ids[0] or False |
722 | + return fp_templ_mapping[fp_template.id] |
723 | |
724 | - def _find_tax_codes(self, cr, uid, wizard, context=None): |
725 | + def _find_tax_codes(self, cr, uid, wizard, chart_template_ids, |
726 | + context=None): |
727 | """ |
728 | Search for, and load, tax code templates to create/update. |
729 | + |
730 | + @param chart_template_ids: IDs of the chart templates to look on, |
731 | + calculated once in the calling method. |
732 | """ |
733 | + if not wizard.chart_template_id: |
734 | + return {} |
735 | new_tax_codes = 0 |
736 | updated_tax_codes = 0 |
737 | tax_code_template_mapping = {} |
738 | - |
739 | - taxes_codes_templates = self.pool.get('account.tax.code.template') |
740 | - taxcodes = self.pool.get('account.tax.code') |
741 | - wiz_taxcodes = self.pool.get('wizard.update.charts.accounts.tax.code') |
742 | - |
743 | + tax_code_templ_obj = self.pool['account.tax.code.template'] |
744 | + tax_code_obj = self.pool['account.tax.code'] |
745 | + wiz_tax_code_obj = self.pool['wizard.update.charts.accounts.tax.code'] |
746 | # Remove previous tax codes |
747 | - wiz_taxcodes.unlink( |
748 | - cr, uid, wiz_taxcodes.search(cr, uid, [])) |
749 | - |
750 | + wiz_tax_code_obj.unlink(cr, uid, wiz_tax_code_obj.search(cr, uid, [])) |
751 | # Search for new / updated tax codes |
752 | root_tax_code_id = wizard.chart_template_id.tax_code_root_id.id |
753 | - children_tax_code_template = taxes_codes_templates.search(cr, uid, [( |
754 | - 'parent_id', 'child_of', [root_tax_code_id])], order='id') |
755 | - for tax_code_template in taxes_codes_templates.browse(cr, uid, children_tax_code_template): |
756 | + children_tax_code_template = tax_code_templ_obj.search(cr, uid, [( |
757 | + 'parent_id', 'child_of', [root_tax_code_id])], order='id', |
758 | + context=context) |
759 | + for tax_code_template in tax_code_templ_obj.browse(cr, uid, |
760 | + children_tax_code_template, context=context): |
761 | # Ensure the tax code template is on the map (search for the mapped |
762 | # tax code id). |
763 | - self._map_tax_code_template(cr, uid, wizard, tax_code_template_mapping, tax_code_template, context) |
764 | - |
765 | - tax_code_id = tax_code_template_mapping.get(tax_code_template.id) |
766 | + tax_code_id = self._map_tax_code_template(cr, uid, wizard, |
767 | + tax_code_template_mapping, |
768 | + tax_code_template, context=context) |
769 | if not tax_code_id: |
770 | new_tax_codes += 1 |
771 | - wiz_taxcodes.create(cr, uid, { |
772 | + wiz_tax_code_obj.create(cr, uid, { |
773 | 'tax_code_id': tax_code_template.id, |
774 | 'update_chart_wizard_id': wizard.id, |
775 | 'type': 'new', |
776 | + 'notes': _('Name or code not found.'), |
777 | }, context) |
778 | elif wizard.update_tax_code: |
779 | # Check the tax code for changes. |
780 | modified = False |
781 | notes = "" |
782 | - tax_code = taxcodes.browse( |
783 | + tax_code = tax_code_obj.browse( |
784 | cr, uid, tax_code_id, context=context) |
785 | - |
786 | if tax_code.code != tax_code_template.code: |
787 | notes += _("The code field is different.\n") |
788 | modified = True |
789 | @@ -360,278 +393,306 @@ |
790 | if tax_code.sign != tax_code_template.sign: |
791 | notes += _("The sign field is different.\n") |
792 | modified = True |
793 | - |
794 | # TODO: We could check other account fields for changes... |
795 | - |
796 | if modified: |
797 | # Tax code to update. |
798 | updated_tax_codes += 1 |
799 | - wiz_taxcodes.create(cr, uid, { |
800 | + wiz_tax_code_obj.create(cr, uid, { |
801 | 'tax_code_id': tax_code_template.id, |
802 | 'update_chart_wizard_id': wizard.id, |
803 | 'type': 'updated', |
804 | 'update_tax_code_id': tax_code_id, |
805 | 'notes': notes, |
806 | }, context) |
807 | - |
808 | return { |
809 | 'new': new_tax_codes, |
810 | 'updated': updated_tax_codes, |
811 | 'mapping': tax_code_template_mapping |
812 | } |
813 | |
814 | - def _find_taxes(self, cr, uid, wizard, context=None): |
815 | + def _find_taxes(self, cr, uid, wizard, chart_template_ids, context=None): |
816 | """ |
817 | Search for, and load, tax templates to create/update. |
818 | + |
819 | + @param chart_template_ids: IDs of the chart templates to look on, |
820 | + calculated once in the calling method. |
821 | """ |
822 | new_taxes = 0 |
823 | updated_taxes = 0 |
824 | - tax_template_mapping = {} |
825 | - |
826 | - taxes = self.pool.get('account.tax') |
827 | - wiz_taxes = self.pool.get('wizard.update.charts.accounts.tax') |
828 | - |
829 | + tax_templ_mapping = {} |
830 | + tax_obj = self.pool['account.tax'] |
831 | + tax_templ_obj = self.pool['account.tax.template'] |
832 | + wiz_taxes_obj = self.pool['wizard.update.charts.accounts.tax'] |
833 | delay_wiz_tax = [] |
834 | # Remove previous taxes |
835 | - wiz_taxes.unlink(cr, uid, wiz_taxes.search(cr, uid, [])) |
836 | + wiz_taxes_ids = wiz_taxes_obj.search(cr, uid, [], context=context) |
837 | + wiz_taxes_obj.unlink(cr, uid, wiz_taxes_ids, context=context) |
838 | # Search for new / updated taxes |
839 | - for tax_template in wizard.chart_template_id.tax_template_ids: |
840 | - # Ensure the tax template is on the map (search for the mapped tax |
841 | - # id). |
842 | - self._map_tax_template( |
843 | - cr, uid, wizard, tax_template_mapping, tax_template, context) |
844 | - |
845 | - tax_id = tax_template_mapping.get(tax_template.id) |
846 | + tax_templ_ids = tax_templ_obj.search( |
847 | + cr, uid, [('chart_template_id', 'in', chart_template_ids)], |
848 | + context=context) |
849 | + for tax_templ in tax_templ_obj.browse(cr, uid, tax_templ_ids, |
850 | + context=context): |
851 | + # Ensure tax template is on the map (search for the mapped tax id) |
852 | + tax_id = self._map_tax_template(cr, uid, wizard, |
853 | + tax_templ_mapping, |
854 | + tax_templ, context=context) |
855 | if not tax_id: |
856 | new_taxes += 1 |
857 | vals_wiz = { |
858 | - 'tax_id': tax_template.id, |
859 | + 'tax_id': tax_templ.id, |
860 | 'update_chart_wizard_id': wizard.id, |
861 | 'type': 'new', |
862 | + 'notes': _('Name or description not found.'), |
863 | } |
864 | - if not tax_template.parent_id: |
865 | - wiz_taxes.create(cr, uid, vals_wiz, context) |
866 | + if not tax_templ.parent_id: |
867 | + wiz_taxes_obj.create(cr, uid, vals_wiz, context) |
868 | else: |
869 | delay_wiz_tax.append(vals_wiz) |
870 | elif wizard.update_tax: |
871 | # Check the tax for changes. |
872 | modified = False |
873 | notes = "" |
874 | - tax = taxes.browse(cr, uid, tax_id, context=context) |
875 | - if tax.sequence != tax_template.sequence: |
876 | + tax = tax_obj.browse(cr, uid, tax_id, context=context) |
877 | + if tax.sequence != tax_templ.sequence: |
878 | notes += _("The sequence field is different.\n") |
879 | modified = True |
880 | - if tax.amount != tax_template.amount: |
881 | + if tax.amount != tax_templ.amount: |
882 | notes += _("The amount field is different.\n") |
883 | modified = True |
884 | - if tax.type != tax_template.type: |
885 | + if tax.type != tax_templ.type: |
886 | notes += _("The type field is different.\n") |
887 | modified = True |
888 | - if tax.applicable_type != tax_template.applicable_type: |
889 | + if tax.applicable_type != tax_templ.applicable_type: |
890 | notes += _("The applicable type field is different.\n") |
891 | modified = True |
892 | - if tax.domain != tax_template.domain: |
893 | + if tax.domain != tax_templ.domain: |
894 | notes += _("The domain field is different.\n") |
895 | modified = True |
896 | - if tax.child_depend != tax_template.child_depend: |
897 | + if tax.child_depend != tax_templ.child_depend: |
898 | notes += _("The child depend field is different.\n") |
899 | modified = True |
900 | - if tax.python_compute != tax_template.python_compute: |
901 | + if tax.python_compute != tax_templ.python_compute: |
902 | notes += _("The python compute field is different.\n") |
903 | modified = True |
904 | - # if tax.tax_group != tax_template.tax_group: |
905 | + # if tax.tax_group != tax_templ.tax_group: |
906 | # notes += _("The tax group field is different.\n") |
907 | # modified = True |
908 | - if tax.base_sign != tax_template.base_sign: |
909 | + if tax.base_sign != tax_templ.base_sign: |
910 | notes += _("The base sign field is different.\n") |
911 | modified = True |
912 | - if tax.tax_sign != tax_template.tax_sign: |
913 | + if tax.tax_sign != tax_templ.tax_sign: |
914 | notes += _("The tax sign field is different.\n") |
915 | modified = True |
916 | - if tax.include_base_amount != tax_template.include_base_amount: |
917 | + if tax.include_base_amount != tax_templ.include_base_amount: |
918 | notes += _("The include base amount field is different.\n") |
919 | modified = True |
920 | - if tax.type_tax_use != tax_template.type_tax_use: |
921 | + if tax.type_tax_use != tax_templ.type_tax_use: |
922 | notes += _("The type tax use field is different.\n") |
923 | modified = True |
924 | # TODO: We could check other tax fields for changes... |
925 | - |
926 | if modified: |
927 | # Tax code to update. |
928 | updated_taxes += 1 |
929 | - wiz_taxes.create(cr, uid, { |
930 | - 'tax_id': tax_template.id, |
931 | + wiz_taxes_obj.create(cr, uid, { |
932 | + 'tax_id': tax_templ.id, |
933 | 'update_chart_wizard_id': wizard.id, |
934 | 'type': 'updated', |
935 | 'update_tax_id': tax_id, |
936 | 'notes': notes, |
937 | }, context) |
938 | - |
939 | for delay_vals_wiz in delay_wiz_tax: |
940 | - wiz_taxes.create(cr, uid, delay_vals_wiz, context) |
941 | + wiz_taxes_obj.create(cr, uid, delay_vals_wiz, context) |
942 | |
943 | - return {'new': new_taxes, 'updated': updated_taxes, 'mapping': tax_template_mapping} |
944 | + return {'new': new_taxes, 'updated': updated_taxes, 'mapping': tax_templ_mapping} |
945 | |
946 | def _find_accounts(self, cr, uid, wizard, context=None): |
947 | """ |
948 | Search for, and load, account templates to create/update. |
949 | """ |
950 | + if not wizard.chart_template_id: |
951 | + return {} |
952 | new_accounts = 0 |
953 | updated_accounts = 0 |
954 | - account_template_mapping = {} |
955 | - |
956 | - accounts = self.pool.get('account.account') |
957 | - accounts_template = self.pool.get('account.account.template') |
958 | - wiz_accounts = self.pool.get( |
959 | - 'wizard.update.charts.accounts.account') |
960 | - |
961 | + acc_templ_mapping = {} |
962 | + acc_obj = self.pool['account.account'] |
963 | + acc_templ_obj = self.pool['account.account.template'] |
964 | + wiz_accounts = self.pool['wizard.update.charts.accounts.account'] |
965 | # Remove previous accounts |
966 | - wiz_accounts.unlink( |
967 | - cr, uid, wiz_accounts.search(cr, uid, [])) |
968 | - |
969 | + wiz_accounts_ids = wiz_accounts.search(cr, uid, [], context=context) |
970 | + wiz_accounts.unlink(cr, uid, wiz_accounts_ids, context=context) |
971 | # Search for new / updated accounts |
972 | root_account_id = wizard.chart_template_id.account_root_id.id |
973 | - children_acc_template = accounts_template.search(cr, uid, [( |
974 | - 'parent_id', 'child_of', [root_account_id])], context=context) |
975 | - children_acc_template.sort() |
976 | - for account_template in accounts_template.browse(cr, uid, children_acc_template, context=context): |
977 | + acc_templ_criteria = [('chart_template_id', |
978 | + '=', |
979 | + wizard.chart_template_id.id)] |
980 | + if root_account_id: |
981 | + acc_templ_criteria = (['|'] + acc_templ_criteria + |
982 | + ['&', ('parent_id', 'child_of', [root_account_id]), |
983 | + ('chart_template_id', '=', False)]) |
984 | + acc_ids = acc_templ_obj.search(cr, uid, acc_templ_criteria, |
985 | + context=context) |
986 | + acc_ids.sort() |
987 | + for acc_templ in acc_templ_obj.browse(cr, uid, acc_ids, |
988 | + context=context): |
989 | # Ensure the account template is on the map (search for the mapped |
990 | # account id). |
991 | - self._map_account_template(cr, uid, wizard, account_template_mapping, account_template, context) |
992 | - |
993 | - account_id = account_template_mapping.get(account_template.id) |
994 | + account_id = self._map_account_template(cr, uid, wizard, |
995 | + acc_templ_mapping, |
996 | + acc_templ, |
997 | + context=context) |
998 | if not account_id: |
999 | new_accounts += 1 |
1000 | wiz_accounts.create(cr, uid, { |
1001 | - 'account_id': account_template.id, |
1002 | + 'account_id': acc_templ.id, |
1003 | 'update_chart_wizard_id': wizard.id, |
1004 | 'type': 'new', |
1005 | + 'notes': _('Code not found.'), |
1006 | }, context) |
1007 | elif wizard.update_account: |
1008 | # Check the account for changes. |
1009 | modified = False |
1010 | notes = "" |
1011 | - account = accounts.browse( |
1012 | - cr, uid, account_id, context=context) |
1013 | - |
1014 | - if account.name != account_template.name and account.name != wizard.company_id.name: |
1015 | + account = acc_obj.browse(cr, uid, account_id, context=context) |
1016 | + if account.name != acc_templ.name and account.name != wizard.company_id.name: |
1017 | notes += _("The name is different.\n") |
1018 | modified = True |
1019 | - if account.type != account_template.type: |
1020 | + if account.type != acc_templ.type: |
1021 | notes += _("The type is different.\n") |
1022 | modified = True |
1023 | - if account.user_type != account_template.user_type: |
1024 | + if account.user_type != acc_templ.user_type: |
1025 | notes += _("The user type is different.\n") |
1026 | modified = True |
1027 | - if account.reconcile != account_template.reconcile: |
1028 | + if account.reconcile != acc_templ.reconcile: |
1029 | notes += _("The reconcile is different.\n") |
1030 | modified = True |
1031 | - |
1032 | # TODO: We could check other account fields for changes... |
1033 | - |
1034 | if modified: |
1035 | # Account to update. |
1036 | updated_accounts += 1 |
1037 | wiz_accounts.create(cr, uid, { |
1038 | - 'account_id': account_template.id, |
1039 | + 'account_id': acc_templ.id, |
1040 | 'update_chart_wizard_id': wizard.id, |
1041 | 'type': 'updated', |
1042 | 'update_account_id': account_id, |
1043 | 'notes': notes, |
1044 | }, context) |
1045 | - |
1046 | - return {'new': new_accounts, 'updated': updated_accounts, 'mapping': account_template_mapping} |
1047 | - |
1048 | - def _find_fiscal_positions(self, cr, uid, wizard, context=None): |
1049 | + return { |
1050 | + 'new': new_accounts, |
1051 | + 'updated': updated_accounts, |
1052 | + 'mapping': acc_templ_mapping |
1053 | + } |
1054 | + |
1055 | + def _find_fiscal_positions(self, cr, uid, wizard, chart_template_ids, |
1056 | + context=None): |
1057 | """ |
1058 | Search for, and load, fiscal position templates to create/update. |
1059 | + |
1060 | + @param chart_template_ids: IDs of the chart templates to look on, |
1061 | + calculated once in the calling method. |
1062 | """ |
1063 | new_fps = 0 |
1064 | updated_fps = 0 |
1065 | - fp_template_mapping = {} |
1066 | - |
1067 | - fiscalpostitions_template = self.pool.get('account.fiscal.position.template') |
1068 | - fiscalpositions = self.pool.get('account.fiscal.position') |
1069 | - wiz_fiscalpositions = self.pool.get( |
1070 | - 'wizard.update.charts.accounts.fiscal.position') |
1071 | - |
1072 | + fp_templ_mapping = {} |
1073 | + tax_templ_mapping = {} |
1074 | + acc_templ_mapping = {} |
1075 | + fp_templ_obj = self.pool['account.fiscal.position.template'] |
1076 | + fp_obj = self.pool['account.fiscal.position'] |
1077 | + wiz_fp = self.pool['wizard.update.charts.accounts.fiscal.position'] |
1078 | # Remove previous fiscal positions |
1079 | - wiz_fiscalpositions.unlink(cr, uid, wiz_fiscalpositions.search(cr, uid, [])) |
1080 | - |
1081 | + wiz_fp.unlink(cr, uid, wiz_fp.search(cr, uid, [])) |
1082 | # Search for new / updated fiscal positions |
1083 | - fp_template_ids = fiscalpostitions_template.search(cr, uid, [('chart_template_id', '=', wizard.chart_template_id.id)], context=context) |
1084 | - for fp_template in fiscalpostitions_template.browse(cr, uid, fp_template_ids, context=context): |
1085 | + fp_template_ids = fp_templ_obj.search(cr, uid, |
1086 | + [('chart_template_id', |
1087 | + 'in', |
1088 | + chart_template_ids)], |
1089 | + context=context) |
1090 | + for fp_templ in fp_templ_obj.browse(cr, uid, fp_template_ids, |
1091 | + context=context): |
1092 | # Ensure the fiscal position template is on the map (search for the |
1093 | # mapped fiscal position id). |
1094 | - self._map_fp_template( |
1095 | - cr, uid, wizard, fp_template_mapping, fp_template, context) |
1096 | - |
1097 | - fp_id = fp_template_mapping.get(fp_template.id) |
1098 | + fp_id = self._map_fp_template(cr, uid, wizard, fp_templ_mapping, |
1099 | + fp_templ, context=context) |
1100 | if not fp_id: |
1101 | # New fiscal position template. |
1102 | new_fps += 1 |
1103 | - wiz_fiscalpositions.create(cr, uid, { |
1104 | - 'fiscal_position_id': fp_template.id, |
1105 | + wiz_fp.create(cr, uid, { |
1106 | + 'fiscal_position_id': fp_templ.id, |
1107 | 'update_chart_wizard_id': wizard.id, |
1108 | 'type': 'new', |
1109 | - }, context) |
1110 | - elif wizard.update_fiscal_position: |
1111 | - # Check the fiscal position for changes. |
1112 | - modified = False |
1113 | - notes = "" |
1114 | - fp = fiscalpositions.browse(cr, uid, fp_id, context=context) |
1115 | - |
1116 | - # Check fiscal position taxes for changes. |
1117 | - if fp_template.tax_ids and fp.tax_ids: |
1118 | - for fp_tax_template in fp_template.tax_ids: |
1119 | - found = False |
1120 | - for fp_tax in fp.tax_ids: |
1121 | - if fp_tax.tax_src_id.name == fp_tax_template.tax_src_id.name: |
1122 | - if fp_tax_template.tax_dest_id and fp_tax.tax_dest_id: |
1123 | - if fp_tax.tax_dest_id.name == fp_tax_template.tax_dest_id.name: |
1124 | - found = True |
1125 | - break |
1126 | - elif not fp_tax_template.tax_dest_id and not fp_tax.tax_dest_id: |
1127 | + 'notes': _('Name not found.'), |
1128 | + }, context=context) |
1129 | + continue |
1130 | + # Check the fiscal position for changes |
1131 | + modified = False |
1132 | + notes = "" |
1133 | + fp = fp_obj.browse(cr, uid, fp_id, context=context) |
1134 | + # Check fiscal position taxes for changes. |
1135 | + if fp_templ.tax_ids and fp.tax_ids: |
1136 | + for fp_tax_templ in fp_templ.tax_ids: |
1137 | + found = False |
1138 | + tax_src_id = self._map_tax_template(cr, uid, wizard, |
1139 | + tax_templ_mapping, |
1140 | + fp_tax_templ.tax_src_id, |
1141 | + context=None) |
1142 | + tax_dest_id = self._map_tax_template(cr, uid, wizard, |
1143 | + tax_templ_mapping, |
1144 | + fp_tax_templ.tax_dest_id, |
1145 | + context=None) |
1146 | + for fp_tax in fp.tax_ids: |
1147 | + if fp_tax.tax_src_id.id == tax_src_id: |
1148 | + if not fp_tax.tax_dest_id: |
1149 | + if not tax_dest_id: |
1150 | found = True |
1151 | break |
1152 | - if not found: |
1153 | - if fp_tax_template.tax_dest_id: |
1154 | - notes += _("Tax mapping not found on the fiscal position instance: %s -> %s.\n") % (fp_tax_template.tax_src_id.name, fp_tax_template.tax_dest_id.name) |
1155 | else: |
1156 | - notes += _("Tax mapping not found on the fiscal position instance: %s -> None.\n") % fp_tax_template.tax_src_id.name |
1157 | - modified = True |
1158 | - elif fp_template.tax_ids and not fp.tax_ids: |
1159 | - notes += _("The template has taxes the fiscal position instance does not.\n") |
1160 | - modified = True |
1161 | - |
1162 | - # Check fiscal position accounts for changes. |
1163 | - if fp_template.account_ids and fp.account_ids: |
1164 | - for fp_account_template in fp_template.account_ids: |
1165 | - found = False |
1166 | - for fp_account in fp.account_ids: |
1167 | - if fp_account.account_src_id.name == fp_account_template.account_src_id.name: |
1168 | - if fp_account.account_dest_id.name == fp_account_template.account_dest_id.name: |
1169 | + if fp_tax.tax_dest_id.id == tax_dest_id: |
1170 | found = True |
1171 | break |
1172 | - if not found: |
1173 | - notes += _("Account mapping not found on the fiscal position instance: %s -> %s.\n") % (fp_account_template.account_src_id.name, fp_account_template.account_dest_id.name) |
1174 | - modified = True |
1175 | - elif fp_template.account_ids and not fp.account_ids: |
1176 | - notes += _("The template has accounts the fiscal position instance does not.\n") |
1177 | - modified = True |
1178 | - |
1179 | - if modified: |
1180 | - # Fiscal position template to update. |
1181 | - updated_fps += 1 |
1182 | - wiz_fiscalpositions.create(cr, uid, { |
1183 | - 'fiscal_position_id': fp_template.id, |
1184 | - 'update_chart_wizard_id': wizard.id, |
1185 | - 'type': 'updated', |
1186 | - 'update_fiscal_position_id': fp_id, |
1187 | - 'notes': notes, |
1188 | - }, context) |
1189 | - |
1190 | - return {'new': new_fps, 'updated': updated_fps, 'mapping': fp_template_mapping} |
1191 | + if not found: |
1192 | + notes += _("Tax mapping not found on the fiscal position instance: %s -> %s.\n") % ( |
1193 | + fp_tax_templ.tax_src_id.name, |
1194 | + fp_tax_templ.tax_dest_id and fp_tax_templ.tax_dest_id.name or _('None')) |
1195 | + modified = True |
1196 | + elif fp_templ.tax_ids and not fp.tax_ids: |
1197 | + notes += _("The template has taxes the fiscal position instance does not.\n") |
1198 | + modified = True |
1199 | + # Check fiscal position accounts for changes |
1200 | + if fp_templ.account_ids and fp.account_ids: |
1201 | + for fp_acc_templ in fp_templ.account_ids: |
1202 | + found = False |
1203 | + acc_src_id = self._map_account_template( |
1204 | + cr, uid, wizard, acc_templ_mapping, |
1205 | + fp_acc_templ.account_src_id, context=context) |
1206 | + acc_dest_id = self._map_account_template( |
1207 | + cr, uid, wizard, acc_templ_mapping, |
1208 | + fp_acc_templ.account_dest_id, context=context) |
1209 | + for fp_acc in fp.account_ids: |
1210 | + if (fp_acc.account_src_id.id == acc_src_id and |
1211 | + fp_acc.account_dest_id.id == acc_dest_id): |
1212 | + found = True |
1213 | + break |
1214 | + if not found: |
1215 | + notes += _("Account mapping not found on the fiscal " |
1216 | + "position instance: %s -> %s.\n") % \ |
1217 | + (fp_acc_templ.account_src_id.name, |
1218 | + fp_acc_templ.account_dest_id.name) |
1219 | + modified = True |
1220 | + elif fp_templ.account_ids and not fp.account_ids: |
1221 | + notes += _("The template has accounts the fiscal position " |
1222 | + "instance does not.\n") |
1223 | + modified = True |
1224 | + if modified: |
1225 | + # Fiscal position template to update |
1226 | + updated_fps += 1 |
1227 | + wiz_fp.create(cr, uid, { |
1228 | + 'fiscal_position_id': fp_templ.id, |
1229 | + 'update_chart_wizard_id': wizard.id, |
1230 | + 'type': 'updated', |
1231 | + 'update_fiscal_position_id': fp_id, |
1232 | + 'notes': notes, |
1233 | + }, context=context) |
1234 | + return {'new': new_fps, 'updated': updated_fps, 'mapping': fp_templ_mapping} |
1235 | |
1236 | def action_find_records(self, cr, uid, ids, context=None): |
1237 | """ |
1238 | @@ -640,18 +701,34 @@ |
1239 | if context is None: |
1240 | context = {} |
1241 | wizard = self.browse(cr, uid, ids[0], context=context) |
1242 | - |
1243 | if wizard.lang: |
1244 | context['lang'] = wizard.lang |
1245 | elif context.get('lang'): |
1246 | del context['lang'] |
1247 | - |
1248 | + # Defaults when calculations are not done |
1249 | + tax_codes_res = {} |
1250 | + taxes_res = {} |
1251 | + accounts_res = {} |
1252 | + fps_res = {} |
1253 | + # Get all chart templates involved |
1254 | + wiz_obj = self.pool['wizard.multi.charts.accounts'] |
1255 | + chart_template_ids = wiz_obj._get_chart_parent_ids( |
1256 | + cr, uid, wizard.chart_template_id, context=context) |
1257 | # Search for, and load, the records to create/update. |
1258 | - tax_codes_res = self._find_tax_codes(cr, uid, wizard, context=context) |
1259 | - taxes_res = self._find_taxes(cr, uid, wizard, context=context) |
1260 | - accounts_res = self._find_accounts(cr, uid, wizard, context=context) |
1261 | - fps_res = self._find_fiscal_positions(cr, uid, wizard, context=context) |
1262 | - |
1263 | + if wizard.update_tax_code: |
1264 | + tax_codes_res = self._find_tax_codes(cr, uid, wizard, |
1265 | + chart_template_ids, |
1266 | + context=context) |
1267 | + if wizard.update_tax: |
1268 | + taxes_res = self._find_taxes(cr, uid, wizard, chart_template_ids, |
1269 | + context=context) |
1270 | + if wizard.update_account: |
1271 | + accounts_res = self._find_accounts(cr, uid, wizard, |
1272 | + context=context) |
1273 | + if wizard.update_fiscal_position: |
1274 | + fps_res = self._find_fiscal_positions(cr, uid, wizard, |
1275 | + chart_template_ids, |
1276 | + context=context) |
1277 | # Write the results, and go to the next step. |
1278 | self.write(cr, uid, [wizard.id], { |
1279 | 'state': 'ready', |
1280 | @@ -676,14 +753,14 @@ |
1281 | new_tax_codes = 0 |
1282 | updated_tax_codes = 0 |
1283 | tax_code_template_mapping = {} |
1284 | - |
1285 | for wiz_tax_code in wizard.tax_code_ids: |
1286 | tax_code_template = wiz_tax_code.tax_code_id |
1287 | tax_code_name = (root_tax_code_id == tax_code_template.id) and wizard.company_id.name or tax_code_template.name |
1288 | - |
1289 | # Ensure the parent tax code template is on the map. |
1290 | - self._map_tax_code_template(cr, uid, wizard, tax_code_template_mapping, tax_code_template.parent_id, context) |
1291 | - |
1292 | + self._map_tax_code_template(cr, uid, wizard, |
1293 | + tax_code_template_mapping, |
1294 | + tax_code_template.parent_id, |
1295 | + context=context) |
1296 | # Values |
1297 | vals = { |
1298 | 'name': tax_code_name, |
1299 | @@ -693,10 +770,8 @@ |
1300 | 'company_id': wizard.company_id.id, |
1301 | 'sign': tax_code_template.sign, |
1302 | } |
1303 | - |
1304 | tax_code_id = None |
1305 | modified = False |
1306 | - |
1307 | if wiz_tax_code.type == 'new': |
1308 | # Create the tax code |
1309 | tax_code_id = taxcodes.create(cr, uid, vals) |
1310 | @@ -713,15 +788,12 @@ |
1311 | else: |
1312 | tax_code_id = wiz_tax_code.update_tax_code_id and wiz_tax_code.update_tax_code_id.id |
1313 | modified = False |
1314 | - |
1315 | # Store the tax codes on the map |
1316 | tax_code_template_mapping[tax_code_template.id] = tax_code_id |
1317 | - |
1318 | if modified: |
1319 | # Detect errors |
1320 | if tax_code_template.parent_id and not tax_code_template_mapping.get(tax_code_template.parent_id.id): |
1321 | log.add(_("Tax code %s: The parent tax code %s can not be set.\n") % (tax_code_name, tax_code_template.parent_id.name), True) |
1322 | - |
1323 | return { |
1324 | 'new': new_tax_codes, |
1325 | 'updated': updated_tax_codes, |
1326 | @@ -732,20 +804,16 @@ |
1327 | """ |
1328 | Search for, and load, tax templates to create/update. |
1329 | """ |
1330 | - taxes = self.pool.get('account.tax') |
1331 | - |
1332 | + taxes = self.pool['account.tax'] |
1333 | new_taxes = 0 |
1334 | updated_taxes = 0 |
1335 | tax_template_mapping = {} |
1336 | taxes_pending_for_accounts = {} |
1337 | - |
1338 | for wiz_tax in wizard.tax_ids: |
1339 | tax_template = wiz_tax.tax_id |
1340 | - |
1341 | # Ensure the parent tax template is on the map. |
1342 | self._map_tax_template(cr, uid, wizard, tax_template_mapping, |
1343 | tax_template.parent_id, context) |
1344 | - |
1345 | # Ensure the referenced tax codes are on the map. |
1346 | tax_code_templates_to_find = [ |
1347 | tax_template.base_code_id, |
1348 | @@ -754,8 +822,9 @@ |
1349 | tax_template.ref_tax_code_id |
1350 | ] |
1351 | for tax_code_template in [tmpl for tmpl in tax_code_templates_to_find if tmpl]: |
1352 | - self._map_tax_code_template(cr, uid, wizard, tax_code_template_mapping, tax_code_template) |
1353 | - |
1354 | + self._map_tax_code_template(cr, uid, wizard, |
1355 | + tax_code_template_mapping, |
1356 | + tax_code_template, context=context) |
1357 | # Values |
1358 | vals_tax = { |
1359 | 'name': tax_template.name, |
1360 | @@ -783,10 +852,8 @@ |
1361 | 'company_id': wizard.company_id.id, |
1362 | 'type_tax_use': tax_template.type_tax_use |
1363 | } |
1364 | - |
1365 | tax_id = None |
1366 | modified = False |
1367 | - |
1368 | if wiz_tax.type == 'new': |
1369 | # Create a new tax. |
1370 | tax_id = taxes.create(cr, uid, vals_tax) |
1371 | @@ -802,17 +869,14 @@ |
1372 | modified = True |
1373 | else: |
1374 | tax_id = wiz_tax.update_tax_id and wiz_tax.update_tax_id.id |
1375 | - |
1376 | # Update the tax template map |
1377 | tax_template_mapping[tax_template.id] = tax_id |
1378 | - |
1379 | if modified: |
1380 | # Add to the dict of taxes waiting for accounts. |
1381 | taxes_pending_for_accounts[tax_id] = { |
1382 | 'account_collected_id': tax_template.account_collected_id and tax_template.account_collected_id.id or False, |
1383 | 'account_paid_id': tax_template.account_paid_id and tax_template.account_paid_id.id or False, |
1384 | } |
1385 | - |
1386 | # Detect errors |
1387 | if tax_template.parent_id and not tax_template_mapping.get(tax_template.parent_id.id): |
1388 | log.add(_("Tax %s: The parent tax %s can not be set.\n") % (tax_template.name, tax_template.parent_id.name), True) |
1389 | @@ -824,7 +888,6 @@ |
1390 | log.add(_("Tax %s: The tax code for the base refund %s can not be set.\n") % (tax_template.name, tax_template.ref_base_code_id.name), True) |
1391 | if tax_template.ref_tax_code_id and not tax_code_template_mapping.get(tax_template.ref_tax_code_id.id): |
1392 | log.add(_("Tax %s: The tax code for the tax refund %s can not be set.\n") % (tax_template.name, tax_template.ref_tax_code_id.name), True) |
1393 | - |
1394 | return { |
1395 | 'new': new_taxes, |
1396 | 'updated': updated_taxes, |
1397 | @@ -867,28 +930,22 @@ |
1398 | """ |
1399 | accounts = self.pool.get('account.account') |
1400 | root_account_id = wizard.chart_template_id.account_root_id.id |
1401 | - |
1402 | # Disable the parent_store computing on account_account during the batch |
1403 | # processing, we will force _parent_store_compute afterwards. |
1404 | self.pool._init = True |
1405 | new_accounts = 0 |
1406 | updated_accounts = 0 |
1407 | account_template_mapping = {} |
1408 | - |
1409 | for wiz_account in wizard.account_ids: |
1410 | account_template = wiz_account.account_id |
1411 | - |
1412 | # Ensure the parent account template is on the map. |
1413 | self._map_account_template(cr, uid, wizard, account_template_mapping, account_template.parent_id, context) |
1414 | - |
1415 | # Ensure the related tax templates are on the map. |
1416 | for tax_template in account_template.tax_ids: |
1417 | self._map_tax_template(cr, uid, wizard, tax_template_mapping, |
1418 | tax_template, context) |
1419 | - |
1420 | # Get the tax ids |
1421 | tax_ids = [tax_template_mapping[tax_template.id] for tax_template in account_template.tax_ids if tax_template_mapping[tax_template.id]] |
1422 | - |
1423 | # Calculate the account code (we need to add zeros to non-view |
1424 | # account codes) |
1425 | code = account_template.code or '' |
1426 | @@ -896,7 +953,6 @@ |
1427 | if len(code) > 0 and len(code) <= wizard.code_digits: |
1428 | code = '%s%s' % ( |
1429 | code, '0' * (wizard.code_digits - len(code))) |
1430 | - |
1431 | # Values |
1432 | vals = { |
1433 | 'name': (root_account_id == account_template.id) and wizard.company_id.name or account_template.name, |
1434 | @@ -912,10 +968,8 @@ |
1435 | 'tax_ids': [(6, 0, tax_ids)], |
1436 | 'company_id': wizard.company_id.id, |
1437 | } |
1438 | - |
1439 | account_id = None |
1440 | modified = False |
1441 | - |
1442 | if wiz_account.type == 'new': |
1443 | # Create the account |
1444 | try: |
1445 | @@ -939,68 +993,65 @@ |
1446 | % (code, ex.name, ex.value), True) |
1447 | else: |
1448 | account_id = wiz_account.update_account_id and wiz_account.update_account_id.id |
1449 | - |
1450 | # Store the account on the map |
1451 | account_template_mapping[account_template.id] = account_id |
1452 | - |
1453 | if modified: |
1454 | # Detect errors |
1455 | if account_template.parent_id and not account_template_mapping.get(account_template.parent_id.id): |
1456 | log.add(_("Account %s: The parent account %s can not be set.\n") % (code, account_template.parent_id.code), True) |
1457 | - |
1458 | # Set this account as the parent of the accounts that seem to |
1459 | # be its children (brothers starting with the same code). |
1460 | if wizard.update_children_accounts_parent: |
1461 | self._update_children_accounts_parent( |
1462 | cr, uid, wizard, log, account_id, context=context) |
1463 | - |
1464 | # Reenable the parent_store computing on account_account |
1465 | # and force the recomputation. |
1466 | self.pool._init = False |
1467 | self.pool.get('account.account')._parent_store_compute(cr) |
1468 | - |
1469 | return { |
1470 | 'new': new_accounts, |
1471 | 'updated': updated_accounts, |
1472 | 'mapping': account_template_mapping |
1473 | } |
1474 | |
1475 | - def _update_taxes_pending_for_accounts(self, cr, uid, wizard, log, taxes_pending_for_accounts, account_template_mapping, context=None): |
1476 | + def _update_taxes_pending_for_accounts(self, cr, uid, wizard, log, |
1477 | + taxes_pending_for_accounts, |
1478 | + acc_templ_mapping, context=None): |
1479 | """ |
1480 | Updates the taxes (created or updated on previous steps) to set |
1481 | the references to the accounts (the taxes where created/updated first, |
1482 | when the referenced accounts where still not available). |
1483 | """ |
1484 | - taxes = self.pool.get('account.tax') |
1485 | - accounts_template = self.pool.get('account.account.template') |
1486 | - |
1487 | + taxes = self.pool['account.tax'] |
1488 | + accounts_template = self.pool['account.account.template'] |
1489 | for key, value in taxes_pending_for_accounts.items(): |
1490 | # Ensure the related account templates are on the map. |
1491 | if value['account_collected_id']: |
1492 | - account_template = accounts_template.browse( |
1493 | + acc_templ = accounts_template.browse( |
1494 | cr, uid, value['account_collected_id'], context=context) |
1495 | - self._map_account_template(cr, uid, wizard, account_template_mapping, account_template, context) |
1496 | + self._map_account_template(cr, uid, wizard, acc_templ_mapping, |
1497 | + acc_templ, context=context) |
1498 | if value['account_paid_id']: |
1499 | - account_template = accounts_template.browse( |
1500 | + acc_templ = accounts_template.browse( |
1501 | cr, uid, value['account_paid_id'], context=context) |
1502 | - self._map_account_template(cr, uid, wizard, account_template_mapping, account_template, context) |
1503 | - |
1504 | + self._map_account_template(cr, uid, wizard, acc_templ_mapping, |
1505 | + acc_templ, context=context) |
1506 | if value['account_collected_id'] or value['account_paid_id']: |
1507 | - if account_template_mapping.get(value['account_collected_id']) and account_template_mapping.get(value['account_paid_id']): |
1508 | + if acc_templ_mapping.get(value['account_collected_id']) and acc_templ_mapping.get(value['account_paid_id']): |
1509 | vals = { |
1510 | - 'account_collected_id': account_template_mapping[value['account_collected_id']], |
1511 | - 'account_paid_id': account_template_mapping[value['account_paid_id']], |
1512 | + 'account_collected_id': acc_templ_mapping[value['account_collected_id']], |
1513 | + 'account_paid_id': acc_templ_mapping[value['account_paid_id']], |
1514 | } |
1515 | taxes.write(cr, uid, [key], vals) |
1516 | else: |
1517 | tax = taxes.browse(cr, uid, key) |
1518 | - if not account_template_mapping.get(value['account_collected_id']): |
1519 | + if not acc_templ_mapping.get(value['account_collected_id']): |
1520 | log.add(_("Tax %s: The collected account can not be set.\n") % (tax.name), True) |
1521 | - if not account_template_mapping.get(value['account_paid_id']): |
1522 | + if not acc_templ_mapping.get(value['account_paid_id']): |
1523 | log.add(_("Tax %s: The paid account can not be set.\n") |
1524 | % (tax.name), True) |
1525 | |
1526 | - def _update_fiscal_positions(self, cr, uid, wizard, log, tax_template_mapping, account_template_mapping, context=None): |
1527 | + def _update_fiscal_positions(self, cr, uid, wizard, log, tax_template_mapping, acc_templ_mapping, context=None): |
1528 | """ |
1529 | Search for, and load, fiscal position templates to create/update. |
1530 | """ |
1531 | @@ -1063,20 +1114,26 @@ |
1532 | # (Re)create the account mappings |
1533 | for fp_account in fp_template.account_ids: |
1534 | # Ensure the related account templates are on the map. |
1535 | - self._map_account_template(cr, uid, wizard, account_template_mapping, fp_account.account_src_id, context) |
1536 | + self._map_account_template(cr, uid, wizard, |
1537 | + acc_templ_mapping, |
1538 | + fp_account.account_src_id, |
1539 | + context=context) |
1540 | if fp_account.account_dest_id: |
1541 | - self._map_account_template(cr, uid, wizard, account_template_mapping, fp_account.account_dest_id, context) |
1542 | + self._map_account_template(cr, uid, wizard, |
1543 | + acc_templ_mapping, |
1544 | + fp_account.account_dest_id, |
1545 | + context=context) |
1546 | # Create the fp account mapping |
1547 | vals_account = { |
1548 | - 'account_src_id': account_template_mapping.get(fp_account.account_src_id.id), |
1549 | - 'account_dest_id': fp_account.account_dest_id and account_template_mapping.get(fp_account.account_dest_id.id), |
1550 | + 'account_src_id': acc_templ_mapping.get(fp_account.account_src_id.id), |
1551 | + 'account_dest_id': fp_account.account_dest_id and acc_templ_mapping.get(fp_account.account_dest_id.id), |
1552 | 'position_id': fp_id, |
1553 | } |
1554 | fiscalpositions_account.create(cr, uid, vals_account) |
1555 | # Check for errors |
1556 | - if not account_template_mapping.get(fp_account.account_src_id.id): |
1557 | + if not acc_templ_mapping.get(fp_account.account_src_id.id): |
1558 | log.add(_("Fiscal position %s: The source account %s can not be set.\n") % (fp_template.name, fp_account.account_src_id.code), True) |
1559 | - if fp_account.account_dest_id and not account_template_mapping.get(fp_account.account_dest_id.id): |
1560 | + if fp_account.account_dest_id and not acc_templ_mapping.get(fp_account.account_dest_id.id): |
1561 | log.add(_("Fiscal position %s: The destination account %s can not be set.\n") % (fp_template.name, fp_account.account_dest_id.code), True) |
1562 | |
1563 | log.add(_("Created or updated fiscal position %s.\n") |
1564 | @@ -1090,29 +1147,42 @@ |
1565 | if context is None: |
1566 | context = {} |
1567 | wizard = self.browse(cr, uid, ids[0], context=context) |
1568 | - |
1569 | if wizard.lang: |
1570 | context['lang'] = wizard.lang |
1571 | elif context.get('lang'): |
1572 | del context['lang'] |
1573 | - |
1574 | log = WizardLog() |
1575 | - |
1576 | + # Defaults when calculations are not done |
1577 | + tax_codes_res = {'mapping': {}} |
1578 | + taxes_res = {'mapping': {}, 'pending': {}} |
1579 | + accounts_res = {'mapping': {}} |
1580 | + fps_res = {} |
1581 | # Create or update the records. |
1582 | - tax_codes_res = self._update_tax_codes( |
1583 | - cr, uid, wizard, log, context=context) |
1584 | - taxes_res = self._update_taxes( |
1585 | - cr, uid, wizard, log, tax_codes_res['mapping'], context=context) |
1586 | - accounts_res = self._update_accounts( |
1587 | - cr, uid, wizard, log, taxes_res['mapping'], context=context) |
1588 | - self._update_taxes_pending_for_accounts(cr, uid, wizard, log, taxes_res['pending'], accounts_res['mapping'], context=context) |
1589 | - fps_res = self._update_fiscal_positions(cr, uid, wizard, log, taxes_res['mapping'], accounts_res['mapping'], context=context) |
1590 | - |
1591 | + if wizard.update_tax_code: |
1592 | + tax_codes_res = self._update_tax_codes(cr, uid, wizard, log, |
1593 | + context=context) |
1594 | + if wizard.update_tax: |
1595 | + taxes_res = self._update_taxes(cr, uid, wizard, log, |
1596 | + tax_codes_res['mapping'], |
1597 | + context=context) |
1598 | + if wizard.update_account: |
1599 | + accounts_res = self._update_accounts(cr, uid, wizard, log, |
1600 | + taxes_res['mapping'], |
1601 | + context=context) |
1602 | + if wizard.update_tax and wizard.update_account: |
1603 | + self._update_taxes_pending_for_accounts(cr, uid, wizard, log, |
1604 | + taxes_res['pending'], |
1605 | + accounts_res['mapping'], |
1606 | + context=context) |
1607 | + if wizard.update_fiscal_position: |
1608 | + fps_res = self._update_fiscal_positions(cr, uid, wizard, log, |
1609 | + taxes_res['mapping'], |
1610 | + accounts_res['mapping'], |
1611 | + context=context) |
1612 | # Check if errors where detected and wether we should stop. |
1613 | if log.has_errors() and not wizard.continue_on_errors: |
1614 | raise orm.except_orm(_('Error'), _( |
1615 | "One or more errors detected!\n\n%s") % log.get_errors_str()) |
1616 | - |
1617 | # Store the data and go to the next step. |
1618 | self.write(cr, uid, [wizard.id], { |
1619 | 'state': 'done', |
1620 | @@ -1125,8 +1195,7 @@ |
1621 | 'updated_accounts': accounts_res.get('updated', 0), |
1622 | 'updated_fps': fps_res.get('updated', 0), |
1623 | 'log': log(), |
1624 | - }, context) |
1625 | - |
1626 | + }, context=context) |
1627 | return _reopen(self, wizard.id, 'wizard.update.chart.accounts') |
1628 | |
1629 | |
1630 | |
1631 | === modified file 'account_chart_update/wizard/wizard_chart_update_view.xml' |
1632 | --- account_chart_update/wizard/wizard_chart_update_view.xml 2013-10-15 14:28:59 +0000 |
1633 | +++ account_chart_update/wizard/wizard_chart_update_view.xml 2014-05-20 00:05:21 +0000 |
1634 | @@ -23,7 +23,9 @@ |
1635 | <field name="company_id" on_change="onchange_company_id(company_id)" |
1636 | attrs="{'invisible':[('state','!=','init')]}" /> |
1637 | <field name="code_digits" attrs="{'invisible':[('state','!=','init')]}" /> |
1638 | - <field name="chart_template_id" attrs="{'invisible':[('state','!=','init')]}" /> |
1639 | + <field name="chart_template_id" |
1640 | + domain="[('visible', '=', True)]" |
1641 | + attrs="{'invisible': [('state','!=','init')], 'required': True}"/> |
1642 | <field name="lang" attrs="{'invisible':[('state','!=','init')]}" /> |
1643 | </group> |
1644 | <group attrs="{'invisible':[('state','!=','init')]}"> |
1645 | @@ -48,73 +50,45 @@ |
1646 | <group attrs="{'invisible':[('state','!=','ready'),]}" |
1647 | string="Records to create/update"> |
1648 | <notebook colspan="4"> |
1649 | - <page string="Tax codes"> |
1650 | + <page string="Tax codes" attrs="{'invisible': [('update_tax_code', '=', False)]}"> |
1651 | <field name="tax_code_ids"> |
1652 | <tree string="Tax codes" colors="red:type=='updated'"> |
1653 | <field name="tax_code_id" /> |
1654 | <field name="update_tax_code_id" /> |
1655 | + <field name="notes" readonly="1" /> |
1656 | <field name="type" invisible="1" /> |
1657 | </tree> |
1658 | - <form string="Tax code" version="7.0"> |
1659 | - <group> |
1660 | - <field name="tax_code_id" /> |
1661 | - <field name="type" /> |
1662 | - <field name="update_tax_code_id" /> |
1663 | - <field name="notes" readonly="1" class="oe_inline" /> |
1664 | - </group> |
1665 | - </form> |
1666 | </field> |
1667 | </page> |
1668 | |
1669 | - <page string="Taxes"> |
1670 | + <page string="Taxes" attrs="{'invisible': [('update_tax', '=', False)]}"> |
1671 | <field name="tax_ids" nolabel="1"> |
1672 | <tree string="Taxes" colors="red:type=='updated'"> |
1673 | <field name="tax_id" /> |
1674 | <field name="update_tax_id" /> |
1675 | + <field name="notes" readonly="1"/> |
1676 | <field name="type" invisible="1" /> |
1677 | </tree> |
1678 | - <form string="Tax" version="7.0"> |
1679 | - <group> |
1680 | - <field name="tax_id" /> |
1681 | - <field name="type" /> |
1682 | - <field name="update_tax_id" /> |
1683 | - <field name="notes" readonly="1" class="oe_inline" /> |
1684 | - </group> |
1685 | - </form> |
1686 | </field> |
1687 | </page> |
1688 | - <page string="Accounts"> |
1689 | + <page string="Accounts" attrs="{'invisible': [('update_account', '=', False)]}"> |
1690 | <field name="account_ids" nolabel="1"> |
1691 | <tree string="Accounts" colors="red:type=='updated'"> |
1692 | <field name="account_id" /> |
1693 | <field name="update_account_id" /> |
1694 | + <field name="notes" readonly="1"/> |
1695 | <field name="type" invisible="1" /> |
1696 | </tree> |
1697 | - <form string="Account" version="7.0"> |
1698 | - <group> |
1699 | - <field name="account_id" /> |
1700 | - <field name="type" /> |
1701 | - <field name="update_account_id" /> |
1702 | - <field name="notes" readonly="1" class="oe_inline" /> |
1703 | - </group> |
1704 | - </form> |
1705 | </field> |
1706 | </page> |
1707 | - <page string="Fiscal positions"> |
1708 | + <page string="Fiscal positions" attrs="{'invisible': [('update_fiscal_position', '=', False)]}"> |
1709 | <field name="fiscal_position_ids" nolabel="1"> |
1710 | <tree string="Fiscal positions" colors="red:type=='updated'"> |
1711 | <field name="fiscal_position_id" /> |
1712 | <field name="update_fiscal_position_id" /> |
1713 | + <field name="notes" readonly="1" /> |
1714 | <field name="type" invisible="1" /> |
1715 | </tree> |
1716 | - <form string="Fiscal position" version="7.0"> |
1717 | - <group> |
1718 | - <field name="fiscal_position_id" /> |
1719 | - <field name="type" /> |
1720 | - <field name="update_fiscal_position_id" /> |
1721 | - <field name="notes" readonly="1" class="oe_inline" /> |
1722 | - </group> |
1723 | - </form> |
1724 | </field> |
1725 | </page> |
1726 | |
1727 | @@ -153,6 +127,9 @@ |
1728 | or |
1729 | <button special="cancel" string="Cancel" class="oe_link" /> |
1730 | </div> |
1731 | + <div states="done"> |
1732 | + <button special="cancel" string="Close" class="oe_link" /> |
1733 | + </div> |
1734 | </footer> |
1735 | </form> |
1736 | </field> |
LGTM