0

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

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 字段求和时,它会返回 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

我究竟做错了什么?

4

1 回答 1

0

与工程师讨论了关于 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).

于 2016-11-18T15:57:28.370 回答