Exact Online 库存位置的库存数量

Quantity in stock in stock locations in Exact Online

使用以下查询,我发现对于具有库存位置的商品,从 REST API StockLocations of Exact Online 返回多行:

select spn.item_code_attr || '-' || spn.warehouse_code_attr || '-' || stn.code key 
,      itm.itemgroupcode
,      itm.itemgroupdescription
,      spn.item_code_attr
,      spn.item_description
,      spn.currentquantity
,      spn.planning_in
,      spn.planning_out
,      spn.currentquantity + spn.planning_in - spn.planning_out plannedquantity
,      -1 bestelniveau /* out of scope */
,      itm.costpricestandard costprijs
,      itm.costpricestandard * spn.currentquantity stockvalue
,      spn.warehouse_code_attr
,      stn.code locatie
,      itm.unitcode UOM
, itm.id
, whe.id
, sln.stock
, sln.itemid
, sln.warehouse
, stn.id
from   exactonlinexml..StockPositions spn
join   exactonlinerest..items itm
on     itm.code = spn.item_code_attr
and    itm.code = 'LE-10242'
and    itm.isstockitem = 1
join   exactonlinerest..warehouses whe
on     whe.code = spn.warehouse_code_attr
left 
outer
join   exactonlinerest..stocklocations sln
on     sln.itemid = itm.id
and    sln.stock != 0
and    sln.warehouse = whe.id
left
outer
join   storagelocations stn
on     stn.id        = sln.storagelocation
and    stn.warehouse = sln.warehouse
--
-- Filter out no stock nor planned.
--
where  ( spn.currentquantity !=0
         or     
         spn.planning_in != 0
         or     
         spn.planning_out != 0
       )
and    spn.item_code_attr = 'LE-10242'
order 
by     key

例如,对于此商品,有 10 个 StockLocations。当我对 Stock 字段求和时,它 returns 是在 StockPositions 中找到的库存数量。但是,似乎每笔交易都会创建一个额外的 StockLocation 条目。

我希望 StockLocation 包含库存中每个位置的总数量。

编辑

StockLocations API 在 https://start.exactonline.nl/api/v1/{division}/logistics/$metadata 中描述为:

<EntityType Name="StockLocation">
  <Key>
    <PropertyRef Name="ItemID"/>
  </Key>
  <Property Name="ItemID" Type="Edm.Guid" Nullable="false"/>
  <Property Name="Warehouse" Type="Edm.Guid" Nullable="true"/>
  <Property Name="WarehouseCode" Type="Edm.String" Nullable="true"/>
  <Property Name="WarehouseDescription" Type="Edm.String" Nullable="true"/>
  <Property Name="Stock" Type="Edm.Double" Nullable="true"/>
  <Property Name="StorageLocation" Type="Edm.Guid" Nullable="true"/>
  <Property Name="StorageLocationCode" Type="Edm.String" Nullable="true"/>
  <Property Name="StorageLocationDescription" Type="Edm.String" Nullable="true"/>
</EntityType>

不知何故 https://start.exactonline.nl/docs/HlpRestAPIResources.aspx

中没有记录

我做错了什么?

与工程师讨论了关于 Hackathon 的问题。这是 StockLocation API 的工作原理;命名并未最佳地反映内容,但这是预期的行为。

有了select field, sum(stock) from stocklocations group by field,您就可以获得正确的信息。

为了提高连接性能,建议为此使用内联视图,例如select ... from table1 join table2 ... join ( select field, sum(stock) from stocklocations group by field)