SaaS DiaryA solo developer's diary of building and running software

Home › Tech log

Tech log

Stop salespeople changing the unit price and hide cost in Odoo 17 to 20

Read-only, hidden or required fields per user group, enforced on screens, imports, the API and AI agents

Published Updated Author GRAMSHIFT5 min read

Contents
  1. Why salespeople can change the price and see the cost
  2. Free ways to lock a field, and where they stop
  3. A read-only field that can still be changed by import
  4. Lock fields per user group on the server
  5. Frequently asked questions

To stop salespeople from changing the unit price or seeing the cost and margin in Odoo 17 to 20, add a rule that makes those fields read-only or hidden for your Sales users and is checked on the server, so imports, the API and AI agents are covered too: Field Lock, which we made at GRAMSHIFT, does this without code.

Odoo Community has no per-group field setting, every internal user can read a product's cost, and a field made read-only in the form view can still be changed by import, through the API, or by an AI agent or n8n flow using the person's API key. Below: why prices and cost are open by default, the free workarounds and their limits, and a no-code server-side rule that holds for screens, imports, the API and AI agents, checked against the Odoo 20 and Odoo 17 source.

  • Prices are free to edit. Unit Price is an ordinary editable field on the order line. The Sales setting Discounts shows or hides the Disc.% column for everyone; it has no per-group option.
  • Cost and margin are visible to all employees. The product Cost and Sales Margin's Unit Cost, Margin and Margin (%) are limited to base.group_user (shown as Role / User in Odoo 20 and Internal User in Odoo 17), which every internal user has.
  • Read-only in a view is not a lock. Imports and API calls write to the model, not to the form, so they never see the view's settings.
  • A server-side rule per field and user group is what actually holds, on every screen, import and API call.

Why salespeople can change the price and see the cost

In Odoo 20, Unit Price (price_unit) on a sales order line is computed from the pricelist but stays editable, and access rights are set per model: a user who may edit a quotation may edit all of its editable fields. There is no option in Settings to make one field read-only for one group.

The product Cost (standard_price) is declared with groups="base.group_user", and the Sales Margin module, which installs automatically with Sales, declares Unit Cost (purchase_price), Margin and Margin (%) the same way. That group is the ordinary internal user group, so every salesperson can read these values: on the form, in list columns they can add back, in exports, in pivot views and through the API. On Odoo 17, Sales Margin is installed when you turn on Margins in the Sales settings, and its fields are open to the same group.

