Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Fields properties depending on edit or create (SOLVED)

By
Pau Ubach
on 9/18/14, 4:20 AM 704 views

I need to have a form where some fields are editable when the user creates the object, but not editable when the user is editing it. 

I mean:

  • When the user clicks create, the field must be editable.
  • When the user access an existing object (using a list) and clicks on edit, the field must be readonly.

 

1
Andreas Stauder
On 9/18/14, 5:38 AM

A record that is not already saved once, has no id. So you can relly on that:

readonly: [('id','>',0)]

Thanks, that's a good idea. Unfortunately it's always readonly, for creating and editing.

Pau Ubach
on 9/18/14, 5:45 AM

I have: 'cus_id': fields.related('quot_id', 'pr_id', 'cus_id', type="many2one", relation="bdd.customers", string="Customer", store=False, readonly="[('id','>',0)]"),

Pau Ubach
on 9/18/14, 5:47 AM

I think that the problem is that readonly is only evaluated when the object is created.

Pau Ubach
on 9/18/14, 6:55 AM
Then you can set a value in 

_defaults = {
  'new': True
}

that makes it possible to distinguish between a new record and a already created. When you overwrite the write(), you can reset the value:

def write(self, cr, uid, ids, vals, context=None):
   vals['new'] = False
   return super(res_partner_ext, self).write(cr, uid, ids, vals, context=context)

brain-tec AG, Andreas Stauder
on 9/18/14, 7:31 AM

It worked. Actually I needed to implement it in create instead of write, but it works. The only that I don't like is to add a new field in the table, but it works. Thanks.

Pau Ubach
on 9/19/14, 3:27 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 9/18/14, 4:20 AM
Seen: 704 times
Last updated: 3/16/15, 8:10 AM