Exact Online中库存地点的库存数量

时间:2016-11-07 15:59:46

标签: exact-online invantive-sql

使用以下查询,我发现对于具有库存位置的项目,从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。当我将库存总和时,它返回在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

没有记录

我做错了什么?

1 个答案:

答案 0 :(得分: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)