← Back to team overview

credativ team mailing list archive

[Merge] lp:~sylvain-legal/openupgrade-addons/7.0-hr_expense into lp:openupgrade-addons

 

Sylvain LE GAL (GRAP) has proposed merging lp:~sylvain-legal/openupgrade-addons/7.0-hr_expense into lp:openupgrade-addons.

Requested reviews:
  OpenUpgrade Committers (openupgrade-committers)

For more details, see:
https://code.launchpad.net/~sylvain-legal/openupgrade-addons/7.0-hr_expense/+merge/186692

Principal tests : 
- create in 6.1, 5 hr_expense_expense. (one for each state) ; 
- create a 3 hr_expense_expense with note & with ref, with note & without ref,without note & with ref ; 
- create 3 hr_expense_line : with product & with uom ; without product & with uom ; without product and without uom ; 
-- 
https://code.launchpad.net/~sylvain-legal/openupgrade-addons/7.0-hr_expense/+merge/186692
Your team OpenUpgrade Committers is requested to review the proposed merge of lp:~sylvain-legal/openupgrade-addons/7.0-hr_expense into lp:openupgrade-addons.
=== added file 'hr_expense/migrations/7.0.1.0/openupgrade_analysis_work.txt'
--- hr_expense/migrations/7.0.1.0/openupgrade_analysis_work.txt	1970-01-01 00:00:00 +0000
+++ hr_expense/migrations/7.0.1.0/openupgrade_analysis_work.txt	2013-09-19 23:44:40 +0000
@@ -0,0 +1,60 @@
+---Fields in module 'hr_expense'---
+### hr.expense.expense is not linked with 'account.invoice' anymore. Nothing to do. 
+# However, it seems to be a bug, so script migration will backup the data.(field with legacy name)
+hr_expense   / hr.expense.expense       / invoice_id (many2one)         : DEL relation: account.invoice
+
+### Ignore, no existing data to push as messages
+hr_expense   / hr.expense.expense       / message_ids (one2many)        : NEW relation: mail.message
+
+### 'ref' field has been deleted in V7. 
+# Migration Choice : merging 'ref' with 'note' field to avoid data loss. OK.
+hr_expense   / hr.expense.expense       / ref (char)                    : DEL 
+
+### Changes in KEYS
+# DEL Keys : 'invoiced', 'paid'
+# NEW Keys : 'done'
+# 'invoiced' and 'paid' state have been merge in one unique state 'done'.
+# Script migration will replace 'invoiced' and 'paid' by 'done' state. (Cf. user_notes.txt #1)
+hr_expense   / hr.expense.expense       / state (selection)             : selection_keys is now '['accepted', 'cancelled', 'confirm', 'done', 'draft']' ('['accepted', 'cancelled', 'confirm', 'draft', 'invoiced', 'paid']')
+
+### Unable to know the voucher_id for existing hr_expense_expense object. Nothing to do. (Cf. user_notes.txt #3)
+hr_expense   / hr.expense.expense       / voucher_id (many2one)         : NEW relation: account.voucher
+
+### uom_id is now required. (That's weird because product_id is not required.)
+# script migration will get the UoM of the related product, if any. 
+# Otherwise, call the '_get_uom_id' function. OK.
+hr_expense   / hr.expense.line          / uom_id (many2one)             : now required, default = function
+
+
+### Modifications in report objects. (view). Nothing to do.
+hr_expense   / hr.expense.report        / invoice_id (many2one)         : DEL relation: account.invoice
+hr_expense   / hr.expense.report        / invoiced (integer)            : DEL 
+hr_expense   / hr.expense.report        / state (selection)             : selection_keys is now '['accepted', 'cancelled', 'confirm', 'done', 'draft']' ('['accepted', 'cancelled', 'confirm', 'draft', 'invoiced', 'paid']')
+hr_expense   / hr.expense.report        / voucher_id (many2one)         : NEW relation: account.voucher
+
+---XML records in module 'hr_expense'---
+### Ignore interface and access records
+NEW ir.actions.act_window: hr_expense.hr_expense_product
+DEL ir.actions.act_window: hr_expense.action_employee_expense
+NEW ir.actions.todo: base.open_menu
+DEL ir.actions.todo: hr_expense.product_normal_form_view_todo
+NEW ir.model.access: hr_expense.access_account_journal_employee
+DEL ir.model.access: hr.access_account_journal_column_hruser
+DEL ir.model.access: hr.access_account_journal_view_hruser
+NEW ir.ui.menu: hr_expense.menu_hr_product
+DEL ir.ui.menu: hr.menu_hr_reporting
+DEL ir.ui.view: hr_expense.board_hr_manager_expense_form
+
+### Ignore added chatter configuration
+NEW mail.message: hr_expense.module_install_notification
+NEW mail.message.subtype: hr_expense.mt_expense_approved
+NEW mail.message.subtype: hr_expense.mt_expense_confirmed
+NEW mail.message.subtype: hr_expense.mt_expense_refused
+
+### XML_id renames & change subflow -> function. (Cf. user_notes.txt #1)
+DEL workflow.activity: hr_expense.act_invoice
+NEW workflow.activity: hr_expense.act_done
+
+### Deleted state. (Cf. user_notes.txt #1)
+DEL workflow.activity: hr_expense.act_paid
+DEL workflow.transition: hr_expense.t9

