Odoo Help

0

Use id's object like default value for another field

By
Clément Glandus
on 4/8/13, 4:55 AM 2,723 views

Hello,

I'm creating a module to manage the no-compliance. To do that a create the object named 'incident' like that :

class non_compliance_incident(osv.osv): _name = "non.compliance.incident" _description = "Incident"

_columns = {
    'date': fields.datetime('Date de création', readonly=True),
    'product_id': fields.many2one('product.product', 'Produit', required=True),
    'partner_id': fields.many2one('res.partner', 'Fournisseur', required=True),
    'reference':fields.char('Référence',size=64),
    'description':fields.char('Description de la non-conformité',size=128),
    'user_id': fields.many2one('res.users', 'Crée par', readonly=True),
    'state': fields.selection([('draft','Brouillon'),('confirmed','En cours'),('done','Soldée'),('cancel','Annulée')],'Statut', size=32),
    'quantity': fields.integer('Quantité'),
}
_defaults = {
    'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
    'user_id': lambda object,cr,uid,context: uid,
    'state': lambda * a:'draft',
}

nctm_incident()

I want to use the id of the object to define the default value of the field 'description'. For exemple :

id = 1 => description IS "NC1" id = 9852 => description IS "NC9852"

Please let me know how to define the default value of the field "description", so my question :

'description': lambda ???

Thank you very much,

CGS

2

Vasiliy Birukov

--Vasiliy Birukov--
Vasiliy Birukov
http://codup.com
3456
| 6 6 8
Russian Federation
--Vasiliy Birukov--

Help develop and implement any project on base Odoo.

Vasiliy Birukov
On 4/9/13, 2:45 AM

You can't use ID as parametr for calculation default value. Because when you open form for create new records, ID yet not assigned, so at this moment it undefined. You can redefine create method and calculate your "description" base on new ID, that you receive after creating record. But while you don't save record, "description" will uncalculated.

If you need unique identificator, then better use builtin model - sequence.

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 platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)

Stats

Asked: 4/8/13, 4:55 AM
Seen: 2723 times
Last updated: 3/16/15, 8:10 AM