Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to access sale.order from stock.picking

By
Marek Toman
on 12/4/14, 3:43 PM 2,594 views

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

1

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
On 12/4/14, 8:25 PM

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.

I think this answer is related to odoo7 only. TKF confirmed this does not work on odoo9, and I can confirm that sale_line_id no longer exists in odoo8

Cats&Dogs bvba, SonnyV
on 1/14/16, 3:56 AM
1
Ahmed Ababneh
On 3/8/16, 3:47 AM

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        

0
TK Fontaine
On 11/30/15, 7:22 AM

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

Mathieu Laflamme
on 8/9/16, 11:22 AM

Apparently this forum doesn't like the leading spaces!

Mathieu Laflamme
on 8/9/16, 11:23 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 12/4/14, 3:43 PM
Seen: 2594 times
Last updated: 3/8/16, 3:47 AM