Preventing users from creating products “on the fly”

Odoo has a “helpful” feature that allows users to create products (and customers, suppliers, etc., etc.) “on the fly”. This is when you enter a product name, no match is found, and Odoo lets you “Create” or “Create and Edit” a new product.

There are several potential problems with this:

  • the user may have mis-typed the name of the product (or customer, or supplier) and will create a duplicate that will cause further confusion.
  • there may be some information that needs to be added for a new product and that will not be entered.
  • a different user or department should be creating products (customers, suppliers) – of course, it may be possible to block this with security rules

The end result can be multiple products with similar names, products with incomplete or incorrect definition, products that should be services, etc.

Fortunately, Odoo does allow you to block this, and it can be done in Odoo Studio, as explained here.

There is a small complication when doing this for products on a sales order in Odoo 13, but there is a workaround.

  1. Enable Studio
  2. Click on the sales order line
  3. Click on the “Edit List View” button.
  4. Click on the “Product” field”
  5. Information about this field is displayed in the left-hand panel.

Note that in Odoo 13 Enterprise Edition, the field is product_template_id. In Odoo 13 Community Edition and previous versions (both Enterprise and Community), the field is product_id.

You will notice that:

  1. The widget is product_configurator
  2. No checkboxes for “Disable creation” and “Disable opening”

The workaround is to change the widget

Now, as you can see, those two checkboxes are visible.

  1. Click on both checkboxes (you may need to do this twice!!)
  2. Exit Studio
  3. Now there’s no option to add a product:

What’s happened here is that Odoo Studio has created an Extension View:

This is the XML:

</data>
   <xpath expr="//field[@name='product_template_id']" position="attributes">
     <attribute name="options">{"no_open":true,"no_create":true}</attribute>
     <attribute name="widget">many2one</attribute>
   </xpath>
</data>

If you don’t have Odoo Studio you could achieve the same effect by creating an Extension View manually.

  • You can probably remove the line that changes the widget, it doesn’t seem to cause any problems.

In older versions of Odoo Studio you would have to make another change (e.g. amend the field description) and then manually update the XML (you could remove the amended field description at the same time).

As noted above, the field is product_id

The XML will be something like this:

<data>
   <xpath expr="//form[1]/sheet[1]/notebook[1]/page[@name='order_lines']/field[@name='order_line']/tree[1]/field[@name='product_id']" position="attributes">
     <attribute name="string">_Product_ </attribute>
   </xpath>
</data>

Yes, Odoo Studio uses “path” statements like that!

You can amend it as follows:

  1. remove the change to the field description
  2. replace it with the “options”:
<data>
   <xpath expr="//form[1]/sheet[1]/notebook[1]/page[@name='order_lines']/field[@name='order_line']/tree[1]/field[@name='product_id']" position="attributes">
      <attribute name="options">{'no_quick_create':True,'no_create_edit':True}</attribute>
   </xpath>
</data>

Community Edition

Obviously there’s no Odoo Studio so you would have to create the Extension View manually (and the field is product_id).

3 thoughts on “Preventing users from creating products “on the fly”

  1. This is very fantastic. However, creating product on the fly provides some level of user convenience. If ‘creating product on the fly’ should be disable at all, it shouldn’t be for all users.

    Like

    1. It can be more convenient, but at the cost of allowing users to create data that might be incorrect. It might be possible to limit this to certain users, suggestions welcome.

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s