【问题标题】:Not getting a response from on_change event in OpenERP 7.0在 OpenERP 7.0 中没有得到 on_change 事件的响应
【发布时间】:2013-10-31 18:57:43
【问题描述】:

我是 OpenERP 新手,对一般编程缺乏经验。我正在尝试从文本字段上的 onchange 事件中获得任何响应。其他人报告说该代码有效,并指出该字段必须失去焦点,因此这可能是我这边的操作系统/浏览器/服务器相关问题。

我尝试了多种变量组合,因为论坛、文档和帮助网站(如 stackoverflow)上的建议各不相同。

查看:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
  <data>
    <record model="ir.ui.view" id="view_product_form_custom">
      <field name="name">CRM - Leads Calendar.inherit</field> 
      <field name="model">crm.lead</field>
      <field name="inherit_id" ref="crm.crm_case_form_view_leads" /> 
      <field name="arch" type="xml">
        <field name="partner_name" on_change="testchange(contact_name)" /> <!-- Note: position="replace" works, have tried partner_name, context and combinations here. -->
        <!-- <field name="contact_name" /> -->
      </field>
    </record>
  </data>
</openerp>

控制器:

from openerp.osv import fields, osv # import crm/leads/view as well?

class modcontroller(osv.osv):
    """Attempting to change contact_name onchange partner_name (Company Name).
    """
    _inherit = "crm.lead"
    _columns = {
        'contact_name': fields.char('Contact Name', size=64, readonly=False),
        'partner_name': fields.char("Customer Name", size=64, help='Got your nose!', select=1, readonly=False),
                }
    _defaults = {
                 }

    def testchange(self, cr, uid, ids, contact_name): #partner_name, context=None
#         return {'warning': {'title': 'test', 'message': 'hello world'}}
#         raise Exception("Are you still there?")
        return {'value': {'contact_name': 'testing'}}


modcontroller()

如您所见,我尝试了引发异常并显示警告对话框,但均未奏效。它确实检测到语法错误。

操作系统:Windows 7 64 位 OpenERP 7.0 最新稳定版本,包括 postgresql。 尝试过的浏览器:Chrome 和 Firefox。没有 NoScript。

附带说明:我首先在 Ubuntu 12.04 VM 上使用 OpenERP 尝试 OpenERP,但我遇到了 100% CPU 负载问题,这几乎使操作系统冻结(鼠标移动每秒 0.5 帧)。

相关网页摘录: Onchange function in Openerp https://www.openerp.com/files/memento/OpenERP_Technical_Memento_latest.pdf(见第 6 页,动态视图) http://forum.openerp.com/forum/topic34853.html

【问题讨论】:

    标签: python xml openerp onchange


    【解决方案1】:

    由于您要继承视图crm.crm_case_form_view_leads,因此您必须使用属性position = replace/after/before 属性指定您必须继承视图中的哪个字段。查看您的代码,我认为您正在尝试将 on_change 事件添加到 CRM 中的字段 partner_name。这可以通过以下方式实现:

    <record model="ir.ui.view" id="view_product_form_custom">
      <field name="name">CRM - Leads Calendar.inherit</field> 
      <field name="model">crm.lead</field>
      <field name="inherit_id" ref="crm.crm_case_form_view_leads" /> 
      <field name="arch" type="xml">
        <xpath expr="//field[@name='partner_name']" position="attributes">
            <attribute name="on_change">testchange(partner_name)</attribute>
        </xpath>
      </field>
    </record>
    

    由于partner_namecontact_name 字段已经存在于模型crm.lead 中,因此您不必再次继承模型crm.lead 并添加这些字段。所以你可以省略

    _columns = {
        'contact_name': fields.char('Contact Name', size=64, readonly=False),
        'partner_name': fields.char("Customer Name", size=64, help='Got your nose!', select=1, readonly=False),
                }
    

    你的 python 文件的一部分。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-09
      • 2014-04-10
      相关资源
      最近更新 更多