使用 Openupgrade 升級至 Odoo 10.0 – 除錯篇

You are here:
< All Topics

完成 使用 Openupgrade 升級至 Odoo 10.0 – 準備篇 後,開始著手升級除錯了

執行升級語法
cd /var/tmp/openupgrade/10.0/server && python migrate.py --config=/opt/openerp-server.conf --database=odoo_v10 --run-migrations=10.0

資料庫升級後,一定會有需要修正的地方,嚴重時甚至無法完成升級

我們可以通過查看 migration.log 分析

vim /var/tmp/openupgrade/migration.log

升級資料庫遇到的問題可分為兩類:可『預先處理』與『事後處理』

預先處理

需預先處理的問題,大多數都是資料庫內的資料有異常,建議事先修正,才不會升級後無法使用

1. 升級完畢後出現了錯誤訊息

/opt/OpenUpgrade/odoo/models.py:403: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode – interpreting them as being unequal
elif not all(cols[field.name][key] == vals[key] for key in vals):

根據此文件 https://github.com/odoo/odoo/commit/c0ec09e9d56485f3c6a24593bbc0240f54e433c3

需修改 addons/mrp/model/mrp_bom.py

sed -i 's/help="When a procurement/help=u"When a procurement/g' /var/tmp/openupgrade/10.0/server/addons/mrp/models/mrp_bom.py && sed -i 's/orders with different BoMs. /orders with different BoMs./g' /var/tmp/openupgrade/10.0/server/addons/mrp/models/mrp_bom.py

完成後再次執行升級語法即可

2. bad query: ALTER TABLE “res_country_state” ADD CONSTRAINT “res_country_state_name_code_uniq” unique(country_id, code)

2018-03-02 17:22:44,829 2194 INFO v10_migrated odoo.sql_db: bad query: ALTER TABLE "res_country_state" ADD CONSTRAINT "res_country_state_name_code_uniq" unique(country_id, code)
 2018-03-02 17:22:44,829 2194 WARNING v10_migrated odoo.models.schema: Table 'res_country_state': unable to add constraint 'unique(country_id, code)'!
 If you want to have it, you should update the records and execute manually:
 ALTER TABLE "res_country_state" ADD CONSTRAINT "res_country_state_name_code_uniq" unique(country_id, code)

由於我們的州份中有完全重複的資料,因此在更新欄位屬性為唯一值時會報錯

ERROR:  could not create unique index "res_country_state_name_code_uniq"
DETAIL:  Key (country_id, code)=(229, å) is duplicated.

較簡單的解決方法是將重複的資料全部刪除(有些需先到聯絡人中修改地址資訊)

在開發者模式下 銷售/設定/聯絡人/本地化/州份 將台灣的縣市全部刪除後在執行

ALTER TABLE "res_country_state" ADD CONSTRAINT "res_country_state_name_code_uniq" unique(country_id, code)

3. bad query: ALTER TABLE “product_uom” ADD CONSTRAINT “product_uom_rounding_gt_zero” CHECK (rounding>0)

2018-03-05 06:38:30,818 8686 INFO odoo10_migrated odoo.sql_db: bad query: ALTER TABLE "product_uom" ADD CONSTRAINT "product_uom_rounding_gt_zero" CHECK (rounding>0)
 2018-03-05 06:38:30,819 8686 WARNING odoo10_migrated odoo.models.schema: Table 'product_uom': unable to add constraint 'CHECK (rounding>0)'!
 If you want to have it, you should update the records and execute manually:
 ALTER TABLE "product_uom" ADD CONSTRAINT "product_uom_rounding_gt_zero" CHECK (rounding>0)

我們系統中有幾個量度單位的 Rounding(捨入精度)為 0,但不能為 0,因此更新屬性時會報錯

ERROR:  check constraint "product_uom_rounding_gt_zero" is violated by some row

在開發者模式下,設定使用者的權限,開啟管理次要單位即可編輯,完成後再次執行

ALTER TABLE "product_uom" ADD CONSTRAINT "product_uom_rounding_gt_zero" CHECK (rounding>0)

4. Table ‘procurement_rule’: unable to set a NOT NULL constraint on column ‘picking_type_id’ !

2018-03-05 06:45:17,784 8686 WARNING odoo10_migrated odoo.models.schema: Table ‘procurement_rule’: unable to set a NOT NULL constraint on column ‘picking_type_id’ !
If you want to have it, you should update the records and execute manually:
ALTER TABLE procurement_rule ALTER COLUMN picking_type_id SET NOT NULL

研究後發現 Procurement Rule 中,有些 Record 沒有對應的 Picking Type(通常都是用不到的 Rule),可考慮直接刪除

delete from procurement_rule where picking_type_id SET is NULL

再更新資料表

ALTER TABLE procurement_rule ALTER COLUMN picking_type_id SET NOT NULL

