一. 需求 在商品管理页面,商品编码由商品名称和种类名构成。比如,商品名为orange,分类名为fruit,那么商品编码自动变成orange_fruit。如何实现商品名,或者分类名变化的时候,商品编码跟着变,是本文要介绍的内容。
二. 步骤
1. 新建一个模块
点击Application dictionary->module,打开模块管理页面,点击新建。下面设置的参数是举例,你们可以自己设置成其他的或者直接按照我说的设置。表头java package: org.openbravo.lws.howtos name:lwstest type: module description: for test callout version:1.0.0。表体,dependency页签:新建一行记录dependent module选择User Interface Application。DBPrefix页签新建一条记录,录入LWS321. Data Package页签新建一条记录,name录入lwstest data package,java package录入org.openbravo.lws.howtos.data.
2. 编写后台代码
项目src目录下面新建一个类ProductConstructSearchKey,包名为:org.openbravo.lws.howtos.ad_callouts内容如下:
// the package name corresponds to the module's manual code folder
// created above
package org.openbravo.lws.howtos.ad_callouts;
import javax.servlet.ServletException;
import org.openbravo.base.secureApp.VariablesSecureApp;
import org.openbravo.dal.service.OBDal;
import org.openbravo.erpCommon.ad_callouts.SimpleCallout;
import org.openbravo.model.common.plm.ProductCategory;
import org.openbravo.utils.FormatUtilities;
public class ProductConstructSearchKey extends SimpleCallout {
private static final long serialVersionUID = 1L;
@Override
protected void execute(CalloutInfo info) throws ServletException {
String strProductName = info.getStringParameter("inpname", null);
String strProductCategoryId = info.getStringParameter(
"inpmProductCategoryId", null);
info.addResult("inpvalue", getConstructedKey(info.vars, strProductName,
strProductCategoryId));
}
protected String getConstructedKey(VariablesSecureApp vars,
String strProductName, String strProductCategoryId) {
final ProductCategory productCategory = OBDal.getInstance().get(
ProductCategory.class, strProductCategoryId);
String strProductCategoryName = productCategory.getName();
String generatedSearchKey = FormatUtilities.replaceJS(strProductName
.replaceAll(" ", ""))
+ "_" + strProductCategoryName.replaceAll(" ", "");
return generatedSearchKey;
}
}
3. 将调用注册到数据字典
点击 Application Dictionary || Setup || Callout 新建一条记录,module选择我们刚刚新建的module,name填写product_Construct_Searchkey,表体java class name填写刚刚新建的那个类org.openbravo.lws.howtos.ad_callouts.ProductConstructSearchKey。
4. 将调用跟数据库列对应起来
点击 Application Dictionary || Tables and Columns ,找到m_product表,切到表体column页签找到name列和Product Category列。将里面的Callout字段值设置为刚刚新建的callout:product_construct_searchkey。
5. 导出数据与编译
运行项目openbravo目录下面的export.database.launch文件,也就是运行ant export.database命令。
然后运行eclipse.compile.launch文件,弹出框输入需要重新编译的窗口也就是Product。重启tomcat应该就可以看到效果了。