0
votes

I'd like to know is it possible to have different form views for edit mode and create mode in odoo ?

Actually I just want to hide some elements in create mode and show it in edit mode.

I've tried to using attrs like :

<button name="%(print_invoice)d" string="Cetak Struk" type="action" attrs="{'invisible':[('id', '!=', False)]}" />    

But when i open the form it gives me error like this :

Uncaught Error: Unknown field id in domain [["id","!=",false]]    

Any help would be appreciated.

Thank you

4

4 Answers

2
votes

@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 !!

6
votes

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" />

5
votes

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>
3
votes

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>