查找库存维度

Finding an inventory dimension

我正在尝试获取 inventDim 记录(如果存在)或创建新记录。

InventDim inventDim;

inventDim.InventLocationId = "220";
inventDim = InventDim::findOrCreate(inventDim);
info(inventDim.inventDimId);

我确信值为“220”的 InventLocationId 已经存在,但无论如何,添加了一个新的。

如果我再次运行以上几行,我会得到最后创建的值,所以这一次,一切都很好。

通过 SQL 签入:

SELECT *
FROM INVENTDIM
WHERE INVENTLOCATIONID = '220'

返回两行。

我可以使用以下行删除添加的行:

 select forUpdate inventDim 
    where inventDim.inventDimId == 'the new id';
 inventDim.delete(true);

我不知道我做错了什么..

InventDim table 包含库存维度的值。每条记录都是唯一的,因为没有记录具有完全相同的维度组合。

这意味着如果您要查找 InventLocationId == "220" 的记录,则可以有很多记录,一个 InventColorId == "Red" 和一个 InventColorId == "Blue".当你组合其他维度时,你会得到更多的组合,例如,你可以有两条记录,颜色为蓝色,位置为 220,InventSizeId 为 5 厘米或 3 厘米。

所以对于上面的示例,您只考虑了一个维度而忽略了其余维度。拥有多个 InventLocationId 设置为 220 的记录是完全可以的,因为一个或多个其他库存维度将不同。

如果您的意思是您想要一条所有其他维度都为空且 InventLocationId 为 220 的记录,您必须在尝试查找记录之前指定其他维度应该为空。

InventDim          inventDim;
InventDim          inventDimNew;
select inventDim
    where inventDim.InventLocationId == "220"
    && inventDim.ConfigId == ""
    && inventDim.InventSizeId == "";
    //Add more blank dimensions depending on the dimensions active in your system.

buf2Buf(inventDim, inventDimNew);
inventDimNew.inventDimId = '';

info(InventDim::findOrCreate(inventDimNew).inventDimId);

听起来您没有完全理解 InventDim 的工作方式,或者您的 All Blank 维度可能存在缓存问题。

解决方案是调试方法 \Data Dictionary\Tables\InventDim\Methods\findDim 以查看它如何尝试 找到 维度,然后再决定创建它。

inventDim.inventLocationId == '220'

与填充了两个字段的另一条记录不同:

inventDim.inventLocationId == '220'

inventDim.inventSiteId == '1'

我发现 AllBlank 维度存在缓存问题。还要在调试器中检查这两个方法,看看您是否发现任何异常情况。一个使用常量 AllBlank 而另一个使用全局对象缓存。

InventDim::inventDimIdBlank();

InventDim::findOrCreateBlank();

关于许可代码、配置密钥、设置、模块和您正在使用的产品组,您可能不会为两种不同的产品启用相同的维度。

例如,您可以在 T-shirts 后面加上尺码和颜色,在帽子后面加上颜色和款式。关于库存维度,您有类似的问题。

根据产品的不同,您可能不会寻找同一组尺寸。您会在 PriceDisc.findPrice()

中找到有关如何使用它的好示例

因此,在您的情况下,发明位置 220 可能已被使用,因此您可能有记录。但它似乎从未单独使用过,而是与其他维度(大小、颜色、批次、序列等)一起使用。在 运行 InventDim::findOrCreate() 方法之前,确保设置所有相关维度。