How Can We Help?

使用 Openupgrade 升級 Odoo 9.0 除錯篇 (未完成)

You are here:
< All Topics

這篇教學是用來記錄使用 OpenUpgrade(.238)升級 Odoo 8.0(.237)至 9.0(.239)的流程

需準備獨立環境進行升級,並將套件更新至最新版,減少出錯的機率

sudo apt-get update
sudo apt-get -y upgrade

資料庫升級前修正

1.錯誤訊息 Can’t find .pfb for face ‘Times-Roman’

依照此連結 http://stackoverflow.com/questions/28281891/cant-setfonttimes-roman-missing-the-t1-files

下載 pfb 檔案後,解壓縮至 /usr/lib/python2.7/dist-packages/reportlab/fonts/

fonts 目錄可能並不存在,需要先手動建立

wget http://www.reportlab.com/ftp/fonts/pfbfer.zip

unzip pfbfer.zip

sudo mkdir /usr/lib/python2.7/dist-packages/reportlab/fonts/

sudo mv *.pfb /usr/lib/python2.7/dist-packages/reportlab/fonts/

 

2. 錯誤訊息

DETAIL:  Key (channel_id)=(2) is not present in table "mail_channel".

由於 mail_followers 表中有紀錄指向 mail.group,造成 mail.group 無法改名為 mail.channel

於 phppgadmin 中執行以下 SQL 指令

delete from mail_followers where res_model = 'mail.group'

 

3. 錯誤訊息

raise UserError(_('Conversion from Product UoM %s to Default UoM %s is not possible as they both belong to different Category!.') % (from_unit.name,to_unit.name))
UserError: (u'Conversion from Product UoM Unit(s) to Default UoM Hour(s) is not possible as they both belong to different Category!.', None)

是由於有一樣服務產品,度量單位(UOM)為『小時』,但 UOS 卻是『件』

此問題同時存在於 product_template 與 account_invoice_line 之中,需一起修正

於 phppgadmin 中執行以下 SQL 指令

select * from product_template where uom_id = 15
update product_template set uos_id = 15 where uom_id = 15
select * from account_invoice_line where product_id = 182
update account_invoice_line set uos_id = 15 where product_id = 182
select * from account_invoice_line where uos_id = 15

 

4. 移除無法正常升級的模組,部分建議先行移除,升級完畢後再重新安裝

直接移除

im_chat:
會造成升級後系統 Layout 破損,無法正常使用

custom_filter_tabs:
已內建此功能

c2c_period_yyyymm:
9.0 好像取消 Period 了

wk_base_partner_patch:
新版 MOB 模組疑除此模組了

account_invoice_zero_autopay:
無 9.0 版可用

account_refund_invoice_fix:
無 9.0 版可用

account_refund_original:
無 9.0 版可用

report_xls:
無 9.0 版可用
需於 mis_builder 中的 __openerp__.py,移除相依性,再移除

 

先移除,再重新安裝

Disable force availability button
Mass Editing
MIS Builder

 

5. 加速測試流程(跳過 Accounting Reconcile 的部分)

truncate table account_move_reconcile cascade

 

6.  下載新版套件(下列有三個套件尚未升級完成,)

Base Currency Inverse Rate
https://www.odoo.com/apps/modules/9.0/base_currency_inverse_rate/
cd /var/tmp
git clone -b 9.0 --depth 1 https://github.com/ingadhoc/account-financial-tools.git
sudo cp -rf /var/tmp/account-financial-tools/base_currency_inverse_rate /opt/apps_odoo9

Account Invoice Zero Autopay
git clone -b 9.0 --depth 1 https://github.com/OCA/partner-contact.git
sudo cp -rf /var/tmp/account-invoicing/account_invoice_zero_autopay /opt/apps_odoo9

Relationship refund - origin invoice
git clone -b 9.0 --depth 1 https://github.com/OCA/l10n-spain.git
sudo cp -rf /var/tmp/l10n-spain/account_refund_original /opt/apps_odoo9

Disable force availability button
https://www.odoo.com/apps/modules/9.0/stock_disable_force_availability_button/
git clone -b 9.0 --depth 1 https://github.com/odoomrp/odoomrp-utils.git
sudo cp -rf /var/tmp/odoomrp-utils/stock_disable_force_availability_button /opt/apps_odoo9

Partner auto salesman(激安不需要)
git clone -b 9.0 --depth 1 https://github.com/OCA/account-invoicing.git
sudo cp -rf /var/tmp/partner-contact/partner_auto_salesman /opt/apps_odoo9

 

