DEV Community

Jeevachaithanyan Sivanandan
Jeevachaithanyan Sivanandan

Posted on

1

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)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay