DEV Community

Jeevachaithanyan Sivanandan
Jeevachaithanyan Sivanandan

Posted on

odoo : how to get purchase order and sales order from invoice model

Hi,
If you need to get purchase order and sales order from account.move model ( invoic), you can use below link

self.line_ids[0].sale_line_ids.order_id.id
Enter fullscreen mode Exit fullscreen mode

that will gives you the sale order id and using that

self.env['sale.order'].browse(sales_order_id).get_purchase_order()
Enter fullscreen mode Exit fullscreen mode

then the method is

        if hasattr(self, 'order_line') and self.order_line:
            purchase_line_ids = getattr(self.order_line, 'purchase_line_ids', [])
            if purchase_line_ids and purchase_line_ids[0]:
                purchase_order = purchase_line_ids[0].order_id
                if purchase_order:
                    return purchase_order
        return ''
Enter fullscreen mode Exit fullscreen mode

Top comments (0)