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

标签 odoo

弹出表单上有一个标有“原始”的输入框,其中包含键入的值“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/

相关文章:

python - 错误 : gevent 1. 4.0 要求 greenlet>=0.4.14,但您将拥有不兼容的 greenlet 0.4.13

javascript - Uncaught ReferenceError : openerp is not defined

python - Odoo v9 - 在编辑表单(不创建)时设置动态域

python - 在 OpenERP-7 中通过按钮调用 TreeView

python - 在 OpenERP 中保存机会时发出警告

python - 如何为不同字段添加 "decoration-danger"?例如,如果我的字段不属于 50-100,我想将其更改为红色。对于其他可能是 85-95

python - 为odoo中的特定组发送通知

javascript - 如何在 Web 客户端上扩展基本字段小部件

report - 如何格式化 Odoo 8 QWeb 报告中的日期?

Odoo 8 - 从 python 方法启动 ir.actions.act_window?