Hi,
Please refer to the code:
from odoo import api, fields, models
class PurchaseOrderLine(models.Model):
_inherit = "purchase.order.line"
product_ids = fields.Many2many(
'product.product',
string="Allowed Products",
compute="_compute_product_ids",
store=False,
)
product_id = fields.Many2one(
'product.product',
string="Product",
domain="[('id', 'in', product_ids)]",
)
@api.depends('order_id.partner_id')
def _compute_product_ids(self):
for line in self:
if line.order_id.partner_id:
products = self.env['product.product'].search([
('purchase_ok', '=', True),
('seller_ids.partner_id', '=', line.order_id.partner_id.id)
])
line.product_ids = products
else:
line.product_ids = False
Hope it helps.
With this change you can no longer order generic products such as office supplies, janitorial supplies, warehouse packaging supplies, consumable computer supplies, etc.
Most of the time, this change is requested because there is a perception people will order the wrong things from the wrong Vendor but in reality it rarely happens.
The Vendor will tell you straight away "we don't sell that".