different view form for edit and create in odoo

夙愿已清 提交于 2019-12-03 21:52:07

@qatz

You cannot have different views based on "Edit" or "Create" of record.

You can try this by adding "state" field and based on the value of state you can hide show the elements.

Hope this helps !!

I have used attrs="{'invisible': [('id', '=', False)]}" to hide a field on creation. You must have id as a (hidden) field in your view, like <field name="id" invisible="1" />

you can easily work around this by using "create_date" as a trafic light.

1st expose the field

# make creation date visible
create_date = fields.Date(
    'Data',
    invisible=False,
    readonly=True,
)

then add it to the form and use it into attrs property

<field name="create_date" invisible="1" />
<ELEM attrs="{'invisible': [('create_date', '!=', False)]}">
[...]
</ELEM>

You can have different views for read, edit and create like this if desired

<div class="oe_read_only">
   READ ONLY
</div>
<div class="oe_edit_only" attrs="{'invisible':[('id', '=', False)]}">
   EDIT ONLY
</div>
<div attrs="{'invisible':[('id', '!=', False)]}">
   CREATE ONLY
</div>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!