基于xTuple框架的擴展是在盡可能不修改xTuple核心代碼的前提下進行ui和腳本開發的。
以下為開發步驟,將在以后空閑時間里逐步進行細節描述。
一、需求分析
略。
二、數據庫設計
序列
對自動增加的唯一編號可以通過序列來實現,這樣可以通過postgresql提供的nextval獲取
CREATE SEQUENCE house.payrecord_id_seq
INCREMENT 1
MINVALUE 1
MAXVALUE 2147483647
START 13
CACHE 1;
ALTER TABLE house.payrecord_id_seq OWNER TO postgres;
三、ui設計
xTuple custom widget 之 xcombobox
對于xcombobox控件,可以增加其他我們需要的類型
1 在xcombobox.h里的XComboBoxTypes枚舉里增加我們要加的類型(如HousePayWays)
2 在xcombobox.cpp里的XComboBox::init函數里增加代碼:
insertEditor(HousePayWays, "housepayways", "MaintainPayWay");
第二個參數為ui名稱:在xcombobox控件下拉里點擊編輯的時候要連接到的ui;
第三個參數為權限名稱:需要在數據庫的數據表priv里存在,可以通過升級包增加此權限,也可以直接在數據庫里增加
3 在xcombobox.cpp里的XComboBox::setType函數里增加switch分支:
case HousePayWays:
query.exec("select payway_id, (payway_name || '-' || payway_description), payway_name "
"from house.payway "
"order by payway_name");
break;
用來獲取數據庫信息數據。
4 編譯xTuple,(不需要重新編譯)。
5 重新打開Qt Designer,即可在xTuple Custom Controls里的xcombobox控件里找到我們之前加好的枚舉類型。
xTuple custom widget 之cluster控件
cluster控件是用戶自己定義的可以實現輸入下拉的一個控件,可以在一個輸入框后面出現搜素標志,并可以進行列表查找、增加等連接操作。
1 創建一個.h和一個.cpp文件,根據需要自行決定是否創建ui文件(如housecluster.h, housecluster.cpp)。里面的代碼請自己增加,如有需要可參考已存在的itemcluster控件代碼。
2 創建一個houseclusterplugin.h頭文件。(請注意命名:以housecluster+plugin),并填充代碼。
3 在widgets.pro里增加這3個文件。(請手動添加,如果自動添加,有可能出現將代碼添加到dll.pro中。)
4 修改widgets.cpp里增加頭文件引用#include "plugins/houseclusterplugin.h",并在構造函數里增加代碼:
m_plugins.append(new HouseClusterPlugin(this));
5 編譯xTuple。(不需要全部重新編譯)
6 重新打開Qt Designer,即可使用此新加的控件。
四、腳本開發
display設計
display頁面在3.8以上的版本中可以完全用腳本實現,以下描述僅限3.8以上的版本
1 創建housepays-detail.mql,用來取出數據庫的數據和dispay里的filter、查詢等功能:
-- Group: housepays
-- Name: detail
-- Notes:
select house.payrecord.*, house.item.item_number, house.custinfo.cust_name
from house.payrecord, house.item, house.custinfo
where house.payrecord.item_id = house.item.item_id
and house.payrecord.cust_id = house.custinfo.cust_id
-- This clause handles filtering if the user wants to search the list
-- The ~* uses PostgreSQL built in support for Regular Expressions
<? if exists("search_pattern") ?>
AND house.item.item_number || house.custinfo.cust_name || house.payrecord.pay_price ~* <? value("search_pattern") ?>
<? endif ?>
2 在連接到此頁面的腳本里增加連接代碼(initMenu.js):
houseExtension.housepaylistDisplay = function()
{
toolbox.newDisplay("housepays");
}
3 xTuple客戶端設計里加載腳本initMenu.js和housepays-detail.mql。
4 重啟xTuple客戶端。運行即可。
參考資料:www.xtuple.org/node/4596
菜單設計
簡單示例:
var productsMenu = mainwindow.findChild("menu.prod");
housecustomerMenu = toolbox.menuAddMenu(productsMenu, qsTr("Customer"));
newhousecustomerAction = toolbox.menuAddAction(housecustomerMenu, qsTr("New Customer"));
newhousecustomerAction.triggered.connect(houseExtension.newhousecustomer);
housecustomersAction = toolbox.menuAddAction(housecustomerMenu, qsTr("Customer List"));
housecustomersAction.triggered.connect(houseExtension.housecustomersDisplay);
var tmpMenu = mainwindow.findChild("menu.prod.reports");
toolbox.menuRemove(productsMenu, tmpMenu);
tmpMenu = mainwindow.findChild("menu.prod.items");
toolbox.menuRemove(productsMenu, tmpMenu);
請注意menuAddMenu和menuAddAction方法的使用。
參考資料:http://www.xtuple.org/node/337
五、其他
腳本語言翻譯
1 創建test.pro工程文件
2 加入.ui,.h,.cpp文件;加入.js文件
3 降.js文件的類型改為SCOURCES
4 增加TRANSLATIONS = test_zh.ts
5 執行lupdate test.pro,生成test_zh.ts文件
6 用Qt Linguist對ts文件進行翻譯操作
7 翻譯結束后執行Qt Linguist的發布操作
8 與原來的xTuple.zh_CN.qm整合:執行lrelease test_zh.qm xTuple.zh_CN.qm -qm xTuple.zh_CN.qm
9 成功。將新的qm文件放入執行目錄即可。
六、更新包創建與發布
升級包package.xml示例:
<package id = "house"
name = "housepackage"
version = "1.0alpha"
developer = "seahouse"
descrip = "house rent system"
updater = "2.2.4">
<pkgnotes>
This package creates a house rent system though scripting.
</pkgnotes>
<prerequisite type = "license" name = "houseLicense">
<message>
<This file is created by seahouse. Copyright @seahouse. seahouse QQ: 260822310, seahouse email:
seahouse21@gmail.com.
</message>
</prerequisite>
<loadappui file = "uiforms/house.ui" />
<loadappui file = "uiforms/houseClass.ui.ui" />
<loadappui file = "uiforms/houseClasses.ui" />
<loadappui file = "uiforms/housecustomer.ui" />
<loadappui file = "uiforms/housepay.ui" />
<loadappui file = "uiforms/housepayway.ui" />
<loadappui file = "uiforms/housepayways.ui" />
<loadappui file = "uiforms/houserent.ui" />
<loadappscript file = "scripts/house.js" />
<loadappscript file = "scripts/houseClass.js" />
<loadappscript file = "scripts/houseClasses.js" />
<loadappscript file = "scripts/housecustomer.js" />
<loadappscript file = "scripts/housecustomers.js" />
<loadappscript file = "scripts/houseitems.js" />
<loadappscript file = "scripts/housepay.js" />
<loadappscript file = "scripts/housepays.js" />
<loadappscript file = "scripts/housepayway.js" />
<loadappscript file = "scripts/housepayways.js" />
<loadappscript file = "scripts/houserent.js" />
<loadappscript file = "scripts/houserents.js" />
<loadappscript file = "scripts/initMenu.js" />
<loadappscript file = "scripts/user.js" />
<loadmetasql file = "metasql/houseitems-detail.mql" />
<loadmetasql file = "metasql/housepays-detail.mql" />
<loadmetasql file = "metasql/houserents-detail.mql" />
<loadpriv name = "MaintainHouseClasses" module = "Products">
Allawed to maintain house classes.
</loadpriv>
<loadpriv name = "MaintainHouseItem" module = "Products">
Allawed to maintain house item.
</loadpriv>
<loadpriv name = "MaintainPayWay" module = "Products">
Allawed to maintain house payway.
</loadpriv>
</package>
其他數據庫操作(在package節點下):
<loadreport file="client/reports/DisplayItemLocations.xml" >sample_scripts package</loadreport>
<createfunction file="database/functions/cashregadjust.sql" name="cashregadjust" />
<createtable file="database/tables/createTerminal.sql" name="terminal" />
<finalscript file="database/tables/createSalenumberseq.sql" />
<createtrigger file="database/triggers/rtlsitestatuscheck.sql" name="rtlsitestatuscheck" />
<createview file="database/views/api_cashregister.sql" name="api_cashregister" />
參考:http://www.xtuple.org/CreateUpdaterPackages