Hi,
Odoo does not include out-of-the-box functionality for restricting products to specific customers. The standard product setup only allows assigning suppliers to products not customers.So,
you need to develop a custom module that adds the overrides for this.
Try the following method.
1- Add a Many2many field on sale.order to hold allowed products.
2-Compute or update that field when partner_id is selected
3-Add a domain on product_id in sale.order.line based on order_id.allowed_products
Explanation.
1. Extend sale.order to Add Allowed Products Field.
from odoo import models, fields, api
class SaleOrder(models.Model):
_inherit = 'sale.order'
allowed_products = fields.Many2many(
'product.product',
string='Allowed Products',
compute='_compute_allowed_products',
store=False,
)
@api.depends('partner_id')
def _compute_allowed_products(self):
for order in self:
if order.partner_id:
# Fetch products for that customer
# You must define a customer-product link. Here's an example:
customer_products = self.env['product.product'].search([
('allowed_customer_ids', 'in', order.partner_id.id)
])
order.allowed_products = customer_products
else:
order.allowed_products = self.env['product.product']
2. Add a New Field on Product to Link Allowed Customers
class ProductProduct(models.Model):
_inherit = 'product.product'
allowed_customer_ids = fields.Many2many(
'res.partner',
string='Allowed Customers'
)
You can use this to assign products to specific customers
3. Extend sale.order.line view with Domain on product_id
<field name="product_id" domain="[('id', 'in', order_id.allowed_products)]"/>
* This method is clean, modular, and respects Odoo’s domain mechanism.
* You can also restrict product search in product.template view if needed.
* Remember: this limits product selection but doesn’t prevent manual changes in backend unless you add constraints.
Hope it helps
Hi Daniel,
In Odoo there is a "Warning when selling this product" section under the Sales tab on Product form - need to activate it first through Settings. Where you can set to "Warning", so when your employee select the product and wants to confirm they need to double confirm. But, I guess this is not what you are looking for.
Extra addons I am not sure, sorry.
I do feel curious about the business flow that you are having now, maybe it's common just that I am not familiar because I am asking why are we not selling to customers? we don't want to gain revenue from certain customers?
Maybe you can share your thoughts on this.
Hope this helps.