콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다

Hi,

Im trying to create webkit report for stock.picking (eg. Picking Slip) and I cannot access customer nor product for this picking list. I know picking has sale_id and purchase_order_id and even product_id but these values are empty. How to access sale.order from low level stock.picking?

Thank you,

Marek

아바타
취소
베스트 답변

If the stock.picking (in this case it should be Delivery Order) is created from Sale Order, then the sale_id field should be populated.

Another path that you might want to check is going through the relationship between stock.move (which has picking_id of the parent stock.picking) which is related to sale.order.line from stock.move's sale_line_id. sale.order.line is related to sale.order through it's order_id.

The relationship from stock.move is more beneficial if you are searching stock.pickings for a sale.order (the reverse of what you need) due to partial shipments, splitting of DO, returns, etc.

아바타
취소
베스트 답변

Here is the code to access the stock move from sale order line on Odoo 8:

class xx_sale_order_line(models.Model):

_inherit = 'sale.order.line'

@api.multi

def get_stock_moves(self, stock_picking_type_codes=['outgoing', 'internal'], values=None):

stock_picking_types = self.env['stock.picking.type'].search( [('code','in',stock_picking_type_codes)])

procurement_orders = self.env['procurement.order'].search([('sale_line_id','=',self.id)])

stock_moves = self.env['stock.move'].search([('procurement_id','in',[procurement_order.id for procurement_order in procurement_orders]),

('picking_type_id','in',[stock_picking_type.id for stock_picking_type in stock_picking_types])

])

return stock_moves        

아바타
취소
베스트 답변

Hello Ivan,

Thank you for your reply.

Unfortunately, in Odoo V9, there is no more reference of sale_xxx in stock_picking or stock_move tables ...

So you can't link sale and stock.

I want to do that, because I would like to get discount (from sale_order_line) to print it on delivery order (from stock.picking).


Edit 25/04/2016

Thank you Ahmed Ababneh, with your answer I built a SQL request :


SELECT e.NAME

FROM stock_picking a

,stock_move b

,procurement_order c

,sale_order_line d

,sale_order e

WHERE a.id = b.picking_id

AND b.procurement_id = c.id

AND c.sale_line_id = d.id

AND d.order_id = e.id



Regards,

FTK

아바타
취소

Some inner joins and more relevant aliases would look much better!

SELECT so.NAME

FROM stock_picking sp

INNER JOIN stock_move sm

ON sp.id = sm.picking_id

INNER JOIN procurement_order po

ON sm.procurement_id = po.id

INNER JOIN sale_order_line sol

ON po.sale_line_id = sol.id

INNER JOIN sale_order so

ON sol.order_id = so.id

Apparently this forum doesn't like the leading spaces!

관련 게시물 답글 화면 활동
1
4월 25
1763
0
5월 23
3370
2
3월 22
2881
3
3월 18
5008
1
1월 25
7425