odoo在庫から入手可能な数量を取得する必要があります。入手可能な数量を取得する方法(Odoo v8およびv9)
私はstock_quant、stock_move、stock_locationのいくつかのモデルがあります。
- 製品は場所
上の誰もが私を導いてくださいすることができをベース
私は二つのことを達成しようとしていますか?
odoo在庫から入手可能な数量を取得する必要があります。入手可能な数量を取得する方法(Odoo v8およびv9)
私はstock_quant、stock_move、stock_locationのいくつかのモデルがあります。
上の誰もが私を導いてくださいすることができをベース
私は二つのことを達成しようとしていますか?
在庫関連項目は製品(機能分野)で定義され、製品から直接すべての倉庫/倉庫または個々の場所/倉庫の在庫を取得できます。
例:すべての倉庫のため
/場所個々の位置について
product = self.env['product.product'].browse(PRODUCT_ID)
available_qty = product.qty_available
/倉庫
product = self.env['product.product'].browse(PRODUCT_ID)
available_qty = product.with_context({'warehouse' : WAREHOUSE_ID}).qty_available
available_qty = product.with_context({'location' : LOCATION_ID}).qty_available
(WAREHOUSE_ID/LOCATION_IDは実際のIDに置き換えてください)
他のフィールドもあります。
Forecasted Stock => virtual_available
Incoming Stock => incoming
Outgoing Stock => outgoing
同様の方法ですべてのフィールドにアクセスできます。コンテキスト内で倉庫/場所を渡さない場合は、すべての倉庫の在庫が一緒に返されます。
詳細については、モジュールのproduct.pyを参照してください。
ソリューション:Odoo 8,9及び10については
@api.onchange('product_id','source_location')
def product_qty_location_check(self):
if self.product_id and self.source_location:
product = self.product_id
available_qty = product.with_context({'location' : self.source_location.id}).qty_available
print available_qty
:
with
uitstock as (
select
t.name product, sum(product_qty) sumout, m.product_id, m.product_uom
from stock_move m
left join product_product p on m.product_id = p.id
left join product_template t on p.product_tmpl_id = t.id
where
m.state like 'done'
and m.location_id in (select id from stock_location where complete_name like '%Stock%')
and m.location_dest_id not in (select id from stock_location where complete_name like '%Stock%')
group by product_id,product_uom, t.name order by t.name asc
),
instock as (
select
t.list_price purchaseprice, t.name product, sum(product_qty) sumin, m.product_id, m.product_uom
from stock_move m
left join product_product p on m.product_id = p.id
left join product_template t on p.product_tmpl_id = t.id
where
m.state like 'done' and m.location_id not in (select id from stock_location where complete_name like '%Stock%')
and m.location_dest_id in (select id from stock_location where complete_name like '%Stock%')
group by product_id,product_uom, t.name, t.list_price order by t.name asc
)
select
i.product, sumin-coalesce(sumout,0) AS stock, sumin, sumout, purchaseprice, ((sumin-coalesce(sumout,0)) * purchaseprice) as stockvalue
from uitstock u
full outer join instock i on u.product = i.product
私は、コードの一部を以下のが、それはエラーを与えている書かれています。 –
'@ api.onchange(' product_id '、' source_location ') def product_qty_location_check(self): if self.product_idおよびself.source_location: product = self.env [' product.product ']。browse(self。 product_id.id) available_qty = product.with_context(倉庫= self.source_location.id).qty_available 印刷available_qty」 エラーが あるMissingError あなたがアクセスしようとしているドキュメントの1つが削除されている**、試してみてください** –
**ありがとうございます。**私は辞書を送ったはずです。 –