Openbravo如何新建一个调用

        一. 需求

        在商品管理页面,商品编码由商品名称和种类名构成。比如,商品名为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应该就可以看到效果了。

        


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值