Merge lp:~pedro.baeza/account-financial-tools/7.0-account_chart_update-enhanced into lp:~account-core-editors/account-financial-tools/7.0

Proposed by Pedro Manuel Baeza
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
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_chart_update: Selection of operations to do now is working.
[FIX] account_chart_update: Adapted to work with inherited account chart templates.
[FIX] account_chart_update: Remove required=True for chart_template_id on DB and put on screen to avoid error when removing chart templates.
[FIX] account_chart_update: Change method to compare taxes of fiscal positions to match with the one comparing taxes.
[FIX] account_chart_update: Change method to compare accounts of fiscal positions to match with the one comparing accounts.
[IMP] account_chart_update: Wizard now shows in tree view modification notes.
[IMP] account_chart_update: For new data to be created, it is marked on notes the reason for the creation (just for clarity).
[IMP] account_chart_update: Tabs for operations that are not going to be performed are hidden.
[IMP] account_chart_update: Some PEP8 here and there.
[IMP] account_chart_update: Enhance a little the mapping searches (there's more room to improve).
[IMP] account_chart_update: Now it takes into account name and description for mapping taxes.

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.

To post a comment you must log in.
Revision history for this message
PabloCM (pablocm) wrote :

LGTM

review: Approve (usage)
Revision history for this message
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_code_template
_find_tax_codes
_find_accounts

There are some missing context:
l.1332
l.1341
l.1516
l.1646
l.2031

review: Needs Fixing (code review, no test)
168. By Pedro Manuel Baeza

Some comments from Yannick's review

Revision history for this message
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.

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

s/required=True from fill/required=True from wizard

Revision history for this message
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_code_template
_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

review: Needs Fixing
169. By Pedro Manuel Baeza

Last fixes from reviews

170. By Pedro Manuel Baeza

Translation updated for avoiding conflicts

Revision history for this message
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.

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

Seems fine that way ondelete="cascade" seems also a better choice.

Thanks!

LGTM

review: Approve (code review, no test)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'account_chart_update/i18n/account_chart_update.pot'
--- account_chart_update/i18n/account_chart_update.pot 2013-10-15 14:19:18 +0000
+++ account_chart_update/i18n/account_chart_update.pot 2014-05-20 00:05:21 +0000
@@ -6,8 +6,8 @@
6msgstr ""6msgstr ""
7"Project-Id-Version: OpenERP Server 7.0\n"7"Project-Id-Version: OpenERP Server 7.0\n"
8"Report-Msgid-Bugs-To: \n"8"Report-Msgid-Bugs-To: \n"
9"POT-Creation-Date: 2013-10-15 14:01+0000\n"9"POT-Creation-Date: 2014-03-21 00:56+0000\n"
10"PO-Revision-Date: 2013-10-15 14:01+0000\n"10"PO-Revision-Date: 2014-03-21 00:56+0000\n"
11"Last-Translator: <>\n"11"Last-Translator: <>\n"
12"Language-Team: \n"12"Language-Team: \n"
13"MIME-Version: 1.0\n"13"MIME-Version: 1.0\n"
@@ -26,18 +26,13 @@
26msgstr ""26msgstr ""
2727
28#. module: account_chart_update28#. module: account_chart_update
29#: code:addons/account_chart_update/wizard/wizard_chart_update.py:36829#: code:addons/account_chart_update/wizard/wizard_chart_update.py:382
30#, python-format30#, python-format
31msgid "The code field is different.\n"31msgid "The code field is different.\n"
32""32""
33msgstr ""33msgstr ""
3434
35#. module: account_chart_update35#. module: account_chart_update
36#: view:wizard.update.charts.accounts:0
37msgid "Fiscal position"
38msgstr ""
39
40#. module: account_chart_update
41#: field:wizard.update.charts.accounts,update_children_accounts_parent:036#: field:wizard.update.charts.accounts,update_children_accounts_parent:0
42msgid "Update children accounts parent"37msgid "Update children accounts parent"
43msgstr ""38msgstr ""
@@ -48,22 +43,22 @@
48msgstr ""43msgstr ""
4944
50#. module: account_chart_update45#. module: account_chart_update
51#: code:addons/account_chart_update/wizard/wizard_chart_update.py:71646#: code:addons/account_chart_update/wizard/wizard_chart_update.py:769
52#, python-format47#, python-format
53msgid "Created tax code %s.\n"48msgid "Created tax code %s.\n"
54""49""
55msgstr ""50msgstr ""
5651
57#. module: account_chart_update52#. module: account_chart_update
58#: code:addons/account_chart_update/wizard/wizard_chart_update.py:101253#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1038
59#, python-format54#, python-format
60msgid "Tax %s: The collected account can not be set.\n"55msgid "Tax %s: The collected account can not be set.\n"
61""56""
62msgstr ""57msgstr ""
6358
64#. module: account_chart_update59#. module: account_chart_update
65#: field:wizard.update.charts.accounts,new_accounts:060#: view:wizard.update.charts.accounts:0
66msgid "New accounts"61msgid "or"
67msgstr ""62msgstr ""
6863
69#. module: account_chart_update64#. module: account_chart_update
@@ -80,14 +75,14 @@
80msgstr ""75msgstr ""
8176
82#. module: account_chart_update77#. module: account_chart_update
83#: code:addons/account_chart_update/wizard/wizard_chart_update.py:107678#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1102
84#, python-format79#, python-format
85msgid "Fiscal position %s: The destination tax %s can not be set.\n"80msgid "Fiscal position %s: The destination tax %s can not be set.\n"
86""81""
87msgstr ""82msgstr ""
8883
89#. module: account_chart_update84#. module: account_chart_update
90#: code:addons/account_chart_update/wizard/wizard_chart_update.py:83985#: code:addons/account_chart_update/wizard/wizard_chart_update.py:881
91#, python-format86#, python-format
92msgid "Tax %s: The tax code for the tax refund %s can not be set.\n"87msgid "Tax %s: The tax code for the tax refund %s can not be set.\n"
93""88""
@@ -104,7 +99,7 @@
104msgstr ""99msgstr ""
105100
106#. module: account_chart_update101#. module: account_chart_update
107#: code:addons/account_chart_update/wizard/wizard_chart_update.py:617102#: code:addons/account_chart_update/wizard/wizard_chart_update.py:651
108#, python-format103#, python-format
109msgid "The template has taxes the fiscal position instance does not.\n"104msgid "The template has taxes the fiscal position instance does not.\n"
110""105""
@@ -116,11 +111,6 @@
116msgstr ""111msgstr ""
117112
118#. module: account_chart_update113#. module: account_chart_update
119#: view:wizard.update.charts.accounts:0
120msgid "Account"
121msgstr ""
122
123#. module: account_chart_update
124#: field:wizard.update.charts.accounts.account,notes:0114#: field:wizard.update.charts.accounts.account,notes:0
125#: field:wizard.update.charts.accounts.fiscal.position,notes:0115#: field:wizard.update.charts.accounts.fiscal.position,notes:0
126#: field:wizard.update.charts.accounts.tax,notes:0116#: field:wizard.update.charts.accounts.tax,notes:0
@@ -135,7 +125,7 @@
135msgstr ""125msgstr ""
136126
137#. module: account_chart_update127#. module: account_chart_update
138#: code:addons/account_chart_update/wizard/wizard_chart_update.py:371128#: code:addons/account_chart_update/wizard/wizard_chart_update.py:385
139#, python-format129#, python-format
140msgid "The info field is different.\n"130msgid "The info field is different.\n"
141""131""
@@ -147,7 +137,7 @@
147msgstr ""137msgstr ""
148138
149#. module: account_chart_update139#. module: account_chart_update
150#: code:addons/account_chart_update/wizard/wizard_chart_update.py:723140#: code:addons/account_chart_update/wizard/wizard_chart_update.py:776
151#, python-format141#, python-format
152msgid "Updated tax code %s.\n"142msgid "Updated tax code %s.\n"
153""143""
@@ -164,22 +154,22 @@
164msgstr ""154msgstr ""
165155
166#. module: account_chart_update156#. module: account_chart_update
167#: code:addons/account_chart_update/wizard/wizard_chart_update.py:806157#: code:addons/account_chart_update/wizard/wizard_chart_update.py:851
168#, python-format158#, python-format
169msgid "Created tax %s.\n"159msgid "Created tax %s.\n"
170""160""
171msgstr ""161msgstr ""
172162
173#. module: account_chart_update163#. module: account_chart_update
164#: code:addons/account_chart_update/wizard/wizard_chart_update.py:477
165#, python-format
166msgid "The base sign field is different.\n"
167""
168msgstr ""
169
170#. module: account_chart_update
174#: code:addons/account_chart_update/wizard/wizard_chart_update.py:459171#: code:addons/account_chart_update/wizard/wizard_chart_update.py:459
175#, python-format172#, python-format
176msgid "The base sign field is different.\n"
177""
178msgstr ""
179
180#. module: account_chart_update
181#: code:addons/account_chart_update/wizard/wizard_chart_update.py:441
182#, python-format
183msgid "The type field is different.\n"173msgid "The type field is different.\n"
184""174""
185msgstr ""175msgstr ""
@@ -196,14 +186,14 @@
196msgstr ""186msgstr ""
197187
198#. module: account_chart_update188#. module: account_chart_update
199#: code:addons/account_chart_update/wizard/wizard_chart_update.py:835189#: code:addons/account_chart_update/wizard/wizard_chart_update.py:877
200#, python-format190#, python-format
201msgid "Tax %s: The tax code for the tax %s can not be set.\n"191msgid "Tax %s: The tax code for the tax %s can not be set.\n"
202""192""
203msgstr ""193msgstr ""
204194
205#. module: account_chart_update195#. module: account_chart_update
206#: code:addons/account_chart_update/wizard/wizard_chart_update.py:612196#: code:addons/account_chart_update/wizard/wizard_chart_update.py:646
207#, python-format197#, python-format
208msgid "Tax mapping not found on the fiscal position instance: %s -> %s.\n"198msgid "Tax mapping not found on the fiscal position instance: %s -> %s.\n"
209""199""
@@ -221,11 +211,6 @@
221211
222#. module: account_chart_update212#. module: account_chart_update
223#: view:wizard.update.charts.accounts:0213#: view:wizard.update.charts.accounts:0
224msgid "Tax"
225msgstr ""
226
227#. module: account_chart_update
228#: view:wizard.update.charts.accounts:0
229msgid "Next"214msgid "Next"
230msgstr ""215msgstr ""
231216
@@ -243,7 +228,7 @@
243msgstr ""228msgstr ""
244229
245#. module: account_chart_update230#. module: account_chart_update
246#: code:addons/account_chart_update/wizard/wizard_chart_update.py:435231#: code:addons/account_chart_update/wizard/wizard_chart_update.py:453
247#, python-format232#, python-format
248msgid "The sequence field is different.\n"233msgid "The sequence field is different.\n"
249""234""
@@ -255,7 +240,7 @@
255msgstr ""240msgstr ""
256241
257#. module: account_chart_update242#. module: account_chart_update
258#: code:addons/account_chart_update/wizard/wizard_chart_update.py:630243#: code:addons/account_chart_update/wizard/wizard_chart_update.py:671
259#, python-format244#, python-format
260msgid "Account mapping not found on the fiscal position instance: %s -> %s.\n"245msgid "Account mapping not found on the fiscal position instance: %s -> %s.\n"
261""246""
@@ -280,7 +265,7 @@
280msgstr ""265msgstr ""
281266
282#. module: account_chart_update267#. module: account_chart_update
283#: code:addons/account_chart_update/wizard/wizard_chart_update.py:465268#: code:addons/account_chart_update/wizard/wizard_chart_update.py:483
284#, python-format269#, python-format
285msgid "The include base amount field is different.\n"270msgid "The include base amount field is different.\n"
286""271""
@@ -292,7 +277,7 @@
292msgstr ""277msgstr ""
293278
294#. module: account_chart_update279#. module: account_chart_update
295#: code:addons/account_chart_update/wizard/wizard_chart_update.py:633280#: code:addons/account_chart_update/wizard/wizard_chart_update.py:674
296#, python-format281#, python-format
297msgid "The template has accounts the fiscal position instance does not.\n"282msgid "The template has accounts the fiscal position instance does not.\n"
298""283""
@@ -309,7 +294,7 @@
309msgstr ""294msgstr ""
310295
311#. module: account_chart_update296#. module: account_chart_update
312#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1014297#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1040
313#, python-format298#, python-format
314msgid "Tax %s: The paid account can not be set.\n"299msgid "Tax %s: The paid account can not be set.\n"
315""300""
@@ -322,7 +307,7 @@
322msgstr ""307msgstr ""
323308
324#. module: account_chart_update309#. module: account_chart_update
325#: code:addons/account_chart_update/wizard/wizard_chart_update.py:941310#: code:addons/account_chart_update/wizard/wizard_chart_update.py:972
326#, python-format311#, python-format
327msgid "Exception creating account %s: %s - %s.\n"312msgid "Exception creating account %s: %s - %s.\n"
328""313""
@@ -334,39 +319,51 @@
334msgstr ""319msgstr ""
335320
336#. module: account_chart_update321#. module: account_chart_update
337#: code:addons/account_chart_update/wizard/wizard_chart_update.py:453322#: code:addons/account_chart_update/wizard/wizard_chart_update.py:471
338#, python-format323#, python-format
339msgid "The python compute field is different.\n"324msgid "The python compute field is different.\n"
340""325""
341msgstr ""326msgstr ""
342327
343#. module: account_chart_update328#. module: account_chart_update
329#: code:addons/account_chart_update/wizard/wizard_chart_update.py:648
330#, python-format
331msgid "None"
332msgstr ""
333
334#. module: account_chart_update
344#: model:ir.model,name:account_chart_update.model_wizard_update_charts_accounts_tax_code335#: model:ir.model,name:account_chart_update.model_wizard_update_charts_accounts_tax_code
345msgid "wizard.update.charts.accounts.tax.code"336msgid "wizard.update.charts.accounts.tax.code"
346msgstr ""337msgstr ""
347338
348#. module: account_chart_update339#. module: account_chart_update
349#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1092340#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1124
350#, python-format341#, python-format
351msgid "Fiscal position %s: The source account %s can not be set.\n"342msgid "Fiscal position %s: The source account %s can not be set.\n"
352""343""
353msgstr ""344msgstr ""
354345
355#. module: account_chart_update346#. module: account_chart_update
356#: code:addons/account_chart_update/wizard/wizard_chart_update.py:833347#: code:addons/account_chart_update/wizard/wizard_chart_update.py:875
357#, python-format348#, python-format
358msgid "Tax %s: The tax code for the base %s can not be set.\n"349msgid "Tax %s: The tax code for the base %s can not be set.\n"
359""350""
360msgstr ""351msgstr ""
361352
362#. module: account_chart_update353#. module: account_chart_update
363#: code:addons/account_chart_update/wizard/wizard_chart_update.py:952354#: code:addons/account_chart_update/wizard/wizard_chart_update.py:983
364#, python-format355#, python-format
365msgid "Exception writing account %s: %s - %s.\n"356msgid "Exception writing account %s: %s - %s.\n"
366""357""
367msgstr ""358msgstr ""
368359
369#. module: account_chart_update360#. module: account_chart_update
361#: code:addons/account_chart_update/wizard/wizard_chart_update.py:543
362#, python-format
363msgid "Code not found."
364msgstr ""
365
366#. module: account_chart_update
370#: view:wizard.update.charts.accounts:0367#: view:wizard.update.charts.accounts:0
371msgid "Note: Not all the fields are tested for changes, just the main ones"368msgid "Note: Not all the fields are tested for changes, just the main ones"
372msgstr ""369msgstr ""
@@ -377,18 +374,13 @@
377msgstr ""374msgstr ""
378375
379#. module: account_chart_update376#. module: account_chart_update
380#: view:wizard.update.charts.accounts:0377#: code:addons/account_chart_update/wizard/wizard_chart_update.py:441
381msgid "or"
382msgstr ""
383
384#. module: account_chart_update
385#: code:addons/account_chart_update/wizard/wizard_chart_update.py:250
386#, python-format378#, python-format
387msgid "Update Chart of Accounts from a Chart Template "379msgid "Name or description not found."
388msgstr ""380msgstr ""
389381
390#. module: account_chart_update382#. module: account_chart_update
391#: code:addons/account_chart_update/wizard/wizard_chart_update.py:531383#: code:addons/account_chart_update/wizard/wizard_chart_update.py:551
392#, python-format384#, python-format
393msgid "The name is different.\n"385msgid "The name is different.\n"
394""386""
@@ -400,28 +392,28 @@
400msgstr ""392msgstr ""
401393
402#. module: account_chart_update394#. module: account_chart_update
403#: code:addons/account_chart_update/wizard/wizard_chart_update.py:736395#: code:addons/account_chart_update/wizard/wizard_chart_update.py:787
404#, python-format396#, python-format
405msgid "Tax code %s: The parent tax code %s can not be set.\n"397msgid "Tax code %s: The parent tax code %s can not be set.\n"
406""398""
407msgstr ""399msgstr ""
408400
409#. module: account_chart_update401#. module: account_chart_update
410#: code:addons/account_chart_update/wizard/wizard_chart_update.py:438402#: code:addons/account_chart_update/wizard/wizard_chart_update.py:456
411#, python-format403#, python-format
412msgid "The amount field is different.\n"404msgid "The amount field is different.\n"
413""405""
414msgstr ""406msgstr ""
415407
416#. module: account_chart_update408#. module: account_chart_update
417#: code:addons/account_chart_update/wizard/wizard_chart_update.py:450409#: code:addons/account_chart_update/wizard/wizard_chart_update.py:468
418#, python-format410#, python-format
419msgid "The child depend field is different.\n"411msgid "The child depend field is different.\n"
420""412""
421msgstr ""413msgstr ""
422414
423#. module: account_chart_update415#. module: account_chart_update
424#: code:addons/account_chart_update/wizard/wizard_chart_update.py:948416#: code:addons/account_chart_update/wizard/wizard_chart_update.py:979
425#, python-format417#, python-format
426msgid "Updated account %s.\n"418msgid "Updated account %s.\n"
427""419""
@@ -438,7 +430,7 @@
438msgstr ""430msgstr ""
439431
440#. module: account_chart_update432#. module: account_chart_update
441#: code:addons/account_chart_update/wizard/wizard_chart_update.py:468433#: code:addons/account_chart_update/wizard/wizard_chart_update.py:486
442#, python-format434#, python-format
443msgid "The type tax use field is different.\n"435msgid "The type tax use field is different.\n"
444""436""
@@ -450,14 +442,14 @@
450msgstr ""442msgstr ""
451443
452#. module: account_chart_update444#. module: account_chart_update
453#: code:addons/account_chart_update/wizard/wizard_chart_update.py:963445#: code:addons/account_chart_update/wizard/wizard_chart_update.py:992
454#, python-format446#, python-format
455msgid "Account %s: The parent account %s can not be set.\n"447msgid "Account %s: The parent account %s can not be set.\n"
456""448""
457msgstr ""449msgstr ""
458450
459#. module: account_chart_update451#. module: account_chart_update
460#: code:addons/account_chart_update/wizard/wizard_chart_update.py:831452#: code:addons/account_chart_update/wizard/wizard_chart_update.py:873
461#, python-format453#, python-format
462msgid "Tax %s: The parent tax %s can not be set.\n"454msgid "Tax %s: The parent tax %s can not be set.\n"
463""455""
@@ -485,21 +477,21 @@
485msgstr ""477msgstr ""
486478
487#. module: account_chart_update479#. module: account_chart_update
488#: code:addons/account_chart_update/wizard/wizard_chart_update.py:374480#: code:addons/account_chart_update/wizard/wizard_chart_update.py:388
489#, python-format481#, python-format
490msgid "The sign field is different.\n"482msgid "The sign field is different.\n"
491""483""
492msgstr ""484msgstr ""
493485
494#. module: account_chart_update486#. module: account_chart_update
495#: code:addons/account_chart_update/wizard/wizard_chart_update.py:813487#: code:addons/account_chart_update/wizard/wizard_chart_update.py:858
496#, python-format488#, python-format
497msgid "Updated tax %s.\n"489msgid "Updated tax %s.\n"
498""490""
499msgstr ""491msgstr ""
500492
501#. module: account_chart_update493#. module: account_chart_update
502#: code:addons/account_chart_update/wizard/wizard_chart_update.py:874494#: code:addons/account_chart_update/wizard/wizard_chart_update.py:914
503#, python-format495#, python-format
504msgid "Exception setting the parent of account %s children: %s - %s.\n"496msgid "Exception setting the parent of account %s children: %s - %s.\n"
505""497""
@@ -531,7 +523,7 @@
531msgstr ""523msgstr ""
532524
533#. module: account_chart_update525#. module: account_chart_update
534#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1127526#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1173
535#, python-format527#, python-format
536msgid "Error"528msgid "Error"
537msgstr ""529msgstr ""
@@ -542,7 +534,7 @@
542msgstr ""534msgstr ""
543535
544#. module: account_chart_update536#. module: account_chart_update
545#: code:addons/account_chart_update/wizard/wizard_chart_update.py:534537#: code:addons/account_chart_update/wizard/wizard_chart_update.py:554
546#, python-format538#, python-format
547msgid "The type is different.\n"539msgid "The type is different.\n"
548""540""
@@ -565,6 +557,11 @@
565msgstr ""557msgstr ""
566558
567#. module: account_chart_update559#. module: account_chart_update
560#: view:wizard.update.charts.accounts:0
561msgid "Close"
562msgstr ""
563
564#. module: account_chart_update
568#: help:wizard.update.charts.accounts,update_tax:0565#: help:wizard.update.charts.accounts,update_tax:0
569msgid "Existing taxes are updated. Taxes are searched by name."566msgid "Existing taxes are updated. Taxes are searched by name."
570msgstr ""567msgstr ""
@@ -575,7 +572,7 @@
575msgstr ""572msgstr ""
576573
577#. module: account_chart_update574#. module: account_chart_update
578#: code:addons/account_chart_update/wizard/wizard_chart_update.py:837575#: code:addons/account_chart_update/wizard/wizard_chart_update.py:879
579#, python-format576#, python-format
580msgid "Tax %s: The tax code for the base refund %s can not be set.\n"577msgid "Tax %s: The tax code for the base refund %s can not be set.\n"
581""578""
@@ -592,14 +589,14 @@
592msgstr ""589msgstr ""
593590
594#. module: account_chart_update591#. module: account_chart_update
595#: code:addons/account_chart_update/wizard/wizard_chart_update.py:462592#: code:addons/account_chart_update/wizard/wizard_chart_update.py:480
596#, python-format593#, python-format
597msgid "The tax sign field is different.\n"594msgid "The tax sign field is different.\n"
598""595""
599msgstr ""596msgstr ""
600597
601#. module: account_chart_update598#. module: account_chart_update
602#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1127599#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1173
603#, python-format600#, python-format
604msgid "One or more errors detected!\n"601msgid "One or more errors detected!\n"
605"\n"602"\n"
@@ -607,7 +604,7 @@
607msgstr ""604msgstr ""
608605
609#. module: account_chart_update606#. module: account_chart_update
610#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1094607#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1126
611#, python-format608#, python-format
612msgid "Fiscal position %s: The destination account %s can not be set.\n"609msgid "Fiscal position %s: The destination account %s can not be set.\n"
613""610""
@@ -619,15 +616,15 @@
619msgstr ""616msgstr ""
620617
621#. module: account_chart_update618#. module: account_chart_update
622#: code:addons/account_chart_update/wizard/wizard_chart_update.py:444619#: code:addons/account_chart_update/wizard/wizard_chart_update.py:462
623#, python-format620#, python-format
624msgid "The applicable type field is different.\n"621msgid "The applicable type field is different.\n"
625""622""
626msgstr ""623msgstr ""
627624
628#. module: account_chart_update625#. module: account_chart_update
629#: view:wizard.update.charts.accounts:0626#: field:wizard.update.charts.accounts,new_accounts:0
630msgid "Tax code"627msgid "New accounts"
631msgstr ""628msgstr ""
632629
633#. module: account_chart_update630#. module: account_chart_update
@@ -636,10 +633,9 @@
636msgstr ""633msgstr ""
637634
638#. module: account_chart_update635#. module: account_chart_update
639#: code:addons/account_chart_update/wizard/wizard_chart_update.py:614636#: code:addons/account_chart_update/wizard/wizard_chart_update.py:373
640#, python-format637#, python-format
641msgid "Tax mapping not found on the fiscal position instance: %s -> None.\n"638msgid "Name or code not found."
642""
643msgstr ""639msgstr ""
644640
645#. module: account_chart_update641#. module: account_chart_update
@@ -653,7 +649,7 @@
653msgstr ""649msgstr ""
654650
655#. module: account_chart_update651#. module: account_chart_update
656#: code:addons/account_chart_update/wizard/wizard_chart_update.py:537652#: code:addons/account_chart_update/wizard/wizard_chart_update.py:557
657#, python-format653#, python-format
658msgid "The user type is different.\n"654msgid "The user type is different.\n"
659""655""
@@ -673,14 +669,14 @@
673msgstr ""669msgstr ""
674670
675#. module: account_chart_update671#. module: account_chart_update
676#: code:addons/account_chart_update/wizard/wizard_chart_update.py:540672#: code:addons/account_chart_update/wizard/wizard_chart_update.py:560
677#, python-format673#, python-format
678msgid "The reconcile is different.\n"674msgid "The reconcile is different.\n"
679""675""
680msgstr ""676msgstr ""
681677
682#. module: account_chart_update678#. module: account_chart_update
683#: code:addons/account_chart_update/wizard/wizard_chart_update.py:447679#: code:addons/account_chart_update/wizard/wizard_chart_update.py:465
684#, python-format680#, python-format
685msgid "The domain field is different.\n"681msgid "The domain field is different.\n"
686""682""
@@ -702,14 +698,14 @@
702msgstr ""698msgstr ""
703699
704#. module: account_chart_update700#. module: account_chart_update
705#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1096701#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1128
706#, python-format702#, python-format
707msgid "Created or updated fiscal position %s.\n"703msgid "Created or updated fiscal position %s.\n"
708""704""
709msgstr ""705msgstr ""
710706
711#. module: account_chart_update707#. module: account_chart_update
712#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1074708#: code:addons/account_chart_update/wizard/wizard_chart_update.py:1100
713#, python-format709#, python-format
714msgid "Fiscal position %s: The source tax %s can not be set.\n"710msgid "Fiscal position %s: The source tax %s can not be set.\n"
715""711""
@@ -726,7 +722,7 @@
726msgstr ""722msgstr ""
727723
728#. module: account_chart_update724#. module: account_chart_update
729#: code:addons/account_chart_update/wizard/wizard_chart_update.py:937725#: code:addons/account_chart_update/wizard/wizard_chart_update.py:968
730#, python-format726#, python-format
731msgid "Created account %s.\n"727msgid "Created account %s.\n"
732""728""
@@ -738,6 +734,12 @@
738msgstr ""734msgstr ""
739735
740#. module: account_chart_update736#. module: account_chart_update
737#: code:addons/account_chart_update/wizard/wizard_chart_update.py:616
738#, python-format
739msgid "Name not found."
740msgstr ""
741
742#. module: account_chart_update
741#: help:wizard.update.charts.accounts,continue_on_errors:0743#: help:wizard.update.charts.accounts,continue_on_errors:0
742msgid "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)."744msgid "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)."
743msgstr ""745msgstr ""
744746
=== modified file 'account_chart_update/wizard/wizard_chart_update.py'
--- account_chart_update/wizard/wizard_chart_update.py 2014-01-07 11:48:24 +0000
+++ account_chart_update/wizard/wizard_chart_update.py 2014-05-20 00:05:21 +0000
@@ -97,7 +97,9 @@
97 ('done', 'Wizard completed')97 ('done', 'Wizard completed')
98 ], 'Status', readonly=True),98 ], 'Status', readonly=True),
99 'company_id': fields.many2one('res.company', 'Company', required=True, ondelete='set null'),99 'company_id': fields.many2one('res.company', 'Company', required=True, ondelete='set null'),
100 'chart_template_id': fields.many2one('account.chart.template', 'Chart Template', required=True, ondelete='set null'),100 'chart_template_id': fields.many2one(
101 'account.chart.template', 'Chart Template', ondelete='cascade',
102 required=True),
101 '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."),103 '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."),
102 '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."),104 '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."),
103 'update_tax_code': fields.boolean('Update tax codes', help="Existing tax codes are updated. Tax codes are searched by name."),105 'update_tax_code': fields.boolean('Update tax codes', help="Existing tax codes are updated. Tax codes are searched by name."),
@@ -242,115 +244,146 @@
242 # Helper methods244 # Helper methods
243 ##########################################################################245 ##########################################################################
244246
245 def _map_tax_template(self, cr, uid, wizard, tax_template_mapping, tax_template, context=None):247 def _map_tax_template(self, cr, uid, wizard, tax_templ_mapping,
248 tax_templ, context=None):
246 """249 """
247 Adds a tax template -> tax id to the mapping.250 Adds a tax template -> tax id to the mapping.
248 """251 """
249 if tax_template and not tax_template_mapping.get(tax_template.id):252 if not tax_templ:
250 taxes = self.pool.get('account.tax')253 return False
251 tax_ids = taxes.search(cr, uid, [254 if tax_templ_mapping.get(tax_templ.id):
252 ('name', '=', tax_template.name),255 return tax_templ_mapping[tax_templ.id]
253 ('company_id', '=', wizard.company_id.id)256 # In other case
254 ], context=context)257 tax_obj = self.pool['account.tax']
255 if tax_ids:258 criteria = ['|',
256 tax_template_mapping[tax_template.id] = tax_ids[0]259 ('name', '=', tax_templ.name),
260 ('description', '=', tax_templ.name)]
261 if tax_templ.description:
262 criteria = (['|', '|'] + criteria +
263 [('description', '=', tax_templ.description),
264 ('name', '=', tax_templ.description)])
265 tax_ids = tax_obj.search(cr, uid, criteria, context=context)
266 tax_templ_mapping[tax_templ.id] = tax_ids and tax_ids[0] or False
267 return tax_templ_mapping[tax_templ.id]
257268
258 def _map_tax_code_template(self, cr, uid, wizard, tax_code_template_mapping, tax_code_template, context=None):269 def _map_tax_code_template(self, cr, uid, wizard,
270 tax_code_templ_mapping, tax_code_template,
271 context=None):
259 """272 """
260 Adds a tax code template -> tax code id to the mapping.273 Adds a tax code template -> tax code id to the mapping.
261 """274 """
262 if tax_code_template and not tax_code_template_mapping.get(tax_code_template.id):275 if not tax_code_template:
263 tax_codes = self.pool.get('account.tax.code')276 return False
264 root_tax_code_id = wizard.chart_template_id.tax_code_root_id.id277 if not wizard.chart_template_id:
265 tax_code_name = (tax_code_template.id == root_tax_code_id) and wizard.company_id.name or tax_code_template.name278 return False
266 tax_code_ids = tax_codes.search(cr, uid, [279 if tax_code_templ_mapping.get(tax_code_template.id):
267 ('name', '=', tax_code_name),280 return tax_code_templ_mapping[tax_code_template.id]
268 ('company_id', '=', wizard.company_id.id)281 # In other case
269 ])282 tax_code_obj = self.pool['account.tax.code']
270 if not tax_code_ids:283 root_tax_code_id = wizard.chart_template_id.tax_code_root_id.id
271 # if we could not match no tax code template name,284 tax_code_name = ((tax_code_template.id == root_tax_code_id) and
272 # try to match on tax code template code, if any285 wizard.company_id.name or tax_code_template.name)
273 tax_code_code = tax_code_template.code286 tax_code_ids = tax_code_obj.search(cr, uid, [
274 if tax_code_code:287 ('name', '=', tax_code_name),
275 tax_code_ids = tax_codes.search(cr, uid, [288 ('company_id', '=', wizard.company_id.id)
276 ('code', '=', tax_code_code),289 ], context=context)
277 ('company_id', '=', wizard.company_id.id)290 if not tax_code_ids:
278 ])291 # if we could not match no tax code template name,
279 if tax_code_ids:292 # try to match on tax code template code, if any
280 tax_code_template_mapping[293 tax_code_code = tax_code_template.code
281 tax_code_template.id] = tax_code_ids[0]294 if tax_code_code:
295 tax_code_ids = tax_code_obj.search(cr, uid, [
296 ('code', '=', tax_code_code),
297 ('company_id', '=', wizard.company_id.id)
298 ], context=context)
299 tax_code_templ_mapping[tax_code_template.id] = (tax_code_ids and
300 tax_code_ids[0] or
301 False)
302 return tax_code_templ_mapping[tax_code_template.id]
282303
283 def _map_account_template(self, cr, uid, wizard, account_template_mapping, account_template, context=None):304 def _map_account_template(self, cr, uid, wizard, acc_templ_mapping,
305 acc_templ, context=None):
284 """306 """
285 Adds an account template -> account id to the mapping307 Adds an account template -> account id to the mapping
286 """308 """
287 if account_template and not account_template_mapping.get(account_template.id):309 if not acc_templ:
288 accounts = self.pool.get('account.account')310 return False
289 code = account_template.code or ''311 if acc_templ_mapping.get(acc_templ.id):
290 if account_template.type != 'view':312 return acc_templ_mapping[acc_templ.id]
291 if len(code) > 0 and len(code) <= wizard.code_digits:313 # In other case
292 code = '%s%s' % (314 acc_obj = self.pool['account.account']
293 code, '0' * (wizard.code_digits - len(code)))315 code = acc_templ.code or ''
294 account_ids = accounts.search(cr, uid, [316 if acc_templ.type != 'view':
295 ('code', '=', code),317 if code and len(code) <= wizard.code_digits:
296 ('company_id', '=', wizard.company_id.id)318 code = '%s%s' % (code, '0' * (wizard.code_digits - len(code)))
297 ], context=context)319 acc_ids = acc_obj.search(cr, uid, [
298 if account_ids:320 ('code', '=', code),
299 account_template_mapping[account_template.id] = account_ids[0]321 ('company_id', '=', wizard.company_id.id)
322 ], context=context)
323 acc_templ_mapping[acc_templ.id] = acc_ids and acc_ids[0] or False
324 return acc_templ_mapping[acc_templ.id]
300325
301 def _map_fp_template(self, cr, uid, wizard, fp_template_mapping, fp_template, context=None):326 def _map_fp_template(self, cr, uid, wizard, fp_templ_mapping, fp_template, context=None):
302 """327 """
303 Adds a fiscal position template -> fiscal position id to the mapping.328 Adds a fiscal position template -> fiscal position id to the mapping.
304 """329 """
305 if fp_template and not fp_template_mapping.get(fp_template.id):330 if not fp_template:
306 fiscalpositions = self.pool.get('account.fiscal.position')331 return False
307 fp_ids = fiscalpositions.search(cr, uid, [332 if fp_templ_mapping.get(fp_template.id):
308 ('name', '=', fp_template.name),333 return fp_templ_mapping[fp_template.id]
309 ('company_id', '=', wizard.company_id.id)334 # In other case
310 ], context=context)335 fp_obj = self.pool['account.fiscal.position']
311 if fp_ids:336 fp_ids = fp_obj.search(cr, uid,
312 fp_template_mapping[fp_template.id] = fp_ids[0]337 [('name', '=', fp_template.name),
338 ('company_id', '=', wizard.company_id.id)],
339 context=context)
340 fp_templ_mapping[fp_template.id] = fp_ids and fp_ids[0] or False
341 return fp_templ_mapping[fp_template.id]
313342
314 def _find_tax_codes(self, cr, uid, wizard, context=None):343 def _find_tax_codes(self, cr, uid, wizard, chart_template_ids,
344 context=None):
315 """345 """
316 Search for, and load, tax code templates to create/update.346 Search for, and load, tax code templates to create/update.
347
348 @param chart_template_ids: IDs of the chart templates to look on,
349 calculated once in the calling method.
317 """350 """
351 if not wizard.chart_template_id:
352 return {}
318 new_tax_codes = 0353 new_tax_codes = 0
319 updated_tax_codes = 0354 updated_tax_codes = 0
320 tax_code_template_mapping = {}355 tax_code_template_mapping = {}
321356 tax_code_templ_obj = self.pool['account.tax.code.template']
322 taxes_codes_templates = self.pool.get('account.tax.code.template')357 tax_code_obj = self.pool['account.tax.code']
323 taxcodes = self.pool.get('account.tax.code')358 wiz_tax_code_obj = self.pool['wizard.update.charts.accounts.tax.code']
324 wiz_taxcodes = self.pool.get('wizard.update.charts.accounts.tax.code')
325
326 # Remove previous tax codes359 # Remove previous tax codes
327 wiz_taxcodes.unlink(360 wiz_tax_code_obj.unlink(cr, uid, wiz_tax_code_obj.search(cr, uid, []))
328 cr, uid, wiz_taxcodes.search(cr, uid, []))
329
330 # Search for new / updated tax codes361 # Search for new / updated tax codes
331 root_tax_code_id = wizard.chart_template_id.tax_code_root_id.id362 root_tax_code_id = wizard.chart_template_id.tax_code_root_id.id
332 children_tax_code_template = taxes_codes_templates.search(cr, uid, [(363 children_tax_code_template = tax_code_templ_obj.search(cr, uid, [(
333 'parent_id', 'child_of', [root_tax_code_id])], order='id')364 'parent_id', 'child_of', [root_tax_code_id])], order='id',
334 for tax_code_template in taxes_codes_templates.browse(cr, uid, children_tax_code_template):365 context=context)
366 for tax_code_template in tax_code_templ_obj.browse(cr, uid,
367 children_tax_code_template, context=context):
335 # Ensure the tax code template is on the map (search for the mapped368 # Ensure the tax code template is on the map (search for the mapped
336 # tax code id).369 # tax code id).
337 self._map_tax_code_template(cr, uid, wizard, tax_code_template_mapping, tax_code_template, context)370 tax_code_id = self._map_tax_code_template(cr, uid, wizard,
338371 tax_code_template_mapping,
339 tax_code_id = tax_code_template_mapping.get(tax_code_template.id)372 tax_code_template, context=context)
340 if not tax_code_id:373 if not tax_code_id:
341 new_tax_codes += 1374 new_tax_codes += 1
342 wiz_taxcodes.create(cr, uid, {375 wiz_tax_code_obj.create(cr, uid, {
343 'tax_code_id': tax_code_template.id,376 'tax_code_id': tax_code_template.id,
344 'update_chart_wizard_id': wizard.id,377 'update_chart_wizard_id': wizard.id,
345 'type': 'new',378 'type': 'new',
379 'notes': _('Name or code not found.'),
346 }, context)380 }, context)
347 elif wizard.update_tax_code:381 elif wizard.update_tax_code:
348 # Check the tax code for changes.382 # Check the tax code for changes.
349 modified = False383 modified = False
350 notes = ""384 notes = ""
351 tax_code = taxcodes.browse(385 tax_code = tax_code_obj.browse(
352 cr, uid, tax_code_id, context=context)386 cr, uid, tax_code_id, context=context)
353
354 if tax_code.code != tax_code_template.code:387 if tax_code.code != tax_code_template.code:
355 notes += _("The code field is different.\n")388 notes += _("The code field is different.\n")
356 modified = True389 modified = True
@@ -360,278 +393,306 @@
360 if tax_code.sign != tax_code_template.sign:393 if tax_code.sign != tax_code_template.sign:
361 notes += _("The sign field is different.\n")394 notes += _("The sign field is different.\n")
362 modified = True395 modified = True
363
364 # TODO: We could check other account fields for changes...396 # TODO: We could check other account fields for changes...
365
366 if modified:397 if modified:
367 # Tax code to update.398 # Tax code to update.
368 updated_tax_codes += 1399 updated_tax_codes += 1
369 wiz_taxcodes.create(cr, uid, {400 wiz_tax_code_obj.create(cr, uid, {
370 'tax_code_id': tax_code_template.id,401 'tax_code_id': tax_code_template.id,
371 'update_chart_wizard_id': wizard.id,402 'update_chart_wizard_id': wizard.id,
372 'type': 'updated',403 'type': 'updated',
373 'update_tax_code_id': tax_code_id,404 'update_tax_code_id': tax_code_id,
374 'notes': notes,405 'notes': notes,
375 }, context)406 }, context)
376
377 return {407 return {
378 'new': new_tax_codes,408 'new': new_tax_codes,
379 'updated': updated_tax_codes,409 'updated': updated_tax_codes,
380 'mapping': tax_code_template_mapping410 'mapping': tax_code_template_mapping
381 }411 }
382412
383 def _find_taxes(self, cr, uid, wizard, context=None):413 def _find_taxes(self, cr, uid, wizard, chart_template_ids, context=None):
384 """414 """
385 Search for, and load, tax templates to create/update.415 Search for, and load, tax templates to create/update.
416
417 @param chart_template_ids: IDs of the chart templates to look on,
418 calculated once in the calling method.
386 """419 """
387 new_taxes = 0420 new_taxes = 0
388 updated_taxes = 0421 updated_taxes = 0
389 tax_template_mapping = {}422 tax_templ_mapping = {}
390423 tax_obj = self.pool['account.tax']
391 taxes = self.pool.get('account.tax')424 tax_templ_obj = self.pool['account.tax.template']
392 wiz_taxes = self.pool.get('wizard.update.charts.accounts.tax')425 wiz_taxes_obj = self.pool['wizard.update.charts.accounts.tax']
393
394 delay_wiz_tax = []426 delay_wiz_tax = []
395 # Remove previous taxes427 # Remove previous taxes
396 wiz_taxes.unlink(cr, uid, wiz_taxes.search(cr, uid, []))428 wiz_taxes_ids = wiz_taxes_obj.search(cr, uid, [], context=context)
429 wiz_taxes_obj.unlink(cr, uid, wiz_taxes_ids, context=context)
397 # Search for new / updated taxes430 # Search for new / updated taxes
398 for tax_template in wizard.chart_template_id.tax_template_ids:431 tax_templ_ids = tax_templ_obj.search(
399 # Ensure the tax template is on the map (search for the mapped tax432 cr, uid, [('chart_template_id', 'in', chart_template_ids)],
400 # id).433 context=context)
401 self._map_tax_template(434 for tax_templ in tax_templ_obj.browse(cr, uid, tax_templ_ids,
402 cr, uid, wizard, tax_template_mapping, tax_template, context)435 context=context):
403436 # Ensure tax template is on the map (search for the mapped tax id)
404 tax_id = tax_template_mapping.get(tax_template.id)437 tax_id = self._map_tax_template(cr, uid, wizard,
438 tax_templ_mapping,
439 tax_templ, context=context)
405 if not tax_id:440 if not tax_id:
406 new_taxes += 1441 new_taxes += 1
407 vals_wiz = {442 vals_wiz = {
408 'tax_id': tax_template.id,443 'tax_id': tax_templ.id,
409 'update_chart_wizard_id': wizard.id,444 'update_chart_wizard_id': wizard.id,
410 'type': 'new',445 'type': 'new',
446 'notes': _('Name or description not found.'),
411 }447 }
412 if not tax_template.parent_id:448 if not tax_templ.parent_id:
413 wiz_taxes.create(cr, uid, vals_wiz, context)449 wiz_taxes_obj.create(cr, uid, vals_wiz, context)
414 else:450 else:
415 delay_wiz_tax.append(vals_wiz)451 delay_wiz_tax.append(vals_wiz)
416 elif wizard.update_tax:452 elif wizard.update_tax:
417 # Check the tax for changes.453 # Check the tax for changes.
418 modified = False454 modified = False
419 notes = ""455 notes = ""
420 tax = taxes.browse(cr, uid, tax_id, context=context)456 tax = tax_obj.browse(cr, uid, tax_id, context=context)
421 if tax.sequence != tax_template.sequence:457 if tax.sequence != tax_templ.sequence:
422 notes += _("The sequence field is different.\n")458 notes += _("The sequence field is different.\n")
423 modified = True459 modified = True
424 if tax.amount != tax_template.amount:460 if tax.amount != tax_templ.amount:
425 notes += _("The amount field is different.\n")461 notes += _("The amount field is different.\n")
426 modified = True462 modified = True
427 if tax.type != tax_template.type:463 if tax.type != tax_templ.type:
428 notes += _("The type field is different.\n")464 notes += _("The type field is different.\n")
429 modified = True465 modified = True
430 if tax.applicable_type != tax_template.applicable_type:466 if tax.applicable_type != tax_templ.applicable_type:
431 notes += _("The applicable type field is different.\n")467 notes += _("The applicable type field is different.\n")
432 modified = True468 modified = True
433 if tax.domain != tax_template.domain:469 if tax.domain != tax_templ.domain:
434 notes += _("The domain field is different.\n")470 notes += _("The domain field is different.\n")
435 modified = True471 modified = True
436 if tax.child_depend != tax_template.child_depend:472 if tax.child_depend != tax_templ.child_depend:
437 notes += _("The child depend field is different.\n")473 notes += _("The child depend field is different.\n")
438 modified = True474 modified = True
439 if tax.python_compute != tax_template.python_compute:475 if tax.python_compute != tax_templ.python_compute:
440 notes += _("The python compute field is different.\n")476 notes += _("The python compute field is different.\n")
441 modified = True477 modified = True
442 # if tax.tax_group != tax_template.tax_group:478 # if tax.tax_group != tax_templ.tax_group:
443 # notes += _("The tax group field is different.\n")479 # notes += _("The tax group field is different.\n")
444 # modified = True480 # modified = True
445 if tax.base_sign != tax_template.base_sign:481 if tax.base_sign != tax_templ.base_sign:
446 notes += _("The base sign field is different.\n")482 notes += _("The base sign field is different.\n")
447 modified = True483 modified = True
448 if tax.tax_sign != tax_template.tax_sign:484 if tax.tax_sign != tax_templ.tax_sign:
449 notes += _("The tax sign field is different.\n")485 notes += _("The tax sign field is different.\n")
450 modified = True486 modified = True
451 if tax.include_base_amount != tax_template.include_base_amount:487 if tax.include_base_amount != tax_templ.include_base_amount:
452 notes += _("The include base amount field is different.\n")488 notes += _("The include base amount field is different.\n")
453 modified = True489 modified = True
454 if tax.type_tax_use != tax_template.type_tax_use:490 if tax.type_tax_use != tax_templ.type_tax_use:
455 notes += _("The type tax use field is different.\n")491 notes += _("The type tax use field is different.\n")
456 modified = True492 modified = True
457 # TODO: We could check other tax fields for changes...493 # TODO: We could check other tax fields for changes...
458
459 if modified:494 if modified:
460 # Tax code to update.495 # Tax code to update.
461 updated_taxes += 1496 updated_taxes += 1
462 wiz_taxes.create(cr, uid, {497 wiz_taxes_obj.create(cr, uid, {
463 'tax_id': tax_template.id,498 'tax_id': tax_templ.id,
464 'update_chart_wizard_id': wizard.id,499 'update_chart_wizard_id': wizard.id,
465 'type': 'updated',500 'type': 'updated',
466 'update_tax_id': tax_id,501 'update_tax_id': tax_id,
467 'notes': notes,502 'notes': notes,
468 }, context)503 }, context)
469
470 for delay_vals_wiz in delay_wiz_tax:504 for delay_vals_wiz in delay_wiz_tax:
471 wiz_taxes.create(cr, uid, delay_vals_wiz, context)505 wiz_taxes_obj.create(cr, uid, delay_vals_wiz, context)
472506
473 return {'new': new_taxes, 'updated': updated_taxes, 'mapping': tax_template_mapping}507 return {'new': new_taxes, 'updated': updated_taxes, 'mapping': tax_templ_mapping}
474508
475 def _find_accounts(self, cr, uid, wizard, context=None):509 def _find_accounts(self, cr, uid, wizard, context=None):
476 """510 """
477 Search for, and load, account templates to create/update.511 Search for, and load, account templates to create/update.
478 """512 """
513 if not wizard.chart_template_id:
514 return {}
479 new_accounts = 0515 new_accounts = 0
480 updated_accounts = 0516 updated_accounts = 0
481 account_template_mapping = {}517 acc_templ_mapping = {}
482518 acc_obj = self.pool['account.account']
483 accounts = self.pool.get('account.account')519 acc_templ_obj = self.pool['account.account.template']
484 accounts_template = self.pool.get('account.account.template')520 wiz_accounts = self.pool['wizard.update.charts.accounts.account']
485 wiz_accounts = self.pool.get(
486 'wizard.update.charts.accounts.account')
487
488 # Remove previous accounts521 # Remove previous accounts
489 wiz_accounts.unlink(522 wiz_accounts_ids = wiz_accounts.search(cr, uid, [], context=context)
490 cr, uid, wiz_accounts.search(cr, uid, []))523 wiz_accounts.unlink(cr, uid, wiz_accounts_ids, context=context)
491
492 # Search for new / updated accounts524 # Search for new / updated accounts
493 root_account_id = wizard.chart_template_id.account_root_id.id525 root_account_id = wizard.chart_template_id.account_root_id.id
494 children_acc_template = accounts_template.search(cr, uid, [(526 acc_templ_criteria = [('chart_template_id',
495 'parent_id', 'child_of', [root_account_id])], context=context)527 '=',
496 children_acc_template.sort()528 wizard.chart_template_id.id)]
497 for account_template in accounts_template.browse(cr, uid, children_acc_template, context=context):529 if root_account_id:
530 acc_templ_criteria = (['|'] + acc_templ_criteria +
531 ['&', ('parent_id', 'child_of', [root_account_id]),
532 ('chart_template_id', '=', False)])
533 acc_ids = acc_templ_obj.search(cr, uid, acc_templ_criteria,
534 context=context)
535 acc_ids.sort()
536 for acc_templ in acc_templ_obj.browse(cr, uid, acc_ids,
537 context=context):
498 # Ensure the account template is on the map (search for the mapped538 # Ensure the account template is on the map (search for the mapped
499 # account id).539 # account id).
500 self._map_account_template(cr, uid, wizard, account_template_mapping, account_template, context)540 account_id = self._map_account_template(cr, uid, wizard,
501541 acc_templ_mapping,
502 account_id = account_template_mapping.get(account_template.id)542 acc_templ,
543 context=context)
503 if not account_id:544 if not account_id:
504 new_accounts += 1545 new_accounts += 1
505 wiz_accounts.create(cr, uid, {546 wiz_accounts.create(cr, uid, {
506 'account_id': account_template.id,547 'account_id': acc_templ.id,
507 'update_chart_wizard_id': wizard.id,548 'update_chart_wizard_id': wizard.id,
508 'type': 'new',549 'type': 'new',
550 'notes': _('Code not found.'),
509 }, context)551 }, context)
510 elif wizard.update_account:552 elif wizard.update_account:
511 # Check the account for changes.553 # Check the account for changes.
512 modified = False554 modified = False
513 notes = ""555 notes = ""
514 account = accounts.browse(556 account = acc_obj.browse(cr, uid, account_id, context=context)
515 cr, uid, account_id, context=context)557 if account.name != acc_templ.name and account.name != wizard.company_id.name:
516
517 if account.name != account_template.name and account.name != wizard.company_id.name:
518 notes += _("The name is different.\n")558 notes += _("The name is different.\n")
519 modified = True559 modified = True
520 if account.type != account_template.type:560 if account.type != acc_templ.type:
521 notes += _("The type is different.\n")561 notes += _("The type is different.\n")
522 modified = True562 modified = True
523 if account.user_type != account_template.user_type:563 if account.user_type != acc_templ.user_type:
524 notes += _("The user type is different.\n")564 notes += _("The user type is different.\n")
525 modified = True565 modified = True
526 if account.reconcile != account_template.reconcile:566 if account.reconcile != acc_templ.reconcile:
527 notes += _("The reconcile is different.\n")567 notes += _("The reconcile is different.\n")
528 modified = True568 modified = True
529
530 # TODO: We could check other account fields for changes...569 # TODO: We could check other account fields for changes...
531
532 if modified:570 if modified:
533 # Account to update.571 # Account to update.
534 updated_accounts += 1572 updated_accounts += 1
535 wiz_accounts.create(cr, uid, {573 wiz_accounts.create(cr, uid, {
536 'account_id': account_template.id,574 'account_id': acc_templ.id,
537 'update_chart_wizard_id': wizard.id,575 'update_chart_wizard_id': wizard.id,
538 'type': 'updated',576 'type': 'updated',
539 'update_account_id': account_id,577 'update_account_id': account_id,
540 'notes': notes,578 'notes': notes,
541 }, context)579 }, context)
542580 return {
543 return {'new': new_accounts, 'updated': updated_accounts, 'mapping': account_template_mapping}581 'new': new_accounts,
544582 'updated': updated_accounts,
545 def _find_fiscal_positions(self, cr, uid, wizard, context=None):583 'mapping': acc_templ_mapping
584 }
585
586 def _find_fiscal_positions(self, cr, uid, wizard, chart_template_ids,
587 context=None):
546 """588 """
547 Search for, and load, fiscal position templates to create/update.589 Search for, and load, fiscal position templates to create/update.
590
591 @param chart_template_ids: IDs of the chart templates to look on,
592 calculated once in the calling method.
548 """593 """
549 new_fps = 0594 new_fps = 0
550 updated_fps = 0595 updated_fps = 0
551 fp_template_mapping = {}596 fp_templ_mapping = {}
552597 tax_templ_mapping = {}
553 fiscalpostitions_template = self.pool.get('account.fiscal.position.template')598 acc_templ_mapping = {}
554 fiscalpositions = self.pool.get('account.fiscal.position')599 fp_templ_obj = self.pool['account.fiscal.position.template']
555 wiz_fiscalpositions = self.pool.get(600 fp_obj = self.pool['account.fiscal.position']
556 'wizard.update.charts.accounts.fiscal.position')601 wiz_fp = self.pool['wizard.update.charts.accounts.fiscal.position']
557
558 # Remove previous fiscal positions602 # Remove previous fiscal positions
559 wiz_fiscalpositions.unlink(cr, uid, wiz_fiscalpositions.search(cr, uid, []))603 wiz_fp.unlink(cr, uid, wiz_fp.search(cr, uid, []))
560
561 # Search for new / updated fiscal positions604 # Search for new / updated fiscal positions
562 fp_template_ids = fiscalpostitions_template.search(cr, uid, [('chart_template_id', '=', wizard.chart_template_id.id)], context=context)605 fp_template_ids = fp_templ_obj.search(cr, uid,
563 for fp_template in fiscalpostitions_template.browse(cr, uid, fp_template_ids, context=context):606 [('chart_template_id',
607 'in',
608 chart_template_ids)],
609 context=context)
610 for fp_templ in fp_templ_obj.browse(cr, uid, fp_template_ids,
611 context=context):
564 # Ensure the fiscal position template is on the map (search for the612 # Ensure the fiscal position template is on the map (search for the
565 # mapped fiscal position id).613 # mapped fiscal position id).
566 self._map_fp_template(614 fp_id = self._map_fp_template(cr, uid, wizard, fp_templ_mapping,
567 cr, uid, wizard, fp_template_mapping, fp_template, context)615 fp_templ, context=context)
568
569 fp_id = fp_template_mapping.get(fp_template.id)
570 if not fp_id:616 if not fp_id:
571 # New fiscal position template.617 # New fiscal position template.
572 new_fps += 1618 new_fps += 1
573 wiz_fiscalpositions.create(cr, uid, {619 wiz_fp.create(cr, uid, {
574 'fiscal_position_id': fp_template.id,620 'fiscal_position_id': fp_templ.id,
575 'update_chart_wizard_id': wizard.id,621 'update_chart_wizard_id': wizard.id,
576 'type': 'new',622 'type': 'new',
577 }, context)623 'notes': _('Name not found.'),
578 elif wizard.update_fiscal_position:624 }, context=context)
579 # Check the fiscal position for changes.625 continue
580 modified = False626 # Check the fiscal position for changes
581 notes = ""627 modified = False
582 fp = fiscalpositions.browse(cr, uid, fp_id, context=context)628 notes = ""
583629 fp = fp_obj.browse(cr, uid, fp_id, context=context)
584 # Check fiscal position taxes for changes.630 # Check fiscal position taxes for changes.
585 if fp_template.tax_ids and fp.tax_ids:631 if fp_templ.tax_ids and fp.tax_ids:
586 for fp_tax_template in fp_template.tax_ids:632 for fp_tax_templ in fp_templ.tax_ids:
587 found = False633 found = False
588 for fp_tax in fp.tax_ids:634 tax_src_id = self._map_tax_template(cr, uid, wizard,
589 if fp_tax.tax_src_id.name == fp_tax_template.tax_src_id.name:635 tax_templ_mapping,
590 if fp_tax_template.tax_dest_id and fp_tax.tax_dest_id:636 fp_tax_templ.tax_src_id,
591 if fp_tax.tax_dest_id.name == fp_tax_template.tax_dest_id.name:637 context=None)
592 found = True638 tax_dest_id = self._map_tax_template(cr, uid, wizard,
593 break639 tax_templ_mapping,
594 elif not fp_tax_template.tax_dest_id and not fp_tax.tax_dest_id:640 fp_tax_templ.tax_dest_id,
641 context=None)
642 for fp_tax in fp.tax_ids:
643 if fp_tax.tax_src_id.id == tax_src_id:
644 if not fp_tax.tax_dest_id:
645 if not tax_dest_id:
595 found = True646 found = True
596 break647 break
597 if not found:
598 if fp_tax_template.tax_dest_id:
599 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)
600 else:648 else:
601 notes += _("Tax mapping not found on the fiscal position instance: %s -> None.\n") % fp_tax_template.tax_src_id.name649 if fp_tax.tax_dest_id.id == tax_dest_id:
602 modified = True
603 elif fp_template.tax_ids and not fp.tax_ids:
604 notes += _("The template has taxes the fiscal position instance does not.\n")
605 modified = True
606
607 # Check fiscal position accounts for changes.
608 if fp_template.account_ids and fp.account_ids:
609 for fp_account_template in fp_template.account_ids:
610 found = False
611 for fp_account in fp.account_ids:
612 if fp_account.account_src_id.name == fp_account_template.account_src_id.name:
613 if fp_account.account_dest_id.name == fp_account_template.account_dest_id.name:
614 found = True650 found = True
615 break651 break
616 if not found:652 if not found:
617 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)653 notes += _("Tax mapping not found on the fiscal position instance: %s -> %s.\n") % (
618 modified = True654 fp_tax_templ.tax_src_id.name,
619 elif fp_template.account_ids and not fp.account_ids:655 fp_tax_templ.tax_dest_id and fp_tax_templ.tax_dest_id.name or _('None'))
620 notes += _("The template has accounts the fiscal position instance does not.\n")656 modified = True
621 modified = True657 elif fp_templ.tax_ids and not fp.tax_ids:
622658 notes += _("The template has taxes the fiscal position instance does not.\n")
623 if modified:659 modified = True
624 # Fiscal position template to update.660 # Check fiscal position accounts for changes
625 updated_fps += 1661 if fp_templ.account_ids and fp.account_ids:
626 wiz_fiscalpositions.create(cr, uid, {662 for fp_acc_templ in fp_templ.account_ids:
627 'fiscal_position_id': fp_template.id,663 found = False
628 'update_chart_wizard_id': wizard.id,664 acc_src_id = self._map_account_template(
629 'type': 'updated',665 cr, uid, wizard, acc_templ_mapping,
630 'update_fiscal_position_id': fp_id,666 fp_acc_templ.account_src_id, context=context)
631 'notes': notes,667 acc_dest_id = self._map_account_template(
632 }, context)668 cr, uid, wizard, acc_templ_mapping,
633669 fp_acc_templ.account_dest_id, context=context)
634 return {'new': new_fps, 'updated': updated_fps, 'mapping': fp_template_mapping}670 for fp_acc in fp.account_ids:
671 if (fp_acc.account_src_id.id == acc_src_id and
672 fp_acc.account_dest_id.id == acc_dest_id):
673 found = True
674 break
675 if not found:
676 notes += _("Account mapping not found on the fiscal "
677 "position instance: %s -> %s.\n") % \
678 (fp_acc_templ.account_src_id.name,
679 fp_acc_templ.account_dest_id.name)
680 modified = True
681 elif fp_templ.account_ids and not fp.account_ids:
682 notes += _("The template has accounts the fiscal position "
683 "instance does not.\n")
684 modified = True
685 if modified:
686 # Fiscal position template to update
687 updated_fps += 1
688 wiz_fp.create(cr, uid, {
689 'fiscal_position_id': fp_templ.id,
690 'update_chart_wizard_id': wizard.id,
691 'type': 'updated',
692 'update_fiscal_position_id': fp_id,
693 'notes': notes,
694 }, context=context)
695 return {'new': new_fps, 'updated': updated_fps, 'mapping': fp_templ_mapping}
635696
636 def action_find_records(self, cr, uid, ids, context=None):697 def action_find_records(self, cr, uid, ids, context=None):
637 """698 """
@@ -640,18 +701,34 @@
640 if context is None:701 if context is None:
641 context = {}702 context = {}
642 wizard = self.browse(cr, uid, ids[0], context=context)703 wizard = self.browse(cr, uid, ids[0], context=context)
643
644 if wizard.lang:704 if wizard.lang:
645 context['lang'] = wizard.lang705 context['lang'] = wizard.lang
646 elif context.get('lang'):706 elif context.get('lang'):
647 del context['lang']707 del context['lang']
648708 # Defaults when calculations are not done
709 tax_codes_res = {}
710 taxes_res = {}
711 accounts_res = {}
712 fps_res = {}
713 # Get all chart templates involved
714 wiz_obj = self.pool['wizard.multi.charts.accounts']
715 chart_template_ids = wiz_obj._get_chart_parent_ids(
716 cr, uid, wizard.chart_template_id, context=context)
649 # Search for, and load, the records to create/update.717 # Search for, and load, the records to create/update.
650 tax_codes_res = self._find_tax_codes(cr, uid, wizard, context=context)718 if wizard.update_tax_code:
651 taxes_res = self._find_taxes(cr, uid, wizard, context=context)719 tax_codes_res = self._find_tax_codes(cr, uid, wizard,
652 accounts_res = self._find_accounts(cr, uid, wizard, context=context)720 chart_template_ids,
653 fps_res = self._find_fiscal_positions(cr, uid, wizard, context=context)721 context=context)
654722 if wizard.update_tax:
723 taxes_res = self._find_taxes(cr, uid, wizard, chart_template_ids,
724 context=context)
725 if wizard.update_account:
726 accounts_res = self._find_accounts(cr, uid, wizard,
727 context=context)
728 if wizard.update_fiscal_position:
729 fps_res = self._find_fiscal_positions(cr, uid, wizard,
730 chart_template_ids,
731 context=context)
655 # Write the results, and go to the next step.732 # Write the results, and go to the next step.
656 self.write(cr, uid, [wizard.id], {733 self.write(cr, uid, [wizard.id], {
657 'state': 'ready',734 'state': 'ready',
@@ -676,14 +753,14 @@
676 new_tax_codes = 0753 new_tax_codes = 0
677 updated_tax_codes = 0754 updated_tax_codes = 0
678 tax_code_template_mapping = {}755 tax_code_template_mapping = {}
679
680 for wiz_tax_code in wizard.tax_code_ids:756 for wiz_tax_code in wizard.tax_code_ids:
681 tax_code_template = wiz_tax_code.tax_code_id757 tax_code_template = wiz_tax_code.tax_code_id
682 tax_code_name = (root_tax_code_id == tax_code_template.id) and wizard.company_id.name or tax_code_template.name758 tax_code_name = (root_tax_code_id == tax_code_template.id) and wizard.company_id.name or tax_code_template.name
683
684 # Ensure the parent tax code template is on the map.759 # Ensure the parent tax code template is on the map.
685 self._map_tax_code_template(cr, uid, wizard, tax_code_template_mapping, tax_code_template.parent_id, context)760 self._map_tax_code_template(cr, uid, wizard,
686761 tax_code_template_mapping,
762 tax_code_template.parent_id,
763 context=context)
687 # Values764 # Values
688 vals = {765 vals = {
689 'name': tax_code_name,766 'name': tax_code_name,
@@ -693,10 +770,8 @@
693 'company_id': wizard.company_id.id,770 'company_id': wizard.company_id.id,
694 'sign': tax_code_template.sign,771 'sign': tax_code_template.sign,
695 }772 }
696
697 tax_code_id = None773 tax_code_id = None
698 modified = False774 modified = False
699
700 if wiz_tax_code.type == 'new':775 if wiz_tax_code.type == 'new':
701 # Create the tax code776 # Create the tax code
702 tax_code_id = taxcodes.create(cr, uid, vals)777 tax_code_id = taxcodes.create(cr, uid, vals)
@@ -713,15 +788,12 @@
713 else:788 else:
714 tax_code_id = wiz_tax_code.update_tax_code_id and wiz_tax_code.update_tax_code_id.id789 tax_code_id = wiz_tax_code.update_tax_code_id and wiz_tax_code.update_tax_code_id.id
715 modified = False790 modified = False
716
717 # Store the tax codes on the map791 # Store the tax codes on the map
718 tax_code_template_mapping[tax_code_template.id] = tax_code_id792 tax_code_template_mapping[tax_code_template.id] = tax_code_id
719
720 if modified:793 if modified:
721 # Detect errors794 # Detect errors
722 if tax_code_template.parent_id and not tax_code_template_mapping.get(tax_code_template.parent_id.id):795 if tax_code_template.parent_id and not tax_code_template_mapping.get(tax_code_template.parent_id.id):
723 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)796 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)
724
725 return {797 return {
726 'new': new_tax_codes,798 'new': new_tax_codes,
727 'updated': updated_tax_codes,799 'updated': updated_tax_codes,
@@ -732,20 +804,16 @@
732 """804 """
733 Search for, and load, tax templates to create/update.805 Search for, and load, tax templates to create/update.
734 """806 """
735 taxes = self.pool.get('account.tax')807 taxes = self.pool['account.tax']
736
737 new_taxes = 0808 new_taxes = 0
738 updated_taxes = 0809 updated_taxes = 0
739 tax_template_mapping = {}810 tax_template_mapping = {}
740 taxes_pending_for_accounts = {}811 taxes_pending_for_accounts = {}
741
742 for wiz_tax in wizard.tax_ids:812 for wiz_tax in wizard.tax_ids:
743 tax_template = wiz_tax.tax_id813 tax_template = wiz_tax.tax_id
744
745 # Ensure the parent tax template is on the map.814 # Ensure the parent tax template is on the map.
746 self._map_tax_template(cr, uid, wizard, tax_template_mapping,815 self._map_tax_template(cr, uid, wizard, tax_template_mapping,
747 tax_template.parent_id, context)816 tax_template.parent_id, context)
748
749 # Ensure the referenced tax codes are on the map.817 # Ensure the referenced tax codes are on the map.
750 tax_code_templates_to_find = [818 tax_code_templates_to_find = [
751 tax_template.base_code_id,819 tax_template.base_code_id,
@@ -754,8 +822,9 @@
754 tax_template.ref_tax_code_id822 tax_template.ref_tax_code_id
755 ]823 ]
756 for tax_code_template in [tmpl for tmpl in tax_code_templates_to_find if tmpl]:824 for tax_code_template in [tmpl for tmpl in tax_code_templates_to_find if tmpl]:
757 self._map_tax_code_template(cr, uid, wizard, tax_code_template_mapping, tax_code_template)825 self._map_tax_code_template(cr, uid, wizard,
758826 tax_code_template_mapping,
827 tax_code_template, context=context)
759 # Values828 # Values
760 vals_tax = {829 vals_tax = {
761 'name': tax_template.name,830 'name': tax_template.name,
@@ -783,10 +852,8 @@
783 'company_id': wizard.company_id.id,852 'company_id': wizard.company_id.id,
784 'type_tax_use': tax_template.type_tax_use853 'type_tax_use': tax_template.type_tax_use
785 }854 }
786
787 tax_id = None855 tax_id = None
788 modified = False856 modified = False
789
790 if wiz_tax.type == 'new':857 if wiz_tax.type == 'new':
791 # Create a new tax.858 # Create a new tax.
792 tax_id = taxes.create(cr, uid, vals_tax)859 tax_id = taxes.create(cr, uid, vals_tax)
@@ -802,17 +869,14 @@
802 modified = True869 modified = True
803 else:870 else:
804 tax_id = wiz_tax.update_tax_id and wiz_tax.update_tax_id.id871 tax_id = wiz_tax.update_tax_id and wiz_tax.update_tax_id.id
805
806 # Update the tax template map872 # Update the tax template map
807 tax_template_mapping[tax_template.id] = tax_id873 tax_template_mapping[tax_template.id] = tax_id
808
809 if modified:874 if modified:
810 # Add to the dict of taxes waiting for accounts.875 # Add to the dict of taxes waiting for accounts.
811 taxes_pending_for_accounts[tax_id] = {876 taxes_pending_for_accounts[tax_id] = {
812 'account_collected_id': tax_template.account_collected_id and tax_template.account_collected_id.id or False,877 'account_collected_id': tax_template.account_collected_id and tax_template.account_collected_id.id or False,
813 'account_paid_id': tax_template.account_paid_id and tax_template.account_paid_id.id or False,878 'account_paid_id': tax_template.account_paid_id and tax_template.account_paid_id.id or False,
814 }879 }
815
816 # Detect errors880 # Detect errors
817 if tax_template.parent_id and not tax_template_mapping.get(tax_template.parent_id.id):881 if tax_template.parent_id and not tax_template_mapping.get(tax_template.parent_id.id):
818 log.add(_("Tax %s: The parent tax %s can not be set.\n") % (tax_template.name, tax_template.parent_id.name), True)882 log.add(_("Tax %s: The parent tax %s can not be set.\n") % (tax_template.name, tax_template.parent_id.name), True)
@@ -824,7 +888,6 @@
824 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)888 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)
825 if tax_template.ref_tax_code_id and not tax_code_template_mapping.get(tax_template.ref_tax_code_id.id):889 if tax_template.ref_tax_code_id and not tax_code_template_mapping.get(tax_template.ref_tax_code_id.id):
826 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)890 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)
827
828 return {891 return {
829 'new': new_taxes,892 'new': new_taxes,
830 'updated': updated_taxes,893 'updated': updated_taxes,
@@ -867,28 +930,22 @@
867 """930 """
868 accounts = self.pool.get('account.account')931 accounts = self.pool.get('account.account')
869 root_account_id = wizard.chart_template_id.account_root_id.id932 root_account_id = wizard.chart_template_id.account_root_id.id
870
871 # Disable the parent_store computing on account_account during the batch933 # Disable the parent_store computing on account_account during the batch
872 # processing, we will force _parent_store_compute afterwards.934 # processing, we will force _parent_store_compute afterwards.
873 self.pool._init = True935 self.pool._init = True
874 new_accounts = 0936 new_accounts = 0
875 updated_accounts = 0937 updated_accounts = 0
876 account_template_mapping = {}938 account_template_mapping = {}
877
878 for wiz_account in wizard.account_ids:939 for wiz_account in wizard.account_ids:
879 account_template = wiz_account.account_id940 account_template = wiz_account.account_id
880
881 # Ensure the parent account template is on the map.941 # Ensure the parent account template is on the map.
882 self._map_account_template(cr, uid, wizard, account_template_mapping, account_template.parent_id, context)942 self._map_account_template(cr, uid, wizard, account_template_mapping, account_template.parent_id, context)
883
884 # Ensure the related tax templates are on the map.943 # Ensure the related tax templates are on the map.
885 for tax_template in account_template.tax_ids:944 for tax_template in account_template.tax_ids:
886 self._map_tax_template(cr, uid, wizard, tax_template_mapping,945 self._map_tax_template(cr, uid, wizard, tax_template_mapping,
887 tax_template, context)946 tax_template, context)
888
889 # Get the tax ids947 # Get the tax ids
890 tax_ids = [tax_template_mapping[tax_template.id] for tax_template in account_template.tax_ids if tax_template_mapping[tax_template.id]]948 tax_ids = [tax_template_mapping[tax_template.id] for tax_template in account_template.tax_ids if tax_template_mapping[tax_template.id]]
891
892 # Calculate the account code (we need to add zeros to non-view949 # Calculate the account code (we need to add zeros to non-view
893 # account codes)950 # account codes)
894 code = account_template.code or ''951 code = account_template.code or ''
@@ -896,7 +953,6 @@
896 if len(code) > 0 and len(code) <= wizard.code_digits:953 if len(code) > 0 and len(code) <= wizard.code_digits:
897 code = '%s%s' % (954 code = '%s%s' % (
898 code, '0' * (wizard.code_digits - len(code)))955 code, '0' * (wizard.code_digits - len(code)))
899
900 # Values956 # Values
901 vals = {957 vals = {
902 'name': (root_account_id == account_template.id) and wizard.company_id.name or account_template.name,958 'name': (root_account_id == account_template.id) and wizard.company_id.name or account_template.name,
@@ -912,10 +968,8 @@
912 'tax_ids': [(6, 0, tax_ids)],968 'tax_ids': [(6, 0, tax_ids)],
913 'company_id': wizard.company_id.id,969 'company_id': wizard.company_id.id,
914 }970 }
915
916 account_id = None971 account_id = None
917 modified = False972 modified = False
918
919 if wiz_account.type == 'new':973 if wiz_account.type == 'new':
920 # Create the account974 # Create the account
921 try:975 try:
@@ -939,68 +993,65 @@
939 % (code, ex.name, ex.value), True)993 % (code, ex.name, ex.value), True)
940 else:994 else:
941 account_id = wiz_account.update_account_id and wiz_account.update_account_id.id995 account_id = wiz_account.update_account_id and wiz_account.update_account_id.id
942
943 # Store the account on the map996 # Store the account on the map
944 account_template_mapping[account_template.id] = account_id997 account_template_mapping[account_template.id] = account_id
945
946 if modified:998 if modified:
947 # Detect errors999 # Detect errors
948 if account_template.parent_id and not account_template_mapping.get(account_template.parent_id.id):1000 if account_template.parent_id and not account_template_mapping.get(account_template.parent_id.id):
949 log.add(_("Account %s: The parent account %s can not be set.\n") % (code, account_template.parent_id.code), True)1001 log.add(_("Account %s: The parent account %s can not be set.\n") % (code, account_template.parent_id.code), True)
950
951 # Set this account as the parent of the accounts that seem to1002 # Set this account as the parent of the accounts that seem to
952 # be its children (brothers starting with the same code).1003 # be its children (brothers starting with the same code).
953 if wizard.update_children_accounts_parent:1004 if wizard.update_children_accounts_parent:
954 self._update_children_accounts_parent(1005 self._update_children_accounts_parent(
955 cr, uid, wizard, log, account_id, context=context)1006 cr, uid, wizard, log, account_id, context=context)
956
957 # Reenable the parent_store computing on account_account1007 # Reenable the parent_store computing on account_account
958 # and force the recomputation.1008 # and force the recomputation.
959 self.pool._init = False1009 self.pool._init = False
960 self.pool.get('account.account')._parent_store_compute(cr)1010 self.pool.get('account.account')._parent_store_compute(cr)
961
962 return {1011 return {
963 'new': new_accounts,1012 'new': new_accounts,
964 'updated': updated_accounts,1013 'updated': updated_accounts,
965 'mapping': account_template_mapping1014 'mapping': account_template_mapping
966 }1015 }
9671016
968 def _update_taxes_pending_for_accounts(self, cr, uid, wizard, log, taxes_pending_for_accounts, account_template_mapping, context=None):1017 def _update_taxes_pending_for_accounts(self, cr, uid, wizard, log,
1018 taxes_pending_for_accounts,
1019 acc_templ_mapping, context=None):
969 """1020 """
970 Updates the taxes (created or updated on previous steps) to set1021 Updates the taxes (created or updated on previous steps) to set
971 the references to the accounts (the taxes where created/updated first,1022 the references to the accounts (the taxes where created/updated first,
972 when the referenced accounts where still not available).1023 when the referenced accounts where still not available).
973 """1024 """
974 taxes = self.pool.get('account.tax')1025 taxes = self.pool['account.tax']
975 accounts_template = self.pool.get('account.account.template')1026 accounts_template = self.pool['account.account.template']
976
977 for key, value in taxes_pending_for_accounts.items():1027 for key, value in taxes_pending_for_accounts.items():
978 # Ensure the related account templates are on the map.1028 # Ensure the related account templates are on the map.
979 if value['account_collected_id']:1029 if value['account_collected_id']:
980 account_template = accounts_template.browse(1030 acc_templ = accounts_template.browse(
981 cr, uid, value['account_collected_id'], context=context)1031 cr, uid, value['account_collected_id'], context=context)
982 self._map_account_template(cr, uid, wizard, account_template_mapping, account_template, context)1032 self._map_account_template(cr, uid, wizard, acc_templ_mapping,
1033 acc_templ, context=context)
983 if value['account_paid_id']:1034 if value['account_paid_id']:
984 account_template = accounts_template.browse(1035 acc_templ = accounts_template.browse(
985 cr, uid, value['account_paid_id'], context=context)1036 cr, uid, value['account_paid_id'], context=context)
986 self._map_account_template(cr, uid, wizard, account_template_mapping, account_template, context)1037 self._map_account_template(cr, uid, wizard, acc_templ_mapping,
9871038 acc_templ, context=context)
988 if value['account_collected_id'] or value['account_paid_id']:1039 if value['account_collected_id'] or value['account_paid_id']:
989 if account_template_mapping.get(value['account_collected_id']) and account_template_mapping.get(value['account_paid_id']):1040 if acc_templ_mapping.get(value['account_collected_id']) and acc_templ_mapping.get(value['account_paid_id']):
990 vals = {1041 vals = {
991 'account_collected_id': account_template_mapping[value['account_collected_id']],1042 'account_collected_id': acc_templ_mapping[value['account_collected_id']],
992 'account_paid_id': account_template_mapping[value['account_paid_id']],1043 'account_paid_id': acc_templ_mapping[value['account_paid_id']],
993 }1044 }
994 taxes.write(cr, uid, [key], vals)1045 taxes.write(cr, uid, [key], vals)
995 else:1046 else:
996 tax = taxes.browse(cr, uid, key)1047 tax = taxes.browse(cr, uid, key)
997 if not account_template_mapping.get(value['account_collected_id']):1048 if not acc_templ_mapping.get(value['account_collected_id']):
998 log.add(_("Tax %s: The collected account can not be set.\n") % (tax.name), True)1049 log.add(_("Tax %s: The collected account can not be set.\n") % (tax.name), True)
999 if not account_template_mapping.get(value['account_paid_id']):1050 if not acc_templ_mapping.get(value['account_paid_id']):
1000 log.add(_("Tax %s: The paid account can not be set.\n")1051 log.add(_("Tax %s: The paid account can not be set.\n")
1001 % (tax.name), True)1052 % (tax.name), True)
10021053
1003 def _update_fiscal_positions(self, cr, uid, wizard, log, tax_template_mapping, account_template_mapping, context=None):1054 def _update_fiscal_positions(self, cr, uid, wizard, log, tax_template_mapping, acc_templ_mapping, context=None):
1004 """1055 """
1005 Search for, and load, fiscal position templates to create/update.1056 Search for, and load, fiscal position templates to create/update.
1006 """1057 """
@@ -1063,20 +1114,26 @@
1063 # (Re)create the account mappings1114 # (Re)create the account mappings
1064 for fp_account in fp_template.account_ids:1115 for fp_account in fp_template.account_ids:
1065 # Ensure the related account templates are on the map.1116 # Ensure the related account templates are on the map.
1066 self._map_account_template(cr, uid, wizard, account_template_mapping, fp_account.account_src_id, context)1117 self._map_account_template(cr, uid, wizard,
1118 acc_templ_mapping,
1119 fp_account.account_src_id,
1120 context=context)
1067 if fp_account.account_dest_id:1121 if fp_account.account_dest_id:
1068 self._map_account_template(cr, uid, wizard, account_template_mapping, fp_account.account_dest_id, context)1122 self._map_account_template(cr, uid, wizard,
1123 acc_templ_mapping,
1124 fp_account.account_dest_id,
1125 context=context)
1069 # Create the fp account mapping1126 # Create the fp account mapping
1070 vals_account = {1127 vals_account = {
1071 'account_src_id': account_template_mapping.get(fp_account.account_src_id.id),1128 'account_src_id': acc_templ_mapping.get(fp_account.account_src_id.id),
1072 'account_dest_id': fp_account.account_dest_id and account_template_mapping.get(fp_account.account_dest_id.id),1129 'account_dest_id': fp_account.account_dest_id and acc_templ_mapping.get(fp_account.account_dest_id.id),
1073 'position_id': fp_id,1130 'position_id': fp_id,
1074 }1131 }
1075 fiscalpositions_account.create(cr, uid, vals_account)1132 fiscalpositions_account.create(cr, uid, vals_account)
1076 # Check for errors1133 # Check for errors
1077 if not account_template_mapping.get(fp_account.account_src_id.id):1134 if not acc_templ_mapping.get(fp_account.account_src_id.id):
1078 log.add(_("Fiscal position %s: The source account %s can not be set.\n") % (fp_template.name, fp_account.account_src_id.code), True)1135 log.add(_("Fiscal position %s: The source account %s can not be set.\n") % (fp_template.name, fp_account.account_src_id.code), True)
1079 if fp_account.account_dest_id and not account_template_mapping.get(fp_account.account_dest_id.id):1136 if fp_account.account_dest_id and not acc_templ_mapping.get(fp_account.account_dest_id.id):
1080 log.add(_("Fiscal position %s: The destination account %s can not be set.\n") % (fp_template.name, fp_account.account_dest_id.code), True)1137 log.add(_("Fiscal position %s: The destination account %s can not be set.\n") % (fp_template.name, fp_account.account_dest_id.code), True)
10811138
1082 log.add(_("Created or updated fiscal position %s.\n")1139 log.add(_("Created or updated fiscal position %s.\n")
@@ -1090,29 +1147,42 @@
1090 if context is None:1147 if context is None:
1091 context = {}1148 context = {}
1092 wizard = self.browse(cr, uid, ids[0], context=context)1149 wizard = self.browse(cr, uid, ids[0], context=context)
1093
1094 if wizard.lang:1150 if wizard.lang:
1095 context['lang'] = wizard.lang1151 context['lang'] = wizard.lang
1096 elif context.get('lang'):1152 elif context.get('lang'):
1097 del context['lang']1153 del context['lang']
1098
1099 log = WizardLog()1154 log = WizardLog()
11001155 # Defaults when calculations are not done
1156 tax_codes_res = {'mapping': {}}
1157 taxes_res = {'mapping': {}, 'pending': {}}
1158 accounts_res = {'mapping': {}}
1159 fps_res = {}
1101 # Create or update the records.1160 # Create or update the records.
1102 tax_codes_res = self._update_tax_codes(1161 if wizard.update_tax_code:
1103 cr, uid, wizard, log, context=context)1162 tax_codes_res = self._update_tax_codes(cr, uid, wizard, log,
1104 taxes_res = self._update_taxes(1163 context=context)
1105 cr, uid, wizard, log, tax_codes_res['mapping'], context=context)1164 if wizard.update_tax:
1106 accounts_res = self._update_accounts(1165 taxes_res = self._update_taxes(cr, uid, wizard, log,
1107 cr, uid, wizard, log, taxes_res['mapping'], context=context)1166 tax_codes_res['mapping'],
1108 self._update_taxes_pending_for_accounts(cr, uid, wizard, log, taxes_res['pending'], accounts_res['mapping'], context=context)1167 context=context)
1109 fps_res = self._update_fiscal_positions(cr, uid, wizard, log, taxes_res['mapping'], accounts_res['mapping'], context=context)1168 if wizard.update_account:
11101169 accounts_res = self._update_accounts(cr, uid, wizard, log,
1170 taxes_res['mapping'],
1171 context=context)
1172 if wizard.update_tax and wizard.update_account:
1173 self._update_taxes_pending_for_accounts(cr, uid, wizard, log,
1174 taxes_res['pending'],
1175 accounts_res['mapping'],
1176 context=context)
1177 if wizard.update_fiscal_position:
1178 fps_res = self._update_fiscal_positions(cr, uid, wizard, log,
1179 taxes_res['mapping'],
1180 accounts_res['mapping'],
1181 context=context)
1111 # Check if errors where detected and wether we should stop.1182 # Check if errors where detected and wether we should stop.
1112 if log.has_errors() and not wizard.continue_on_errors:1183 if log.has_errors() and not wizard.continue_on_errors:
1113 raise orm.except_orm(_('Error'), _(1184 raise orm.except_orm(_('Error'), _(
1114 "One or more errors detected!\n\n%s") % log.get_errors_str())1185 "One or more errors detected!\n\n%s") % log.get_errors_str())
1115
1116 # Store the data and go to the next step.1186 # Store the data and go to the next step.
1117 self.write(cr, uid, [wizard.id], {1187 self.write(cr, uid, [wizard.id], {
1118 'state': 'done',1188 'state': 'done',
@@ -1125,8 +1195,7 @@
1125 'updated_accounts': accounts_res.get('updated', 0),1195 'updated_accounts': accounts_res.get('updated', 0),
1126 'updated_fps': fps_res.get('updated', 0),1196 'updated_fps': fps_res.get('updated', 0),
1127 'log': log(),1197 'log': log(),
1128 }, context)1198 }, context=context)
1129
1130 return _reopen(self, wizard.id, 'wizard.update.chart.accounts')1199 return _reopen(self, wizard.id, 'wizard.update.chart.accounts')
11311200
11321201
11331202
=== modified file 'account_chart_update/wizard/wizard_chart_update_view.xml'
--- account_chart_update/wizard/wizard_chart_update_view.xml 2013-10-15 14:28:59 +0000
+++ account_chart_update/wizard/wizard_chart_update_view.xml 2014-05-20 00:05:21 +0000
@@ -23,7 +23,9 @@
23 <field name="company_id" on_change="onchange_company_id(company_id)"23 <field name="company_id" on_change="onchange_company_id(company_id)"
24 attrs="{'invisible':[('state','!=','init')]}" />24 attrs="{'invisible':[('state','!=','init')]}" />
25 <field name="code_digits" attrs="{'invisible':[('state','!=','init')]}" />25 <field name="code_digits" attrs="{'invisible':[('state','!=','init')]}" />
26 <field name="chart_template_id" attrs="{'invisible':[('state','!=','init')]}" />26 <field name="chart_template_id"
27 domain="[('visible', '=', True)]"
28 attrs="{'invisible': [('state','!=','init')], 'required': True}"/>
27 <field name="lang" attrs="{'invisible':[('state','!=','init')]}" />29 <field name="lang" attrs="{'invisible':[('state','!=','init')]}" />
28 </group>30 </group>
29 <group attrs="{'invisible':[('state','!=','init')]}">31 <group attrs="{'invisible':[('state','!=','init')]}">
@@ -48,73 +50,45 @@
48 <group attrs="{'invisible':[('state','!=','ready'),]}"50 <group attrs="{'invisible':[('state','!=','ready'),]}"
49 string="Records to create/update">51 string="Records to create/update">
50 <notebook colspan="4">52 <notebook colspan="4">
51 <page string="Tax codes">53 <page string="Tax codes" attrs="{'invisible': [('update_tax_code', '=', False)]}">
52 <field name="tax_code_ids">54 <field name="tax_code_ids">
53 <tree string="Tax codes" colors="red:type=='updated'">55 <tree string="Tax codes" colors="red:type=='updated'">
54 <field name="tax_code_id" />56 <field name="tax_code_id" />
55 <field name="update_tax_code_id" />57 <field name="update_tax_code_id" />
58 <field name="notes" readonly="1" />
56 <field name="type" invisible="1" />59 <field name="type" invisible="1" />
57 </tree>60 </tree>
58 <form string="Tax code" version="7.0">
59 <group>
60 <field name="tax_code_id" />
61 <field name="type" />
62 <field name="update_tax_code_id" />
63 <field name="notes" readonly="1" class="oe_inline" />
64 </group>
65 </form>
66 </field>61 </field>
67 </page>62 </page>
6863
69 <page string="Taxes">64 <page string="Taxes" attrs="{'invisible': [('update_tax', '=', False)]}">
70 <field name="tax_ids" nolabel="1">65 <field name="tax_ids" nolabel="1">
71 <tree string="Taxes" colors="red:type=='updated'">66 <tree string="Taxes" colors="red:type=='updated'">
72 <field name="tax_id" />67 <field name="tax_id" />
73 <field name="update_tax_id" />68 <field name="update_tax_id" />
69 <field name="notes" readonly="1"/>
74 <field name="type" invisible="1" />70 <field name="type" invisible="1" />
75 </tree>71 </tree>
76 <form string="Tax" version="7.0">
77 <group>
78 <field name="tax_id" />
79 <field name="type" />
80 <field name="update_tax_id" />
81 <field name="notes" readonly="1" class="oe_inline" />
82 </group>
83 </form>
84 </field>72 </field>
85 </page>73 </page>
86 <page string="Accounts">74 <page string="Accounts" attrs="{'invisible': [('update_account', '=', False)]}">
87 <field name="account_ids" nolabel="1">75 <field name="account_ids" nolabel="1">
88 <tree string="Accounts" colors="red:type=='updated'">76 <tree string="Accounts" colors="red:type=='updated'">
89 <field name="account_id" />77 <field name="account_id" />
90 <field name="update_account_id" />78 <field name="update_account_id" />
79 <field name="notes" readonly="1"/>
91 <field name="type" invisible="1" />80 <field name="type" invisible="1" />
92 </tree>81 </tree>
93 <form string="Account" version="7.0">
94 <group>
95 <field name="account_id" />
96 <field name="type" />
97 <field name="update_account_id" />
98 <field name="notes" readonly="1" class="oe_inline" />
99 </group>
100 </form>
101 </field>82 </field>
102 </page>83 </page>
103 <page string="Fiscal positions">84 <page string="Fiscal positions" attrs="{'invisible': [('update_fiscal_position', '=', False)]}">
104 <field name="fiscal_position_ids" nolabel="1">85 <field name="fiscal_position_ids" nolabel="1">
105 <tree string="Fiscal positions" colors="red:type=='updated'">86 <tree string="Fiscal positions" colors="red:type=='updated'">
106 <field name="fiscal_position_id" />87 <field name="fiscal_position_id" />
107 <field name="update_fiscal_position_id" />88 <field name="update_fiscal_position_id" />
89 <field name="notes" readonly="1" />
108 <field name="type" invisible="1" />90 <field name="type" invisible="1" />
109 </tree>91 </tree>
110 <form string="Fiscal position" version="7.0">
111 <group>
112 <field name="fiscal_position_id" />
113 <field name="type" />
114 <field name="update_fiscal_position_id" />
115 <field name="notes" readonly="1" class="oe_inline" />
116 </group>
117 </form>
118 </field>92 </field>
119 </page>93 </page>
12094
@@ -153,6 +127,9 @@
153 or127 or
154 <button special="cancel" string="Cancel" class="oe_link" />128 <button special="cancel" string="Cancel" class="oe_link" />
155 </div>129 </div>
130 <div states="done">
131 <button special="cancel" string="Close" class="oe_link" />
132 </div>
156 </footer>133 </footer>
157 </form>134 </form>
158 </field>135 </field>

Subscribers

People subscribed via source and target branches