前置準備作業

安裝必要元件,並更新套件
sudo apt-get install -y git
sudo easy_install decorator requests pyPdf passlib openerp-client-lib
sudo chown -R odoo: /opt/odoo_apps
升級 Odoo 至最新版本,並更新模組

建議執行,減少出錯機率(尚未更新)

sudo su - odoo -s /bin/bash
vi /opt/odoo_apps/server/install/openerp-server.conf (非必要)
/usr/bin/odoo.py -d GAPL --update=all --stop-after-init
下載 OpenUpgrade
cd /var/tmp
git clone --branch 9.0 https://github.com/OpenUpgrade/OpenUpgrade.git
mkdir -p /var/tmp/openupgrade/9.0/
ln -s /var/tmp/OpenUpgrade /var/tmp/openupgrade/9.0/server

升級流程

準備資料庫

備份需要升級的資料庫,並傳至 Openupgrade 主機後 Restore 至 Postgresql 中

Dump
pg_dump GAPL -U cewolf -f GAPL.sql

SCP
scp GAPL.sql cewolf@192.168.1.238:~

Restore
psql -U cewolf -d GAPL < GAPL.sql
進行升級
cd /var/tmp/openupgrade/9.0/server/
wget https://raw.githubusercontent.com/OpenUpgrade/OpenUpgrade/HEAD/scripts/migrate.py
python migrate.py --config=/etc/odoo/openerp-server.conf --database=Clone --run-migrations=9.0
檢查 Migration Log => 修正錯誤

根據經驗,升級通常不會一次就成功,尤其是有進行過客製化後,更需要重複修正,這時可以藉由 migration.log 來判斷該如何處理

檔案位置
/var/tmp/openupgrade/migration.log

Migration Log 包含了四種類型的紀錄

INFO:系統訊息(不重要)
DEBUG:進行修改的SQL語法
WARNING:一些警告,通常可以忽略
ERROR:錯誤訊息,如果跳 ERROR 之後還能執行,那就是可以忽略得 ERROR,如果會中斷 Migration 流程,必須優先解決

如果 Migration Log 最後幾行顯示的是

2016-02-26 11:34:15,528 23380 INFO Hanyu_migrated openerp.modules.loading: Modules loaded.
2016-02-26 11:34:15,531 23380 INFO Hanyu_migrated openerp.models: Computing parent left and right for table ir_ui_menu...
2016-02-26 11:34:15,720 23380 INFO Hanyu_migrated openerp.models: Computing parent left and right for table stock_location...
2016-02-26 11:34:15,738 23380 INFO Hanyu_migrated openerp.service.server: Initiating shutdown
2016-02-26 11:34:15,738 23380 INFO Hanyu_migrated openerp.service.server: Hit CTRL-C again or send a second signal to force the shutdown.

據經驗這表示已經升級完成了!

After Migration

好不容易完成升級了,接下來需要把升級完成的資料庫備份並轉移到 Odoo 9 的環境下

根據目前的經驗,剛升級完成的資料庫無法使用 Odoo 內建的 Restore 還原

