I’m not sure why the file attachment didn’t work last time, so I’ll try it again
EDIT:
And failed again.
Let’s see if we can do it inline:
/*
* Script: searchForItem
* Notes: Add extra column(s)
* Order: 0
* Version: 3.3.x
*
* Copyright(c) 2009 petebisson - xtuple[at]bisson.co.uk
*
* This file is a script adding extra functionality to
* xTuple ERP: PostBooks Edition, a free and open source
* Enterprise Resource Planning software suite,
* Copyright (c) 1999-2009 by OpenMFG LLC, d/b/a xTuple.
*
* It is licensed to you under the Common Public Attribution License
* version 1.0, the full text of which (including xTuple-specific Exhibits)
* is available at www.xtuple.com/CPAL. By using this software, you agree
* to be bound by its terms.
*/
function newFillList()
{
try {
var qry = toolbox.executeQuery(mql, setParams());
toolbox.populateXTreeWidget(_item, qry, false);
}
catch (e)
{
toolbox.messageBox("critical", mywindow, mywindow.windowTitle, e.lineNumber + ": " + e);
}
}
function setParams()
{
var params = new Object;
params.purchased = qsTr("Purchased");
params.manufactured = qsTr("Manufactured");
params.phantom = qsTr("Phantom");
params.breeder = qsTr("Breeder");
params.coProduct = qsTr("Co-Product");
params.byProduct = qsTr("By-Product");
params.reference = qsTr("Reference");
params.costing = qsTr("Costing");
params.tooling = qsTr("Tooling");
params.outside = qsTr("Outside Process");
params.assortment = qsTr("Assortment");
params.job = qsTr("Job");
params.planning = qsTr("Planning");
params.kit = qsTr("Kit");
params.error = qsTr("Error");
params.useNumber = _searchNumber.checked;
params.useDescrip1 = _searchDescrip1.checked;
params.useDescrip2 = _searchDescrip2.checked;
params.searchString = _search.text.toUpperCase();
if(_showInactive.checked)
{
params.showInactive = true;
}
return params;
}
var _item = mywindow.findChild("_item");
var _search = mywindow.findChild("_search");
var _searchDescrip1 = mywindow.findChild("_searchDescrip1");
var _searchDescrip2 = mywindow.findChild("_searchDescrip2");
var _searchNumber = mywindow.findChild("_searchNumber");
var _showInactive = mywindow.findChild("_showInactive");
var mql = " SELECT item_id,"
+ " item_number, (item_descrip1 || ' ' || item_descrip2) AS description,"
+ " CASE WHEN (item_type='P') THEN <? value(\"purchased\") ?>"
+ " WHEN (item_type='M') THEN <? value(\"manufactured\") ?>"
+ " WHEN (item_type='F') THEN <? value(\"phantom\") ?>"
+ " WHEN (item_type='B') THEN <? value(\"breeder\") ?>"
+ " WHEN (item_type='C') THEN <? value(\"coProduct\") ?>"
+ " WHEN (item_type='Y') THEN <? value(\"byProduct\") ?>"
+ " WHEN (item_type='R') THEN <? value(\"reference\") ?>"
+ " WHEN (item_type='S') THEN <? value(\"costing\") ?>"
+ " WHEN (item_type='T') THEN <? value(\"tooling\") ?>"
+ " WHEN (item_type='A') THEN <? value(\"assortment\") ?>"
+ " WHEN (item_type='O') THEN <? value(\"outside\") ?>"
+ " WHEN (item_type='J') THEN <? value(\"job\") ?>"
+ " WHEN (item_type='L') THEN <? value(\"planning\") ?>"
+ " WHEN (item_type='K') THEN <? value(\"kit\") ?>"
+ " ELSE <? value(\"error\") ?>"
+ " END AS type, "
+ " location_name "
+ " FROM item "
+ " LEFT OUTER JOIN itemsite ON item.item_id = itemsite.itemsite_item_id"
+ " LEFT OUTER JOIN location ON itemsite.itemsite_location_id = location.location_id"
+ " WHERE ( ( ((<? value(\"useNumber\") ?>) AND (item_number ~* <? value(\"searchString\") ?>))"
+ " OR ((<? value(\"useDescrip1\") ?>) AND (item_descrip1 ~* <? value(\"searchString\") ?>))"
+ " OR ((<? value(\"useDescrip2\") ?>) AND (item_descrip2 ~* <? value(\"searchString\") ?>)) )"
+ " <? if not exists(\"showInactive\") ?> "
+ " AND (item_active) "
+ " <?endif ?>"
+ " ) "
+ " ORDER BY item_number;";
// Add the new column(s) to the XTreeWidget
// All the original columns are set by xTuple core code so we can ignore them.
toolbox.addColumnXTreeWidget(_item, qsTr("Location"), -1, Qt.AlignLeft, true, "location_name");
// Disconnect handlers from the original code or the old
// query runs and the new column(s) do not get re-populated.
toolbox.coreDisconnect(_showInactive, "clicked()", mywindow, "sFillList()");
toolbox.coreDisconnect(_searchNumber, "toggled(bool)", mywindow, "sFillList()");
toolbox.coreDisconnect(_searchDescrip1, "toggled(bool)", mywindow, "sFillList()");
toolbox.coreDisconnect(_searchDescrip2, "toggled(bool)", mywindow, "sFillList()");
toolbox.coreDisconnect(_search, "lostFocus()", mywindow, "sFillList()");
toolbox.coreDisconnect(mainwindow, "itemsUpdated(int, bool)", mywindow, "sFillList()");
// ... and connect the new handlers.
_showInactive.clicked.connect(newFillList);
_searchNumber.toggled.connect(newFillList);
_searchDescrip1.toggled.connect(newFillList);
_searchDescrip2.toggled.connect(newFillList);
_search.lostFocus.connect(newFillList);
mainwindow.itemsUpdated.connect(newFillList);
// Run newFillList() once on load.
newFillList();