gpt4 book ai didi

odoo - 如何将输入框值传递给 OpenERP 中的按钮操作函数?

转载 作者:行者123 更新时间:2023-12-02 15:06:27 28 4
gpt4 key购买 nike

弹出表单上有一个标有“原始”的输入框,其中包含键入的值“105-0045”,并附有图片。按钮点击操作代码位于函数action_replace()中。当点击“替换”按钮时,如何将输入框的值传递给按钮函数action_replace()?

enter image description here

这是我的 XML 代码,其中定义了输入框:

    <record id="replace_all_in_BOM_form" model="ir.ui.view">
<field name="name">replace.all.in.BOM.form</field>
<field name="model">product.template</field>
<field name="priority" eval="20"/>
<field name="type">form</field>
<field name="arch" type="xml">
<label class="text-inline" for="original_name" string="Original"
></label>
<input name="original_name" id="original_id" ></input>
<group>
<field name="default_code" string="Replacement" readonly="1"
invisible="0" />
<field name="uom_id" invisible="1" />
<field name="uom_po_id" invisible="1" />
<field name="type" invisible="1" />
<field name="categ_id" invisible="1" />
<field name="name" invisible="1" />
</group>
<button type="object" string="Replace" name="action_replace" />
</field>
</record>

<record id="action5" model="ir.actions.act_window">
<field name="name">Replace all in BOM</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">product.template</field>
<field name="view_type">form</field>
<field name="target">new</field>
<field name="view_id" ref="replace_all_in_BOM_form"/>
</record>

<record id="ir_BOM_structure5" model="ir.values">
<field eval="'client_action_multi'" name="key2"/>
<field eval="'product.template'" name="model"/>
<field name="name">Replace all in BOM</field>
<field eval="'ir.actions.act_window,'+str(action5)" name="value"/></record>

这是py代码的一部分:

def default_get(self, cr, uid, fields, context=None):
product_obj = self.pool.get('product.template')
record_ids = context and context.get('active_ids', []) or []
res = {}
for product in product_obj.browse(cr, uid, record_ids, context=context):
if 'default_code' in fields:
#in 'default_code' is a field name of that pop-up window
res.update({'default_code': product.default_code, 'name': product.name, 'uom_id': product.uom_id.id,
'uom_po_id': product.uom_po_id.id, 'type': product.type, 'categ_id': product.categ_id.id })
return res

def action_replace(self, cr, uid, ids, context=None):
txt_value = ''
for record in self.browse(cr,uid,ids,context=context):
txt_value = record.original_id
return {
'type': 'ir.actions.act_window',
'res_model': 'product.template',
'name': _('Replace all in BOM'),
'res_id': ids[0],
'view_type': 'form',
'view_mode': 'form',
'view_id': 1212,
'target': 'new',
'nodestroy': True,
'context': context
}

最佳答案

每当点击按钮时,系统默认的行为是先保存数据,然后执行按钮点击功能。因此,在单击按钮中您将找到当前记录的“ids”。以下是获取该文本框值的方法。

def action_replace(self,cr,uid,ids,context=None):
for record in self.browse(cr,uid,ids,context=context):
txt_value = record.original
<<your further code>>
return True

关于odoo - 如何将输入框值传递给 OpenERP 中的按钮操作函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28113814/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com