Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
504 Zobrazení

Hello,


In Odoo 18, I have two models:

class A(models.Model):
_name = 'class.a'

name = fields.Char(string='Name')
other_field = fields.Char(string='Other Field')

class B(models.Model):
_name = 'class.b'

name = fields.Char(string='Name')
a_ids = fields.Many2many(string='A_ids', comodel_name='class.a')

And I have an XML view for the 'class.b'

<record id="class_b_fom_view" model="ir.ui.view">
<field name="name">class.b.form.view</field>
<field name="model">class.b</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form>
<field name="name"/>
<field name="a_ids">
<list create="False">
<field name="name"/>
<field name="other_field"/>
</list>
<form create="False" edit="False" delete="False">
<field name="name"/>
<field name="other_field"/>
</form>
</field>
</form>
</field>
</record>

I can add existing 'class.a' records.

I can't create, modify or delete 'class.a' records.

However, if I click on a record already selected, and if I click on the maximization button (top, at left of X close button) of the form of 'class.a', Odoo switch to the normal 'class.a' form and I can modify and suppress the record, as well as create a new 'class.a' record.

How to avoid this behavior, e.g.deleting the maximization button or hiding it?


Best regards,


Boris

Avatar
Zrušit

Who is supposed to create/write/unlink class.a records? Because this sounds more like bad permission management. With two access rules you could simply prevent peasants from doing any modification and only grant it to users with elevated access.

Nejlepší odpověď

Hi,


If you want to restrict users from creating, editing, deleting, or opening class.a records from the class.b form view (i.e., disable the maximize button and keep the inline widget read-only), you can configure the XML like this:


<record id="class_b_form_view" model="ir.ui.view">

    <field name="name">class.b.form.view</field>

    <field name="model">class.b</field>

    <field name="arch" type="xml">

        <form>

            <field name="name"/>

            <field name="a_ids" options="{'no_open': True}">

                <list create="False">

                    <field name="name"/>

                    <field name="other_field"/>

                </list>

                <form create="false" edit="false" delete="false">

                    <field name="name"/>

                    <field name="other_field"/>

                </form>

            </field>

        </form>

    </field>

</record>


    options="{'no_open': True}": hides the maximize button from the inline form.


    create="false", edit="false", delete="false" inside <form>: disables creation, editing, and deletion of related records.


    create="false" inside <list>: disables adding new records from the list view.


This setup ensures users can only view existing class.a records inline without being able to open them in a separate full form view.


Hope it helps.

Avatar
Zrušit