--[[
|
编码: WMS-19-01
|
名称: 容器货品明细-创建前
|
作者:HAN
|
日期:2025-1-29
|
|
级别:固定 (说明本段代码在项目中不太会变化)
|
|
函数: BeforeDataObjCreate
|
|
功能:
|
1)创建一个【容器货品明细】需要到【容器货品】表找一下这个物料是否存在,有存在合并数量,
|
不存在就要创建一个【容器货品】,并且把【容器货品】的ID作为 S_CG_ID 设置到【容器货品明细】
|
更改记录:
|
|
--]]
|
|
wms_base = require( "wms_base" )
|
|
function BeforeDataObjCreate ( strLuaDEID )
|
local nRet, strRetInfo
|
|
-- step1: 获取当前【容器货品明细】的关键信息
|
nRet, strRetInfo = mobox.getCurEditDataObjAttr( strLuaDEID, "S_CNTR_CODE","S_ITEM_CODE","N_ITEM_STATE","S_END_USER","F_QTY",
|
"S_ITEM_NAME","S_ITEM_SPEC","S_UOM","C_ITEM_MERGE")
|
if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前编辑属性失败! "..strRetInfo ) end
|
local obj_attrs = json.decode( strRetInfo )
|
local cntr_code = obj_attrs[1].value
|
local item_code = obj_attrs[2].value
|
local item_state = lua.StrToNumber(obj_attrs[3].value)
|
local end_user = obj_attrs[4].value
|
local qty = lua.StrToNumber(obj_attrs[5].value)
|
local item_name = obj_attrs[6].value
|
local item_spec = obj_attrs[7].value
|
local uom = obj_attrs[8].value
|
local merge = obj_attrs[9].value
|
local cg_id = ''
|
|
if ( merge == 'Y') then
|
-- step2: 获取当前【容器货品】记录
|
local strCondition
|
strCondition = "S_CNTR_CODE='"..cntr_code.."' AND S_ITEM_CODE='"..item_code.."'"
|
nRet, strRetInfo = mobox.queryOneDataObjAttr(strLuaDEID, "Container_Good", strCondition, "S_ITEM_CODE" )
|
if (nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "获取【容器货品】信息失败! " .. strRetInfo ) end
|
if ( strRetInfo == '') then
|
-- 如果不存在【容器货品】就新建一个
|
local cntr_good = m3.AllocObject(strLuaDEID,"Container_Good")
|
local ret_info
|
|
cntr_good.cntr_no = cntr_code
|
cntr_good.item_code = item_code
|
cntr_good.item_name = item_name
|
cntr_good.item_spec = item_spec
|
cntr_good.uom = uom
|
cntr_good.qty = qty
|
|
nRet, ret_info = m3.CreateDataObj(strLuaDEID, cntr_good)
|
if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), 'mobox 创建【容器货品】对象失败!'..ret_info ) end
|
-- 获取创建成功的【容器货品】对象标识
|
cg_id = ret_info.id
|
else
|
local strSetAttr = ''
|
local ret_info = json.decode(strRetInfo)
|
cg_id = ret_info.id
|
-- 需要累计数量
|
strCondition = "S_ID = '"..cg_id.."'"
|
strSetAttr = "F_QTY = F_QTY + "..qty
|
nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Container_Good", strCondition, strSetAttr )
|
if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "更新【容器货品】数量失败!"..strRetInfo ) end
|
end
|
end
|
|
-- 根据字典获取 N_LOCK_STATE 的货品状态
|
local item_state_name = wms_base.GetDictItemName( strLuaDEID, "WMS_ItemState", item_state )
|
|
local attr_value = {}
|
attr_value[1] = lua.KeyValueObj( "S_CG_ID", cg_id )
|
attr_value[2] = lua.KeyValueObj( "S_ITEM_STATE", item_state_name )
|
nRet, strRetInfo = mobox.setCurEditDataObjAttr( strLuaDEID, lua.table2str(attr_value) )
|
if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "设置【容器货品明细】信息失败! "..strRetInfo ) end
|
end
|