=== added file 'hr_expense/migrations/7.0.1.0/post-migration.py'
--- hr_expense/migrations/7.0.1.0/post-migration.py	1970-01-01 00:00:00 +0000
+++ hr_expense/migrations/7.0.1.0/post-migration.py	2013-09-19 23:44:40 +0000
@@ -0,0 +1,151 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    This module copyright (C) 2013 Sylvain LE GAL
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+from openerp import pooler, SUPERUSER_ID
+from openerp.openupgrade import openupgrade
+
+def migrate_hr_expense_account_move(cr, pool):
+    """
+    Fill the field account_move_id with account_invoice information.
+    """
+    # (Cf. user_notes.txt #2)
+    invoice_obj = pool.get('account.invoice')
+    expense_obj = pool.get('hr.expense.expense')
+    cr.execute("""
+        SELECT id, {0}
+        FROM hr_expense_expense
+        WHERE {1} ='paid' AND account_move_id is Null
+        """.format(
+            openupgrade.get_legacy_name('invoice_id'),
+            openupgrade.get_legacy_name('state')))
+    for (expense_id, invoice_id) in cr.fetchall():
+        account_move_id = invoice_obj.browse(
+            cr, SUPERUSER_ID, invoice_id, context=None).move_id.id
+        expense_obj = pool.get('hr.expense.expense')
+        expense_obj.write(
+            cr, SUPERUSER_ID, [expense_id],
+            {'account_move_id': account_move_id})
+
+def migrate_hr_expense_expense_ref(cr, pool):
+    """
+    Join existing 'note' values and obsolete 'ref' values into
+    text field 'note' on the 'hr.expense.expense' model.
+    """
+    expense_obj = pool.get('hr.expense.expense')
+    cr.execute("""
+        SELECT id, {0}, {1}
+        FROM hr_expense_expense
+        WHERE {1} is not NULL AND {1} != ''
+        """.format(
+            'note',
+            openupgrade.get_legacy_name('ref')))
+    for (expense_id, note, ref) in cr.fetchall():
+        note = note + '\n' if note else ''
+        expense_obj.write(
+            cr, SUPERUSER_ID, [expense_id],
+            {'note': note + ref})
+
+def set_hr_expense_line_uom(cr, pool):
+    line_obj = pool.get('hr.expense.line')
+    product_obj = pool.get('product.product')
+    cr.execute("""
+        SELECT id, product_id
+        FROM hr_expense_line 
+        WHERE uom_id is Null
+        """)
+    for (line_id, product_id) in cr.fetchall():
+        if product_id: 
+            uom_id = product_obj.browse(
+                cr, SUPERUSER_ID, product_id, context=None).uom_id.id
+        else: 
+            uom_id = line_obj._get_uom_id(cr, SUPERUSER_ID, context=None)
+        line_obj.write(
+            cr, SUPERUSER_ID, [line_id],
+            {'uom_id': uom_id})
+
+def migrate_hr_expense_expense_state(cr, pool):
+    """
+    Change obsolete 'state' values for hr_expense_expense.state ; 
+    Manage workflow modifications.
+    """
+    model_obj  = pool.get('ir.model.data')
+    
+    # recover compatible states
+    cr.execute("""
+        UPDATE hr_expense_expense 
+        SET state = {0} 
+        WHERE {0} != 'invoiced' and {0} != 'paid'
+        """.format(openupgrade.get_legacy_name('state')))
+    
+    # set 'done' state instead of 'invoiced' and 'paid' 
+    cr.execute("""
+        UPDATE hr_expense_expense 
+        SET state = 'done'
+        WHERE {0} = 'invoiced' OR {0} = 'paid'
+        """.format(openupgrade.get_legacy_name('state')))
+    
+    #change wkf items that are in state 'paid', 
+    # setting act_id to act_done id. (before was act_paid id) ; 
+    act_done_id = model_obj.get_object(cr, SUPERUSER_ID, 'hr_expense', 'act_done').id
+    cr.execute("""
+        UPDATE wkf_workitem 
+        SET act_id = {0}
+        WHERE inst_id IN (
+            SELECT id 
+            FROM wkf_instance 
+            WHERE res_type='hr.expense.expense' AND res_id in (
+                SELECT id 
+                FROM hr_expense_expense 
+                WHERE {1}='paid'
+            )
+        );""".format(
+            act_done_id, 
+            openupgrade.get_legacy_name('state')))
+    
+    # Change wkf workitems from sublow to function
+    cr.execute("""
+        UPDATE wkf_workitem 
+        SET subflow_id = Null, state='complete'
+        WHERE inst_id IN (
+            SELECT id 
+            FROM wkf_instance 
+            WHERE res_type='hr.expense.expense' AND res_id in (
+                SELECT id 
+                FROM hr_expense_expense 
+                WHERE {0}='invoiced'
+            )
+        );""".format(openupgrade.get_legacy_name('state')))
+
+    # No more flow_end in hr_expense worfklow
+    cr.execute("""
+    UPDATE wkf_instance 
+        SET state='active'
+        WHERE res_type='hr.expense.expense' AND res_id in (
+            SELECT id 
+            FROM hr_expense_expense 
+            WHERE {0}='paid');""".format(openupgrade.get_legacy_name('state')))
+
+@openupgrade.migrate()
+def migrate(cr, version):
+    pool = pooler.get_pool(cr.dbname)
+    migrate_hr_expense_account_move(cr, pool)
+    migrate_hr_expense_expense_ref(cr, pool)
+    set_hr_expense_line_uom(cr, pool)
+    migrate_hr_expense_expense_state(cr, pool)