必須使用 PSQL 還原後,再透過 odoo 的 –update=all 指令進行完整升級(參照 After migration

備份升級後的資料庫與產品 FileStore
Dump
pg_dump Clone_migrated -U cewolf -O -f GAPL_migrated.sql

Copy Image FileStore
cd /var/lib/odoo/.local/share/Odoo/filestore
tar zcvf odoo9.tar.gz ./Clone_migrated/
scp odoo9.tar.gz cewolf@192.168.1.239:~

SCP
scp GAPL_migrated.sql cewolf@192.168.1.239:~


到 Odoo 9 的 Server
PSQL Restore Database
psql -U cewolf -d GAPL < GAPL_migrated.sql

Restore
/home/cewolf/.local/share/Odoo/filestore/
使用 DB owner 執行下列語法(此處是使用 cewolf )
/usr/bin/odoo.py -d GAPL --update=all

看到了這行表示更新完成了
2016-03-02 10:30:47,525 1642 INFO Hv8 openerp.modules.loading: Modules loaded.
2016-03-02 10:30:47,528 1642 INFO Hv8 openerp.models: Computing parent left and right for table ir_ui_menu...

資料庫升級後修正

ALTER TABLE product_price_history ALTER COLUMN product_id SET NOT NULL

ALTER TABLE account_tax ALTER COLUMN tax_group_id SET NOT NULL

ALTER TABLE account_move_line ALTER COLUMN date_maturity SET NOT NULL

update account_chart_template set currency_id = 145 where currency_id is null

ALTER TABLE account_chart_template ALTER COLUMN currency_id SET NOT NULL

ALTER TABLE account_chart_template ALTER COLUMN transfer_account_id SET NOT NULL

ALTER TABLE “calendar_event_type” ADD CONSTRAINT “calendar_event_type_name_uniq” unique (name)

ALTER TABLE account_move_line ALTER COLUMN date_maturity SET NOT NULL

ALTER TABLE delivery_carrier ALTER COLUMN product_id SET NOT NULL

ALTER TABLE delivery_carrier ALTER COLUMN partner_id SET NOT NULL

 

ERP 內部設定

1. 更新 MOB 模組
2. 關閉報錯的 View

『設定』/『用戶介面』/『檢視』

搜尋 res.partner.opt_out.search(ID 為 1194),關閉即可

3. 重新設定新建客戶預設值

升級後新建客戶會發現在『會計分頁』中,預設的『應收科目』與『應付科目』不是不見了就是錯了

原因為原先的欄位名稱修改了

需要用 Admin 登入,到『設定』/『技術』/『動作』/『使用者定義之預設值』,搜尋 property_account 後修改

應收科目:property_account_receivable => property_account_receivable_id

應付科目:property_account_payable => property_account_payable_id

也可以用 SQL 來更新

update ir_values set name = 'property_account_receivable_id' where name = 'property_account_receivable'
update ir_values set name = 'property_account_payable_id' where name = 'property_account_payable'
4. 補完會計設定

Odoo 9.0 在會計模組作了相當大程度的修改

1. 可先至會計模組點右上角進度條補齊設定

2. 修改稅率

『會計』/『設計』/『會計』/『稅別』

將現有的『未稅價』、『含稅價』之中的『金額』由 0.0500% 修改為 5%

並於 Advanced Options 分頁中設定 Tax Group

3. 登記客戶付款時沒有付款方式

要去『會計』/『設定』/『會計』/『帳簿』

點進去後,到『進階設定』個別設定

可成為收款方式:勾選『Debit Methods』

可成為付款方式:勾選『付款方法』

注意!不要設定『貨幣』選項,除非是外幣帳戶!

4. 設定 Inter-Banks Transfer Account

Odoo 9 的設定多了這個必填的設定,主要是用來處理流動資金帳戶間的金流

到『會計』/『設定』/『設定』=> 『銀行和現金』/『設定』/『Inter-Bank Transfer Account』新增

名稱:Liquidity Transfers

代碼:隨意(如 6500)

類型:Current Assets

允許調節:勾選

6. 補齊產品分類設定

升級後,產品內的『成本計算方式』 移至『產品分類』下

產品分類內多了『存貨估價』,原先設定好的『入庫科目』『庫存輸出科目』被清空

所以需重新設定,到『銷售』/『設定』/『產品』/『產品分類』

『入庫科目』:6100

『出庫科目』:6200

『成本計算方式』:Real Price

『存貨估價』:Perpetual (automated)

可使用 Mass Editing 一次大量設定

Model:product.category

Field 1:property_stock_account_input_categ_id

Field 2:property_stock_account_output_categ_id

Field 3:property_cost_method

Field 4:property_valuation

7. 使用 Database Cleanup

MOB Magento Orders Mapping 清空了

因為新版的 MOB 將原本的 magento_orders 轉移至 wk_order_mapping

目前 wk_order_mapping 中的 erp_order_id 是關鍵

erp_order_id 對應的 sale_order 中的 ecommerce_channel 也需要同步修改為 magento 才行

update sale_order set ecommerce_channel = 'magento' where channel = 'magento'
alter table magento_orders add ecommerce_order_id int
update magento_orders set ecommerce_order_id = cast(mage_increment_id as int)
alter table magento_orders rename column order_ref to erp_order_id
alter table magento_orders rename column mage_increment_id to name
alter table magento_orders drop column oe_order_id
alter table magento_orders alter column ecommerce_order_id integer NOT null => contains null value
drop table wk_order_mapping
alter table magento_orders rename to wk_order_mapping
update magento_orders set mage_increment_id =replace(mage_increment_id,'100000','')
update magento_orders set mage_increment_id =replace(mage_increment_id,'10000','')
update magento_orders set mage_increment_id =replace(mage_increment_id,'10001','')

參考資料:

After migration

Automated migration script

Db migrated to odoo 8, update stuck at computing ir_ui_menu parent_left and parent_right

Table of Contents