Reputation: 3897
I need to show the label
or title
of a field in OpenErp.
I have a piece of code in the purchase
module that retrieves company_id, partner_id, date_order, etc
from the form, and then show these fields values in a concatenated way:
def _combinalos(self, cr, uid, ids, field_name, args, context=None):
values = {}
for id in ids:
rec = self.browse(cr, uid, [id], context=context)[0]
values[id] = {}
values[id] = '0%s-%s%s-%s-%s' %(rec.company_id, rec.partner_id, rec.soli_cant, rec.dest, rec.date_order)
return values
Then i call this function like:
'nombre' : fields.function(_combinalos, type='char', string='Nombre', arg=('empresa','provee','soli_cant', 'dest', 'anho'), method=True),
And of course the XML view code:
<h1>
<label string="Request for Quotation " attrs="{'invisible': [('state','not in',('draft','sent'))]}"/>
<label string="Purchase Order " attrs="{'invisible': [('state','in',('draft','sent'))]}"/>
<field name="nombre" class="oe_inline" readonly="1" />
</h1>
Being nombre
the function field.
Problem is, when i save the document, it should show me the names or labels for these fields, but just shows me like the ID of the field or something:
So, how could i show the 'name' or 'label' for these fiels? Is it maybe some attribute in the xml field call?
Thanks in advance.
Upvotes: 3
Views: 2428
Reputation: 980
1)Lable is not display may be because you not specified " for
" attribute use it like
<h1>
<label string="Request for Quotation " for="nombre" attrs="{'invisible': [('state','not in',('draft','sent'))]}"/>
<label string="Purchase Order " for="nombre" attrs="{'invisible': [('state','in',('draft','sent'))]}"/>
<field name="nombre" class="oe_inline" readonly="1" />
</h1>
or may be you use a class oe_editonly
in div out side h1 tag like .
<div class="oe_title">
<div class="oe_edit_only">
<h1> Your code </h1>
</div>
</div>
This will display a label in edit mode only, once you save a record label becomes invisible.
2)Problem is, when i save the document, it should show me the names or labels for these fields, but just shows me like the ID of the field or something:
it is because the problem in your function _combinalos
return browse object rec.company_id that is return a browse object of company if you want id
you should return rec.company_id.id like
def _combinalos(self, cr, uid, ids, field_name, args, context=None):
values = {}
for id in ids:
rec = self.browse(cr, uid, [id], context=context)[0]
values[id] = {}
values[id] = '0%s-%s%s-%s-%s' %(rec.company_id.id, rec.partner_id.id, rec.soli_cant, rec.dest, rec.date_order)
return values
Upvotes: 4