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.

1

how to call function in _rec_name?

By
mihir shah
on 5/8/13, 11:05 AM 1,713 views

class metal_revision(osv.osv): _name = 'metal.revision' _rec_name = 'revision_no'

def _return_revision(self, cursor, user, field, context=None):            
#values=False  
#if not context.get('metal_revision_relation'):
   #return False        

qur=("""select revision_no from metal_revision where metal_revision_relation=3""" )
cursor.execute(qur)
    r = cursor.fetchall()
values=r[0]
return values   

_columns = {

    'revision_no': fields.char('Revsion No.', size=50,required=True,),
    'description':fields.char('Description', size=250),
    'residual_total':fields.float('Residucal Total',digits=(16,2)),
    'active':fields.boolean('Active'),
     'elements_line_ids':fields.many2many           ('metal.element','metal_elements_relation','metal_element_id','elements_line_ids','Elements'),
    'metal_revision_relation' : fields.many2one('metal.metal', 'Revision metal id'),        

}

i want only the selected field values(revision_no) should be return in '_rec_name' for dat i wrote sql query but how to call function in _rec_name

2

Francesco OpenCode

--Francesco OpenCode--
3608
| 5 7 9
Grottaglie, Italy
--Francesco OpenCode--

Italian Odoo (OpenERP) Modules Developer LINKEDIN: http://www.linkedin.com/in/francescoapruzzese

Francesco OpenCode
On 5/8/13, 11:10 AM

_rec_name is used to indicated what class field will be used instead of name as main field (for example as realation name). You can use a string that indicates the field name. If you want that this must be dynamic, you must create a function that return a field name and not a field value.

This answer is invalid.

2

Ghanshyam Prajapati

--Ghanshyam Prajapati--
1377
| 4 4 8
Pune, India
--Ghanshyam Prajapati--
OpenERP Developer
Ghanshyam Prajapati
On 5/8/13, 11:15 AM

After

_columns = {

    'revision_no': fields.char('Revsion No.', size=50,required=True,),
    'description':fields.char('Description', size=250),
    'residual_total':fields.float('Residucal Total',digits=(16,2)),
    'active':fields.boolean('Active'),
     'elements_line_ids':fields.many2many           ('metal.element','metal_elements_relation','metal_element_id','elements_line_ids','Elements'),
    'metal_revision_relation' : fields.many2one('metal.metal', 'Revision metal id'),        

}

Please paste following code.

_defaults={
    'revision_no': _return_revision,
}

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

0 follower(s)

Stats

Asked: 5/8/13, 11:05 AM
Seen: 1713 times
Last updated: 3/16/15, 8:10 AM