Skip to Content
Menu
This question has been flagged

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

Avatar
Discard
Best Answer

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.

Avatar
Discard
Best Answer

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        

Avatar
Discard
Best Answer

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

Avatar
Discard

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!

Related Posts Replies Views Activity
0
May 23
1759
2
Mar 22
1675
3
Mar 18
3616
3
Sep 20
7253
1
Feb 16
5663