This question has been flagged
1 Reply
1856 Views

Instead of browsing newly purchased products on the purchase order view, which is slow and require a lot of click, I would like to browse them through products view. For example, opening Sales/Products and filtering with a PO number.


How can I tweak Odoo to be able to look for a purchase order in products ?

Avatar
Discard

If i understand well your requirement, you want to have access to PO from Product.

If so, Go to product form View, you will have a smart button for Purchased quantities.

Click on the smart button and you will get graph view with line Chart diagram by default.

Swittch to Bar or Pie Chart. then click on the result.

You will be redirected to the list of related POs.

Author

Thank you for your answer. But it is not what I want to do. My question wasn't understandable.
I would like to search for all products related to a purchase. For example, opening Sales/Products and filtering with a PO number.

Best Answer

Hello Xavier Brochard,

To filter products related to a purchase order you need to add Many2many relation field of 'purchase.order' to Products and create compute method to add purchase orders to that field.

Find Example in comment.

I hope this will help you.

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Avatar
Discard

Step 1: Inherit Products model and add field as below.

purchase_order_ids = fields.Many2many(comodel_name="purchase.order", compute="_get_po_ids", store=True)

def _get_po_ids(self):
for rec in self:
rec.purchase_order_ids = self.env["purchase.order"].search([
("order_line.product_id", "=", rec.id)
]).ids

And to search based on purchase order’s relation field you need to inherit the search view of products and add the field to it.

Step 2: Inherit product’s search view.

<xpath expr='//path' position='position'>
<field name="purchase_order_ids" string="Purchase Order"/>
</xpath>

Author

Thanks a lot Jainesh Shah!