=== added file 'hr_expense/migrations/7.0.1.0/pre-migration.py'
--- hr_expense/migrations/7.0.1.0/pre-migration.py	1970-01-01 00:00:00 +0000
+++ hr_expense/migrations/7.0.1.0/pre-migration.py	2013-09-19 23:44:40 +0000
@@ -0,0 +1,39 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    This module copyright (C) 2013 Sylvain LE GAL
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+from openerp.openupgrade import openupgrade
+
+column_renames = {
+    'hr_expense_expense':[
+        ('invoice_id', None),
+        ('state', None),
+        ('ref', None),
+    ],
+}
+
+xmlid_renames = [
+    ('hr_expense.act_invoice', 'hr_expense.act_done'),
+]
+
+@openupgrade.migrate()
+def migrate(cr, version):
+    openupgrade.rename_columns(cr, column_renames)
+    openupgrade.rename_xmlids(cr, xmlid_renames)

=== added file 'hr_expense/migrations/7.0.1.0/user_notes.txt'
--- hr_expense/migrations/7.0.1.0/user_notes.txt	1970-01-01 00:00:00 +0000
+++ hr_expense/migrations/7.0.1.0/user_notes.txt	2013-09-19 23:44:40 +0000
@@ -0,0 +1,40 @@
+********************************************************************************
+1/ Change in state selection of 'hr_expense_expense.state'
+
+In 6.1 : 
+- 'invoiced' state with associated activity 'act_invoice' (kind : sublow 'account.wkf')
+- 'paid' state that with associated activity 'act_paid' that is flagged with 'flow_stop'.
+
+In 7.0 : 
+- 'done' state with associated activity 'act_done'. (kind : function)
+- no 'flow_stop' in wkf_expenses.
+
+Script migration will assume that : 
+- 'invoiced' is now 'done' ; 
+- 'paid' is obsoleted and changed to 'done' ; 
+
+pre-migration script will do : 
+- backup the old state, using a legacy field 'state' ; 
+- rename 'act_invoice' to 'act_paid' ; 
+
+post-migration script will do : 
+- in 'hr_expense_expense' change 'invoiced' / 'paid' to 'done' ; 
+- in wkf_workitem : change items that are in state 'paid', setting act_id to act_done. (before act_paid) ; 
+- in wkf_workitem : change items that are in state 'invoiced', setting sublow to None and state to complete (old was running) ; (because there is no more subflow association) ; 
+- in wkf_instance : change instances that are complete to active, because there is no more flow_stop activity ; 
+
+********************************************************************************
+2/ in 'hr_expense_expense' 'account_move_id' was not filled in V6.1
+
+In 6.1, the account_move_id is present in model but unused ; 
+In 7.0, the account_move_id is present, and filled from 'done' state.
+
+Conclusion : it's like a "NEW field".
+
+So there is a bug after migration, by clicking on the button 'Open Accounting Entries' for 'done' expenses. (old 'invoiced' and 'paid').
+
+To fix that, script migration will get the move_id of the account_invoice of the hr_expense for expense in 'paid' state.
+The problem persists for old 'invoiced' expense because in this state there is no account_move created.
+
+********************************************************************************
+3/ expense has now a 'voucher_id' field, but this field seems to be unused in 'hr_expense' module. 


Follow ups