2016-10-24 2 views
4

odoo에서 재고 수량을 구해야합니다.제품 수량 (Odoo v8 및 v9)을 얻는 방법

여러 가지 모델이 있습니다. stock_quant, stock_move, stock_location.

  1. 제품은 위치

에 사람이 나를 인도시겠습니까 기반

  • 제품을 사용할 수있는 주문 가능 수량 총 :

    나는 두 가지를 달성하기 위해 노력하고 무엇입니까?

  • 답변

    2

    재고 관련 필드는 제품 (기능 필드)에 정의되어 있으며 제품에서 직접 모든 창고/위치 또는 개별 위치/창고에 대한 재고를 얻을 수 있습니다.

    예 : 모든웨어 하우스

    /위치 개별 위치는

    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 
    
    +0

    하지만 오류를주고있다. –

    +0

    '@ api.onchange ('product_id ','source_location ') def product_qty_location_check (self) : if self.product_id 및 self.source_location : product = self.env ['product.product ']. product_id.id) available_qty = product.with_context (창고 = self.source_location.id) .qty_available 인쇄 available_qty ' 오류가 가 ** MissingError 액세스하려는 문서 중 하나가 삭제 된 , 시도하십시오됩니다 다시 시원하게. ** –

    +0

    ** 고마워. ** 사전을 보냈어야 했어. –

    -2

    :

    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 
    
    내가 코드 조각 다음 작성한
    관련 문제