Merge lp:~sylvain-legal/openupgrade-addons/7.0-account_with_cashbox into lp:openupgrade-addons

Proposed by Sylvain LE GAL (GRAP)
Status: Merged
Merged at revision: 8136
Proposed branch: lp:~sylvain-legal/openupgrade-addons/7.0-account_with_cashbox
Merge into: lp:openupgrade-addons
Diff against target: 184 lines (+120/-8)
3 files modified
account/migrations/7.0.1.1/openupgrade_analysis_work.txt (+22/-7)
account/migrations/7.0.1.1/post-migration.py (+92/-1)
account/migrations/7.0.1.1/pre-migration.py (+6/-0)
To merge this branch: bzr merge lp:~sylvain-legal/openupgrade-addons/7.0-account_with_cashbox
Reviewer Review Type Date Requested Status
Stefan Rijnhart (Opener) Approve
Holger Brunn (Therp) code review Approve
Review via email: mp+183767@code.launchpad.net

Commit message

[ADD] migration for account_cashbox_line.

Description of the change

Add the migration script for cashbox.

To post a comment you must log in.
Revision history for this message
Holger Brunn (Therp) (hbrunn) :
review: Approve (code review)
Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account/migrations/7.0.1.1/openupgrade_analysis_work.txt'
2--- account/migrations/7.0.1.1/openupgrade_analysis_work.txt 2013-07-24 12:41:33 +0000
3+++ account/migrations/7.0.1.1/openupgrade_analysis_work.txt 2013-09-05 20:31:43 +0000
4@@ -1,22 +1,37 @@
5 ---Fields in module 'account'---
6-### TODO: migrate cashbox opening and closing items
7+# 'opening_details_ids' replacing 'starting_details_ids' : one2many field based on account_cashbox_line.banck_statement_id (many2one) Nothing to do for the object account_banck_statement
8+account / account.bank.statement / starting_details_ids (one2many): DEL relation: account.cashbox.line
9+account / account.bank.statement / opening_details_ids (one2many): NEW relation: account.cashbox.line
10+
11+# 'closing_details_ids' replacing 'ending_details_ids' : one2many field based on account_cashbox_line.banck_statement_id (many2one) Nothing to do for the object account_banck_statement
12+account / account.bank.statement / ending_details_ids (one2many) : DEL relation: account.cashbox.line
13 account / account.bank.statement / closing_details_ids (one2many): NEW relation: account.cashbox.line
14+
15+# new field one2many based on account_cashbox_line.banck_statement_id (many2one) Nothing to do for the object account_banck_statement
16 account / account.bank.statement / details_ids (one2many) : NEW relation: account.cashbox.line
17-account / account.bank.statement / ending_details_ids (one2many) : DEL relation: account.cashbox.line
18-account / account.bank.statement / opening_details_ids (one2many): NEW relation: account.cashbox.line
19-account / account.bank.statement / starting_details_ids (one2many): DEL relation: account.cashbox.line
20+
21+### The account_cashbox_line concept changes a lot.
22+# Use case : in the cashbox : at the opening state, there is 1 '1 euro coin' and at the closing state, 3 '1 euro coin'.
23+# in 6.1 : there is 2 lines in account_cashbox_line. One with starting_id linked to the account_bank_statement (number=1), the other with the ending_id linked to the account_bank_statement (number=3)
24+# in 7.0 : there is one line with number_opening = 1 and number_closing = 3
25+# -> Migration script will delete all the "ending" and merge the data to the "starting" line. (If the starting line exists)
26 account / account.cashbox.line / bank_statement_id (many2one) : NEW relation: account.bank.statement
27 account / account.cashbox.line / ending_id (many2one) : DEL relation: account.bank.statement
28+account / account.cashbox.line / starting_id (many2one) : DEL relation: account.bank.statement
29 account / account.cashbox.line / number (integer) : DEL
30 account / account.cashbox.line / number_closing (integer) : NEW
31 account / account.cashbox.line / number_opening (integer) : NEW
32-account / account.cashbox.line / starting_id (many2one) : DEL relation: account.bank.statement
33+
34+### Ignore new fields
35 account / account.journal / cash_control (boolean) : NEW
36+account / account.journal / with_last_closing_balance (boolean): NEW
37 account / account.journal / cashbox_line_ids (one2many) : NEW relation: account.journal.cashbox.line
38-account / account.journal / with_last_closing_balance (boolean): NEW
39+account / account.journal / internal_account_id (many2one): NEW relation: account.account
40+
41+### Ignore new fields (new table)
42 account / account.journal.cashbox.line / journal_id (many2one) : NEW relation: account.journal, required: required
43 account / account.journal.cashbox.line / pieces (float) : NEW
44-account / account.journal / internal_account_id (many2one): NEW relation: account.account
45+
46
47 ### Ignore, no existing data to push as messages
48 account / account.bank.statement / message_ids (one2many) : NEW relation: mail.message
49
50=== modified file 'account/migrations/7.0.1.1/post-migration.py'
51--- account/migrations/7.0.1.1/post-migration.py 2013-07-24 12:41:33 +0000
52+++ account/migrations/7.0.1.1/post-migration.py 2013-09-05 20:31:43 +0000
53@@ -18,10 +18,12 @@
54 # along with this program. If not, see <http://www.gnu.org/licenses/>.
55 #
56 ##############################################################################
57-
58+import logging
59 from openerp import pooler, SUPERUSER_ID
60 from openerp.openupgrade import openupgrade, openupgrade_70
61
62+logger = logging.getLogger('OpenUpgrade')
63+
64 def migrate_invoice_addresses(cr, pool):
65 # Contact id takes precedence over old partner id
66 openupgrade_70.set_partner_id_from_partner_address_id(
67@@ -75,12 +77,101 @@
68 cr, SUPERUSER_ID, reconcile_ids,
69 {'opening_reconciliation': True})
70
71+def merge_account_cashbox_line(cr, pool):
72+ # Check an unmanaged case by the migration script
73+ cr.execute("""
74+ select count(*) as quantity2 from (
75+ SELECT count(*) as quantity1
76+ FROM account_cashbox_line
77+ GROUP BY %s, %s, pieces) as tmp
78+ WHERE quantity1 > 1
79+ """%(
80+ openupgrade.get_legacy_name('starting_id'),
81+ openupgrade.get_legacy_name('ending_id'),
82+ ))
83+ count = cr.fetchone()[0]
84+ if count>0:
85+ logger.error('Some duplicated datas in account_cashbox_line (%s). This case is not covered.' %(count))
86+
87+ cashboxline_obj = pool.get('account.cashbox.line')
88+ # Getting all the row from cashbox_line (type "ending")
89+ cr.execute("""
90+ SELECT id as id_end, pieces, %s as ending_id, %s as number
91+ FROM account_cashbox_line
92+ WHERE %s is not NULL AND bank_statement_id is NULL
93+ """ %(
94+ openupgrade.get_legacy_name('ending_id'),
95+ openupgrade.get_legacy_name('number'),
96+ openupgrade.get_legacy_name('ending_id'),
97+ ))
98+ for (id_end, pieces, ending_id, number) in cr.fetchall():
99+ # Check if there is some corresping cashbox_line (type "starting")
100+ cr.execute("""
101+ SELECT id, %s
102+ FROM account_cashbox_line
103+ WHERE %s=%s AND pieces=%s
104+ """ %(
105+ openupgrade.get_legacy_name('number'),
106+ openupgrade.get_legacy_name('starting_id'),
107+ ending_id,
108+ pieces,
109+ ))
110+
111+ if cr.rowcount==0:
112+ # "ending" cashbox_line becomes normal.
113+ cashboxline_obj.write(
114+ cr, SUPERUSER_ID, [id_end],
115+ {
116+ 'number_opening': 0,
117+ 'number_closing': number,
118+ 'bank_statement_id': ending_id,
119+ })
120+
121+ elif cr.rowcount==1:
122+ row = cr.fetchone()
123+ # "starting" cashbox_line becomes normal with data of "ending" cashbox_line
124+ cashboxline_obj.write(
125+ cr, SUPERUSER_ID, [row[0]],
126+ {
127+ 'number_opening': row[1],
128+ 'number_closing': number,
129+ 'bank_statement_id': ending_id,
130+ })
131+ # delete the "ending" cashbox_line
132+ cashboxline_obj.unlink(cr, SUPERUSER_ID, [id_end])
133+
134+ elif cr.rowcount>1:
135+ # there is duplicated datas in the 6.1 Database
136+ pass
137+
138+ # Getting all the rows from cashbox_line (type "starting") that didn't change
139+ cr.execute("""
140+ SELECT id as id_start, %s as starting_id, %s as number
141+ FROM account_cashbox_line
142+ WHERE %s is not NULL AND bank_statement_id is NULL
143+ """ %(
144+ openupgrade.get_legacy_name('starting_id'),
145+ openupgrade.get_legacy_name('number'),
146+ openupgrade.get_legacy_name('starting_id'),
147+ ))
148+
149+ for (id_start, starting_id, number) in cr.fetchall():
150+ cashboxline_obj.write(
151+ cr, SUPERUSER_ID, [id_start],
152+ {
153+ 'number_opening': number,
154+ 'number_closing': 0,
155+ 'bank_statement_id': starting_id,
156+ })
157+
158+
159 @openupgrade.migrate()
160 def migrate(cr, version):
161 pool = pooler.get_pool(cr.dbname)
162 migrate_invoice_addresses(cr, pool)
163 migrate_invoice_names(cr, pool)
164 lock_closing_reconciliations(cr, pool)
165+ merge_account_cashbox_line(cr, pool)
166 openupgrade.load_xml(
167 cr, 'account',
168 'migrations/7.0.1.1/data.xml')
169
170=== modified file 'account/migrations/7.0.1.1/pre-migration.py'
171--- account/migrations/7.0.1.1/pre-migration.py 2013-09-03 16:38:16 +0000
172+++ account/migrations/7.0.1.1/pre-migration.py 2013-09-05 20:31:43 +0000
173@@ -32,6 +32,12 @@
174 [
175 ('name', None),
176 ('note', None),
177+ ],
178+ 'account_cashbox_line':
179+ [
180+ ('ending_id', None),
181+ ('starting_id', None),
182+ ('number', None),
183 ]
184 }
185

Subscribers

People subscribed via source and target branches