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

Subscribers

People subscribed via source and target branches