5. IOError: [Errno 2] 沒有此一檔案或目錄

2018-03-02 17:24:21,095 2194 INFO v10_migrated odoo.addons.base.ir.ir_attachment: _read_file reading /root/.local/share/Odoo/filestore/v10_migrated/c2/c23bc6c927cbfa495f06c1e875cc5ca1e700ae53
Traceback (most recent call last):
File “/var/tmp/openupgrade/10.0/server/odoo/addons/base/ir/ir_attachment.py”, line 100, in _file_read
r = open(full_path,’rb’).read().encode(‘base64′)
IOError: [Errno 2] 沒有此一檔案或目錄: u’/root/.local/share/Odoo/filestore/v10_migrated/c2/c23bc6c927cbfa495f06c1e875cc5ca1e700ae53’

這部分很奇妙,因為我們資料庫的 filestore 是存放在 /var/lib/odoo/filestore 之中

使用 SQL 查詢

 select * from ir_attachment where store_fname = '/c2/c23bc6c927cbfa495f06c1e875cc5ca1e700ae53'

發現是 res.partner 中 Administrator 的 image,於是將伙伴 Administrator 的大頭照刪除即可

6. 交貨後 Sale Order Lines 不會顯示 delivered

Odoo 8.0 升級 9.0 時將 hr_expense_ok 改為 can_be_expense,並且多了 expense_policy 這個欄位(預設值為 cost

在 9.0 並沒有找到可以修改 expense_policy 的地方

但在 Odoo 10 中,即使產品 can_be_expense 未啟用,但只要 expense_policy 設定為 cost 時就不會進行欄位同步

可以使用 SQL 語法檢查,發現全部產品都是這個情況

select * from product_template where expense_policy = 'cost' and can_be_expensed is not true

使用 SQL 將全部產品 expense_policy 修改 “no” 即可解決

update product_template SET expense_policy = 'no' where expense_policy = 'cost'
升級後處理

升級後處理的問題,都是升級資料庫後新增欄位,需進一步設定欄位屬性

1. ALTER TABLE “mrp_production” ALTER COLUMN “picking_type_id” SET NOT NULL

2018-03-05 06:45:17,511 8686 INFO odoo10_migrated odoo.sql_db: bad query: ALTER TABLE “mrp_production” ALTER COLUMN “picking_type_id” SET NOT NULL
2018-03-05 06:45:17,512 8686 WARNING odoo10_migrated odoo.models: WARNING: unable to set column picking_type_id of table mrp_production not null !
Try to re-run: openerp-server –update=module
If it doesn’t work, update records and execute manually:
ALTER TABLE mrp_production ALTER COLUMN picking_type_id SET NOT NULL
Traceback (most recent call last):
File “/opt/OpenUpgrade/odoo/models.py”, line 2576, in _auto_init
cr.execute(‘ALTER TABLE “%s” ALTER COLUMN “%s” SET NOT NULL’ % (self._table, name))
File “/opt/OpenUpgrade/odoo/sql_db.py”, line 154, in wrapper
return f(self, *args, **kwargs)
File “/opt/OpenUpgrade/odoo/sql_db.py”, line 231, in execute
res = self._obj.execute(query, params)
IntegrityError: column “picking_type_id” contains null values

Odoo 10 中,MO多了 Picking Operation 的欄位,所以需要先製作一個 Manufacture Picking Operation 才能修正

使用 SQL 修正工單

update mrp_production set picking_type_id = " ?????"

再更新資料表

ALTER TABLE mrp_production ALTER COLUMN picking_type_id SET NOT NULL

2. bad query: ALTER TABLE “mrp_subproduct” ALTER COLUMN “product_uom_id” SET NOT NULL

2018-03-05 06:46:15,999 8686 INFO odoo10_migrated odoo.sql_db: bad query: ALTER TABLE “mrp_subproduct” ALTER COLUMN “product_uom_id” SET NOT NULL
2018-03-05 06:46:16,000 8686 WARNING odoo10_migrated odoo.models: WARNING: unable to set column product_uom_id of table mrp_subproduct not null !
Try to re-run: openerp-server –update=module
If it doesn’t work, update records and execute manually:
ALTER TABLE mrp_subproduct ALTER COLUMN product_uom_id SET NOT NULL
Traceback (most recent call last):
File “/opt/OpenUpgrade/odoo/models.py”, line 2576, in _auto_init
cr.execute(‘ALTER TABLE “%s” ALTER COLUMN “%s” SET NOT NULL’ % (self._table, name))
File “/opt/OpenUpgrade/odoo/sql_db.py”, line 154, in wrapper
return f(self, *args, **kwargs)
File “/opt/OpenUpgrade/odoo/sql_db.py”, line 231, in execute
res = self._obj.execute(query, params)
IntegrityError: column “product_uom_id” contains null values

product_uom_id 也是 Odoo 10 新增的欄位,在我們的應用下可直接用 Unit(s) 來取代

update mrp_subproduct set product_uom_id = 1 where product_uom_id is NULL

再更新資料表

ALTER TABLE "mrp_subproduct" ALTER COLUMN "product_uom_id" SET NOT NULL
無法理解的警告訊息
2018-03-02 17:23:51,937 2194 WARNING v10_migrated odoo.models: ir.ui.menu.write() with unknown fields: parent
2018-03-02 17:24:15,117 2194 WARNING v10_migrated odoo.models: res.users.write() with unknown fields: alias_name

這兩個 field 在對應的的 models 與資料庫中的 Table 都找不到,先不理會

 

升級完畢後
首次登入
1. Upgrade MOB
2. 重新設定 MOB 參數
修改 MOB Order.php
修改這
$partnerShippingId = $erpAddressArray[2];
改為
$partnerShippingId = $erpAddressArray[2];
$billing = $thisOrder->getBillingAddress();
$TAXID = $billing->getVatId();
‘date_order’=>new xmlrpcval($thisOrder->getCreatedAt(), “string”),
加上
‘tax_id’=>new xmlrpcval($TAXID,”string”),

$paymentInfo = ‘Payment Information:- ‘.$paymentMethod;
改為
$paymentInfo = ‘付款方式:’.$paymentMethod.”\n”.’Magento 單號:’.$incrementId;

$region = urlencode($flatAddress->getRegion());

加上這兩行
$zip = $flatAddress->getPostcode();
$street = $zip.” “.$city.$street;

往下幾行,註解這幾行
‘street2’=>new xmlrpcval($streetTwo, “string”),
‘city’=>new xmlrpcval($city, “string”),
‘zip’=>new xmlrpcval($flatAddress->getPostcode(), “string”),

MOB

已測試功能
1. Magento 訂單可正常同步
2. Odoo 開發票,Magento 會變付款
3. Magento 開發票,Odoo 會變付款
4. Magento 修改 SKU,Odoo 會修改
5. Odoo 運送,Magento 會交貨,is_shipped 會打勾
6. Magento 運送, Odoo 會交貨,is_shipped 會打勾
7. Odoo 更新產品數量,Magento 會改變(但須經由同步產品才行)
測試過功能,正常無誤
1. Odoo 修改 SKU,Magento 不會修改(可以考慮把 SKU 欄位作為 唯一值,或是不可修改)
2. Magento update Qty On Hand,Odoo 不會改變

統編模組

已測試功能
  1. 自動同步 Tax_id 與 note 至 Invoice
  2.  Clear 按鈕運作正常
  3. 檢查統編是否正確(SO 與 Accounting 皆正常)

MIS Report

已測試功能
  1. 報表正常顯示

CEWOLF_INV_GUI

已測試功能
  1. 【鯨躍發票】:匯出、匯入

invoice 匯入、匯出

已測試功能

1.【鯨躍發票】:匯出、匯入

貨運單匯入、匯出

已測試功能

1.【貨運資料】:匯出、匯入

 

update ir_model_data set noupdate = false where noupdate is true and id = 5401;
update ir_model_data set noupdate = false where noupdate is true and id = 5930;
update ir_model_data set noupdate = false where noupdate is true and id = 2840;
update ir_model_data set noupdate = false where noupdate is true and id = 38335;

 

ALTER TABLE mrp_production ALTER COLUMN picking_type_id SET NOT NULL
ALTER TABLE mrp_production ALTER COLUMN picking_type_id SET NOT NULL

 

 

2018-06-28 14:52:21,298 23698 INFO open_migrated odoo.addons.base.ir.ir_ui_view: Field `name` does not exist

Error context:
View `mrp.bom.tree`
[view_id: 1964, xml_id: n/a, model: mrp.bom, parent_id: n/a]
2018-06-28 14:52:21,299 23698 WARNING open_migrated odoo.modules.loading: invalid custom view(s) for model mrp.bom: Field `name` does not exist

Error context:
View `mrp.bom.tree`
[view_id: 1964, xml_id: n/a, model: mrp.bom, parent_id: n/a]
2018-06-28 14:52:21,607 23698 INFO open_migrated odoo.addons.base.ir.ir_ui_view: Field `journal_id` does not exist

Error context:
View `account.analytic.line.tree`
[view_id: 422, xml_id: n/a, model: account.analytic.line, parent_id: n/a]
2018-06-28 14:52:21,607 23698 WARNING open_migrated odoo.modules.loading: invalid custom view(s) for model account.analytic.line: Field `journal_id` does not exist

Error context:
View `account.analytic.line.tree`
[view_id: 422, xml_id: n/a, model: account.analytic.line, parent_id: n/a]

Previous 使用 Openupgrade 升級至 Odoo 10.0 – 準備篇
Next 使用 Openupgrade 升級至 Odoo 9.0 – 準備篇(Hanyu)
Table of Contents