[Python] Odoo 17: How to control which fields are available in the Export wizard using a...

Discussão em 'Python' iniciado por Stack, Julho 21, 2025.

  1. Stack

    Stack Membro Participativo

    What I want to know:


    • How do I properly prevent fields marked as restricted from showing in the Export wizard?


    • Do I need to override the export controller or monkey-patch export_data?


    • What is the best practice for this kind of field-level export restriction?

    Context:


    • Odoo version: 17;


    • Using a custom module with Python controllers;


    • I’m comfortable with inheriting controllers and adding custom routes.

    What I tried:


    • I added a custom boolean field named restricted to the ir.model.fields model using a custom addon;


    • I can see the restricted field in Settings → Technical → Fields, and I can check/uncheck it for any field;


    • I tried using attrs and access rights rules, but they only work in form or tree views, not in the Export wizard;


    • I attempted to restrict the field directly by modifying its properties in the database or UI, but that gave me this error:

    Invalid Operation:
    Properties of base fields cannot be altered in this manner! Please modify them through Python code, preferably through a custom addon.
    ​
    • I looked into export_data but I’m not sure how to properly override it or the Export controller logic.

    What I expected:
    I expected that when restricted is checked on a field, that field should not appear in the list of fields in the Export wizard (the box where you select which fields to export).

    I want normal users to never see restricted fields as exportable, while Admins can still configure which fields are restricted. Here is a screenshot of the ir.model.fields model with the restricted field visible: screenshot.

    Continue reading...

Compartilhe esta Página