Jianw
2025-05-13 3b39fe3810c3ee2ec9ec97236c1769c5c85e062c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
--[[
    编码: WMS-15-08
    名称: 收货单-定版后
    作者:HAN  
    日期:2025-1-29
 
    级别:项目 (说明本段代码在项目中需要变化)
    
    函数: AfterStateChange
 
    功能:
        - 判断物料是否要检验? 如果需要生成检验单,如果不需要检验生成上架单
        - 根据货品的去向增加检验区、上架区的量表
        - 是否检验可以根据来源类型,货品类型等来设置,就目前新兴项目来说入成品库都不需要检验(因此这块代码暂时空缺),可以从纳特项目中来实践
        - 设置【收货单明细】的状态为定版
    更改记录:
 
--]]
wms_in = require( "wms_inbound" )
 
function AfterStateChange ( strLuaDEID )
    local  nRet, strRetInfo
    local  inspection_area = ''   -- 检验区
    local  putaway_area = ''      -- 上架区
 
    -- 获取收货单相关信息
    nRet, strRetInfo = mobox.getCurEditDataObjAttr( strLuaDEID ) 
    if ( nRet ~= 0 )  then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前编辑属性失败! "..strRetInfo ) end 
    -- 根据获取的属性生成收货单对象
    nRet, strRetInfo = mobox.objAttrsToLuaJson( "Receipt_Order", strRetInfo )
    if ( nRet ~= 0 or strRetInfo == '' ) then lua.Error( strLuaDEID, debug.getinfo(1), "objAttrsToLuaJson失败! "..strRetInfo ) end 
    local receipt_obj = json.decode( strRetInfo ) 
    if ( receipt_obj == nil ) then lua.Error( strLuaDEID, debug.getinfo(1), "objAttrsToLuaJson失败! " ) end 
 
    -- step1 判断收货单里是否有设置检验
    if ( receipt_obj.inspection == 'Y' ) then
        wms_in.CreateInspectionOrder( strLuaDEID, receipt_obj, inspection_area )
    elseif ( receipt_obj.inspection == 'N' ) then 
        WMS_CreatePutawayOrder( strLuaDEID, receipt_obj, putaway_area )
    else
        -- 通过供应商来判断
        if ( receipt_obj.supplier_no == '' ) then lua.Error( strLuaDEID, debug.getinfo(1), "收货单中的供应商编码不能为空! " ) end 
        -- 获取供应商对象
        nRet, supplier_obj = m3.GetDataObjectByKey( strLuaDEID, "Supplier", "S_NO", receipt_obj.supplier_no )
        if ( nRet == 0 ) then
            -- 是否免检
            if ( supplier_obj.uninspected == 'Y' ) then
                WMS_CreatePutawayOrder( strLuaDEID, receipt_obj, putaway_area )
            elseif (supplier_obj.uninspected == 'N') then
                wms_in.CreateInspectionOrder( strLuaDEID, receipt_obj, inspection_area )
            else
                WMS_CreatePutawayOrder( strLuaDEID, receipt_obj, putaway_area )
            end
        else
            WMS_CreatePutawayOrder( strLuaDEID, receipt_obj, putaway_area )
        end
    end
 
    if ( receipt_obj.no == '') then
        lua.Warning( strLuaDEID, debug.getinfo(1), "收货单编号为空! " )
        return
    end
    if ( receipt_obj.state == nil or  receipt_obj.state == '') then
        lua.Warning( strLuaDEID, debug.getinfo(1), "收货单状态为空或nil, 检查一下是否有定义名为 state 的 Lua 属性! " )
        return
    end
 
 
    -- 清除 asn_no 的最大行号记录 ()
    nRet, strRetInfo = mobox.removeSerialNumber( "行号", receipt_obj.no )
    if ( nRet ~= 0 )  then lua.Error( strLuaDEID, debug.getinfo(1), "removeSerialNumber() 失败! "..strRetInfo ) end 
 
    lua.Debug( strLuaDEID, debug.getinfo(1), "receipt_obj.state", receipt_obj.state )
    
    -- 设置【收货单明细】的状态=定版
    local strCondition = "S_RECEIPT_NO = '"..receipt_obj.no.."'"
    nRet, strRetInfo = mobox.setDataObjStateByCondition( strLuaDEID, "Receipt_Detail", strCondition, receipt_obj.state )
    if ( nRet ~= 0 )  then lua.Error( strLuaDEID, debug.getinfo(1), "setDataObjStateByCondition() 失败! "..strRetInfo ) end 
end