python - 标签字段问题 - OpenErp

标签 python xml view orm openerp

我需要在 OpenErp 中显示字段的 labeltitle

我在 purchase 模块中有一段代码从表单中检索 company_id、partner_id、date_order 等,然后以串联的方式显示这些字段值:

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

然后我这样调用这个函数:

        'nombre' : fields.function(_combinalos, type='char', string='Nombre', arg=('empresa','provee','soli_cant', 'dest', 'anho'), method=True),

当然还有 XML View 代码:

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

作为函数字段的名称

问题是,当我保存文档时,它应该显示这些字段的名称或标签,但只显示字段的 ID 或其他内容:

Image

那么,我如何显示这些字段的“名称”或“标签”?可能是 xml 字段调用中的某个属性?

提前致谢。

最佳答案

1)Lable 不显示可能是因为你没有指定“for”属性像使用它一样

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

或者您可能在 h1 标签之外的 div 中使用类 oe_editonly,例如 .

<div class="oe_title">
    <div class="oe_edit_only">
       <h1> Your code </h1>
    </div>
</div>

这将仅在编辑模式下显示标签,一旦您保存记录标签将变得不可见。

2)问题是,当我保存文档时,它应该显示这些字段的名称或标签,但只显示字段的 ID 或其他内容:

这是因为你的函数 _combinalos 返回浏览对象 rec.company_id 的问题是返回公司的浏览对象如果你想要 id 你应该返回 rec.company_id .id 喜欢

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

关于python - 标签字段问题 - OpenErp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18972574/

相关文章:

python - Flask 中的嵌套蓝图?

xml - 通过 KissXML (iOS) 从包中加载 XML 文档

android - 使用 WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH 获取所有 MotionEvents

iphone - 有没有办法可以在 iPhone SDK 上制作叠加 View ?

android - 如何在android中使用ViewFlipper显示来自sqlite的内容

Python 总和(生成器): calling an external function

python - Django + redis session 跨多主机共享

python - tkinter - 无限 Canvas "world"/"view"- 跟踪 View 中的项目

xml - 如何在 XSLT 中将元素属性转换为元素名称?

python - 调用 ElementTree.parse 时为 "XML or text declaration not at start of entity: line 2, column 0"