Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet

 In the Inventory app, it is possible to clearly assign a product to a supplier under the Purchasing tab. Now I have the following question using the following example:


I have a customer and create a sales order for them. We have preconfigured products in the warehouse that are theoretically freely available for sale to any other customer. Now we want to prevent this one product from mistakenly appearing in the sales order for a customer who is not allowed to buy it. I would therefore like to sell a product only to this one customer and not to anyone else.


I am of the opinion that we are not the only ones who have this wish. Is that possible? If not, does anyone know of an add-on or app that solves exactly this problem?

Avatar
Verwerfen

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.


Beste Antwort

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

Avatar
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
3
Dez. 18
4491
6
Jan. 24
13141
1
März 25
1751
1
Feb. 25
3207
2
Feb. 25
2134