qatz
qatz

Reputation: 163

different view form for edit and create in odoo

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

Upvotes: 0

Views: 6169

Answers (4)

Fractalf
Fractalf

Reputation: 5319

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>

Upvotes: 3

cgs
cgs

Reputation: 342

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

Upvotes: 7

simahawk
simahawk

Reputation: 2431

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>

Upvotes: 5

Hardik Patadia
Hardik Patadia

Reputation: 1999

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

Upvotes: 2

Related Questions