Python 在一个字段中显示输入的3个字段
我想知道是否有某种方式可以在一个字段中显示,其他三个字段的串联,已经是相同的形式 例如:Python 在一个字段中显示输入的3个字段,python,orm,module,field,openerp,Python,Orm,Module,Field,Openerp,我想知道是否有某种方式可以在一个字段中显示,其他三个字段的串联,已经是相同的形式 例如: 'field_1' : fields.integer('Campo 1'), field_2' : fields.integer('Campo 2'), field_3' : fields.integer('Campo 3'), 然后在一个字段中显示这3个字段的输入: field_concatenated : fields.related(?)('field_1', 'field_2', 'field
'field_1' : fields.integer('Campo 1'),
field_2' : fields.integer('Campo 2'),
field_3' : fields.integer('Campo 3'),
然后在一个字段中显示这3个字段的输入:
field_concatenated : fields.related(?)('field_1', 'field_2', 'field_3', 'Name of the field'),
我放了一个“?”符号,因为我实际上不知道如何实现这一点,可能使用了相关的类型一?顺便说一下,这3个字段在同一个类窗体上
结果字段可以是只读
,并在表单保存后显示
我希望我已经解释清楚了
提前谢谢
EDIT
字段的类型可以是integer
和char
2nd EDIT
实例:
'empresa' : fields.integer('Empresa'),
'provee' : fields.integer('Proveedor'),
'soli_cant' : fields.integer('Cantidad de Solicitudes'),
'dest' : fields.char('Destino'),
'anho' : fields.integer('Año'),
因此,手动填充这些字段后,结果字段必须以类似于empresa-proveesoli\u cant-dest-anho
一个接一个地被证明是provee
和soli\u cant
(没有“-”),如果不可能,则显示没有分隔符的串联
也许它不一定在python代码中声明,也许在xml视图中有一些快捷方式
类似于
idk
3rd EDIT
我现在使用的实际代码(感谢):
各栏:
'empresa' : fields.integer('Empresa'),
'provee' : fields.integer('Proveedor'),
'soli_cant' : fields.integer('Cantidad de Solicitudes'),
'dest' : fields.char('Destino'),
'anho' : fields.integer('Año'),
包含其列的函数:
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][field_name] = '%s %s %s %s %s' %(rec.empresa, rec.provee, rec.soli_cant, rec.dest, rec.anho)
return values
columns = {
'nombre' : fields.function(_combinalos, string='Referencia de Pedido', type='char', arg=('empresa','provee','soli_cant', 'dest', 'anho'), method=True),
当然,所有这些都在同一个课堂上
然后我从xml视图中调用它,如下所示:
<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>
如果这是报价请求
或采购订单
在所有这些之后,我确实填充了integer
和char
类型的5个字段,但仍然没有将这些字段“串联”在一个字符串或标题中,只是一个标签上写着[object object],这可能是标签的问题?列中函数的字符串名称可能?创建一个新的函数字段,并将其他三个字段组合在一起:
def _combine(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] = '%s %s %s' % (rec.field1, rec.field2, rec.field3)
return values
_columns = {
...
fields.function(_combine, string='three fields in one!', type='char',
arg=('field1','field2','field3'), method=True),
注:未测试代码
\u combine
方法应与其他列以及字段一起成为类的一部分。function
也应位于该类的\u columns
创建一个新的functional字段,并将其他三个字段合并在一起:
def _combine(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] = '%s %s %s' % (rec.field1, rec.field2, rec.field3)
return values
_columns = {
...
fields.function(_combine, string='three fields in one!', type='char',
arg=('field1','field2','field3'), method=True),
注:未测试代码
\u combine
方法应该与其他列以及字段一起成为类的一部分。函数
也应该在该类的\u列中
你有可以发布的现有代码吗?实际上我没有,但为了澄清起见,我可以尽快写下一个,我将编辑我的问题。进行编辑,我希望这能澄清我的问题,谢谢。你有可以发布的现有代码吗?事实上我没有,但我可以尽快写下一个,以便澄清,我将编辑我的问题。编辑完成后,我希望这能澄清我的问题,谢谢。谢谢!但是它给了我一个错误,说“TypeError:‘str’object不可调用”错误出现在‘return’语句之前的最后一行,我使用了5个字段,4个整数和1个字符,这可能是问题所在吗?@KristianKoci:我忘记了那一行上的%
符号。修正了,太棒了!但它只显示了[object object]我填写的字段,但没有显示这些字段的数据,只是[object object]谢谢,但如果我理解得很好,那么它已经在同一个类中,所有:integer、char和function,包括function本身(_combine)都在同一个类中:(,是的,都在同一列中。我的意思是,函数与所有字段在同一类中,函数字段与其他字段在同一列中。谢谢!但它给了我一个错误,说“TypeError:'str'对象不可调用”错误出现在“return”语句前的最后一行,我使用了5个字段,即4个整数和1个字符,这可能是问题吗?@KristianKoci:我忘记了那行上的%
符号。修复了。太棒了!但它只显示了[object object]我填充了字段,但没有显示这些字段的数据,只有[object object]谢谢,但是如果我理解的很好,那么它已经在同一个类中了,所有:integer、char和function,包括function本身(_combine)都在同一个类中:(,是的,都在同一列中。我的意思是,function与所有字段在同一个类中,function field与其他字段在同一列中。