Free ways to lock a field, and where they stop

  • Make the field read-only or invisible in the form view. An inherited view, or Odoo Studio in Enterprise, can grey out Unit Price or hide the Unit Cost column; Studio can even show a field only to some groups. This is still a display setting. Importing a file (Odoo's import calls the model directly), XML-RPC, JSON-RPC, JSON-2, and connectors such as n8n or an MCP server for an AI agent all bypass the form, so the value still changes or can still be read.
  • Turn off the Discounts setting. The Disc.% column disappears for everyone, managers included, and the unit price itself stays editable.
  • Record rules. They decide which records a user may read or edit, not which fields. A rule cannot say "this user may edit the order but not its price".
  • Change the code. A developer can override the model's write and create to refuse a field for a group, or change a field's groups attribute so that only managers can read it. This does work on the server, but it is custom code to write, test and carry through every upgrade, and each new field needs another change.

The first three are free and quick, but none of them is checked when the value arrives at the server. If the rule matters (prices, cost, margin), it has to be checked there.

A read-only field that can still be changed by import

This is the most common surprise. A field made read-only in the form view looks locked, but Import (in the gear menu next to the list title) still offers it as a column and writes the file's values straight to the model, and so does every API call. Setting readonly=True on the Python field keeps it off the Import screen, but write, create and load sent through the API still accept the value. Neither is a check on the server, and that is where the check has to be.

Lock fields per user group on the server

We made Field Lock for this (GRAMSHIFT, Odoo 17, 18, 19 and 20, Community and Enterprise on your own server or Odoo.sh; Odoo Online does not accept third-party Python modules). You add rules instead of editing views: a model, the fields, a mode (Read-only, Required or Hidden), the user groups it applies to and the groups exempted. No code. It is listed for Odoo 20, Odoo 19, Odoo 18, Odoo 17; on Odoo 17 and 18, which have no JSON-2 API, the lock covers XML-RPC and JSON-RPC.

  • Lock prices: Sales Order Line, Unit Price and Discount, Read-only, for Sales / User: Own Documents Only, except Sales / Administrator. Salespeople still create, quote and confirm; the price Odoo computes from the pricelist, also after a quantity change, is accepted. The Discount button below the order lines follows the rule.
  • Hide cost and margin: Product, Cost, and Sales Order Line and Sales Order, Unit Cost, Margin and Margin (%), Hidden (add Sales Analysis, Margin and Margin (%), if salespeople open reports). For salespeople the columns and the Margin line of the totals disappear, the API returns the values empty, and exporting, filtering or grouping by them is refused. Managers see everything as before.
  • Required for one team: Sales Order, Customer Reference, Required, for the sales team only, so every quotation carries the customer's PO number while other departments save as before.

The rule is checked on the values themselves, whatever sends them: the screen, an import, XML-RPC, JSON-RPC, JSON-2, or an AI agent using the salesperson's API key. A refused change rolls back the whole save and returns an access error that names the field (HTTP 403 on JSON-2, or 422 for a missing required field), so a person, an import file or an agent knows why. If you also want to control what an AI agent's API key may do beyond fields, AI API Key Permissions makes keys read-only or unable to delete, and AI API Key Approval holds their changes until a person approves them (these two are for Odoo 19 and 20).

Frequently asked questions

How do I stop salespeople from changing the unit price in Odoo?

Standard Odoo (17 to 20) has no setting for it: anyone who may edit a quotation may change its prices, and a read-only field in the form view can still be changed by import or API. A server-side rule does it: with Field Lock, a Read-only rule on Sales Order Line for Unit Price and Discount, applying to your Sales users except Sales administrators, so prices come from the pricelist.

How do I hide the cost price from salespeople in Odoo?

In standard Odoo the product Cost and the Sales Margin fields are readable by every internal user. Hiding the column in a view leaves the value in exports and the API. Hidden rules in Field Lock on Cost, Unit Cost, Margin and Margin (%), plus the Sales Analysis margin if salespeople open reports, remove them from salespeople's screens, return them empty through the API and refuse exporting or grouping by them.

A field is read-only in the form view, but users still change it with an import. Why?

A read-only setting in the form view only changes the screen: Import still offers the field and writes it, and so do XML-RPC, JSON-RPC and JSON-2 calls. readonly=True on the Python field keeps it off the Import screen, but API calls can still write it. The check has to be on the server: custom code overriding write and create, or a rules module such as Field Lock.

How do I make a field read-only or required for a specific user group in Odoo?

Odoo Community has no per-group setting for this. Without code, Field Lock adds rules: a model, the fields, a mode (Read-only, Required or Hidden), the groups it applies to and the groups exempted, checked on the server for screens, imports and the API.

Does Field Lock work on Odoo 19 or Odoo 18?

Yes. Field Lock is listed separately for Odoo 20, Odoo 19 and Odoo 18 on the Odoo Apps Store, with the same rules: read-only, required or hidden fields per user group, on screens, imports and the API. Odoo 18 has no JSON-2 API, so there the lock covers XML-RPC and JSON-RPC.

Does Field Lock work on Odoo 17?

Yes. Field Lock is listed for Odoo 17 (17.0) on the Odoo Apps Store, for Community and Enterprise on your own server or Odoo.sh, with the same read-only, required and hidden rules per user group on screens, imports and the API. Odoo 17 has no JSON-2 API, so the lock covers XML-RPC and JSON-RPC. It cannot be installed on Odoo Online, which does not accept third-party Python modules.

Can I hide the cost in Odoo 17 without a third-party module?

Only on some screens: a developer can limit the Cost field to a group in the views, but exports, filters and the API still read the value. To keep it from salespeople everywhere, a Hidden rule in Field Lock on Cost, Unit Cost, Margin and Margin (%) is checked on the server, so the value is empty through the API and cannot be exported or grouped by.

Related articles

Tech logKPI dashboard for Odoo Community 20: shared dashboards from any list or pivot, where each user sees only their own numbersOn Odoo 20 Community you can view ready-made dashboards but not build your own or share one with your team. An add-on turns any list, pivot or graph into a number card or chart from the gear menu, and counts every card with the viewer's own access rights, so salespeople see only their own totals. Tech logAI assistant for Odoo Community: ask your Odoo data in plain English with your own OpenAI, Claude or Gemini key (Odoo 20)Odoo 20 Community has no AI assistant that answers questions about your records. To ask "What were confirmed sales per month this year?" inside Odoo, you need an add-on that uses your own OpenAI, Claude, Gemini or Ollama key. What to check first: read-only, the asking user's rights, no SQL, and answers you can open in Odoo. Tech logSeparate inventory adjustment gains and losses in Odoo 19 and 20 (Stock Valuation Account Incoming and Outgoing are gone)Odoo 19 and 20 have one Loss Account on the Inventory adjustment location, so counts that find stock and counts that lose stock both post there and the profit and loss shows only the net. What changed from Odoo 18, the debit and credit of each case, the manual workaround, and a Gain Account next to the Loss Account. Tech logMake AI agent changes in Odoo wait for approval (ChatGPT, Claude, MCP, n8n, Odoo 20)Odoo 20 has no approval step for API calls outside purchases: JSON-2, XML-RPC and JSON-RPC run the method as soon as the key is checked, and confirming an order or posting an invoice needs no more than ordinary Sales or Billing rights. What standard Odoo offers, free ways to limit an AI agent, and how to make its changes wait for a person. Tech logRead-only Odoo API key for ChatGPT, Claude or an MCP server (Odoo 20)In Odoo 20 Community the only scope a new API key can get is RPC, and a key acts with every right of its user: on 2026-10-09 the same key that read orders also confirmed them through /json/2/sale.order/action_confirm. The free way to limit an AI agent is a dedicated user; where that stops, and why an ordinary update from an agent can remove order lines. Tech logWhen was an Odoo API key last used? Find unused keys and limit API calls (Odoo 20)An Odoo 20 API key stores its description, user, scope, creation date and expiration date, and nothing about its use. Latest Login on the user changes only for some clients, the server log does not name the key, and Odoo has no limit on calls per key. What each source shows, free ways to keep keys under control, and how to see the last call, IP address and daily calls of every key.
All English articles