Help

欢迎!

该社区面向专业人士和我们产品和服务的爱好者。
分享和讨论最好的内容和新的营销理念,建立您的专业形象,一起成为更好的营销人员。


0

Make readonly start_date, end_date from sale order view

Avatar
Discard
2 Answers
0
Avatar
odoo
Best Answer

Hi,


Try the following code.


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

    <field name="name">sale.subscription.order.form.readonly</field>

    <field name="model">sale.order</field>

    <field name="inherit_id" ref="sale_subscription.sale_subscription_primary_form_view"/>

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

        <xpath expr="//field[@name='start_date']" position="attributes">

            <attribute name="readonly">1</attribute>

        </xpath>

        <xpath expr="//field[@name='end_date']" position="attributes">

            <attribute name="readonly">1</attribute>

        </xpath>

    </field>

</record>


In the enterprise add-on, there is another view that inherits from sale_subscription.sale_subscription_order_view_form and is set as the primary view.


Hope it helps

Avatar
Discard
0
Avatar
odoo
Best Answer

Hi,

Here is update code so please try this 
<record id="sale_subscription_order_view_form_readonly" model="ir.ui.view">

    <field name="name">sale.subscription.order.form.readonly</field>

    <field name="model">sale.order</field>

    <field name="inherit_id" ref="sale_subscription.sale_subscription_order_view_form"/>

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

        <xpath expr="//field[@name='start_date']" position="attributes">

            <attribute name="readonly">1</attribute>

        </xpath>

        <xpath expr="//field[@name='end_date']" position="attributes">

            <attribute name="readonly">1</attribute>

        </xpath>

    </field>

</record>


Use xpath for reliability


other way to make filed readonly is :


<field name="start_date" readonly="1"/>

<field name="end_date" readonly="1"/>

it is make always readonly filed


I hope it is usefull

3 Comments
Avatar
Discard
Avatar
odoo
-

in Odoo 18 we can do both path and using fields also.
I already tried this approach but it's no working

Avatar
odoo
-

Hii,
Check This:
Open a sale order in Odoo

Enable Developer Mode

Click the bug icon → "Edit View: Form"

Note the External ID — is it really sale_subscription.sale_subscription_order_view_form?

If not — you are patching the wrong view.
start_date and end_date are coming from another model
Use Developer Mode to check the field origin:

Hover over the field label → if it's a related field (e.g., from subscription_id.start_date), you must modify that model/view, or set readonly in the Python field definition.
Some view or module is overriding your change after yours loads
To rule this out:

Give your view a high sequence:
<field name="priority" eval="1000"/>

OR place it at the bottom of the data list in your __manifest__.py

Try This Final Setup (Full Example):

<record id="sale_order_start_end_readonly" model="ir.ui.view">
<field name="name">sale.order.readonly.start_end</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale_subscription.sale_subscription_order_view_form"/>
<field name="priority" eval="1000"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='start_date']" position="attributes">
<attribute name="readonly">1</attribute>
</xpath>
<xpath expr="//field[@name='end_date']" position="attributes">
<attribute name="readonly">1</attribute>
</xpath>
</field>
</record>
i hope it is usefull
Add this temporarily to verify:
<xpath expr="//field[@name='start_date']" position="replace">
<field name="start_date" readonly="1"/>
</xpath>

Avatar
odoo
-

I did this, The external id is sale.view_order_form but there is no field called start_date and end_date.
so I check the inherited views and then find it is subscription module's view and tried to change the attribute but it is not working.
I did it using python field as well but don't know what wrong with this!