1

私は OpenERP を初めて使用し、プログラミング全般の経験がありません。テキストフィールドの onchange イベントから応答を得ようとしています。フィールドがフォーカスを失う必要があることに注意して、コードが機能することを他の誰かが報告しているため、私の側の OS/ブラウザー/サーバー関連の問題である可能性があります。

フォーラム、ドキュメント、ヘルプ サイト (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()

ご覧のとおり、例外の発生と警告ダイアログの表示の両方を試しましたが、どちらも機能しませんでした。構文エラーを検出しました。

OS: Windows 7 64 ビット OpenERP 7.0 最新の安定リリース (postgresql を含む)。試したブラウザ: Chrome と Firefox。ノースクリプトなし。

補足として、最初に毎晩 OpenERP を使用して Ubuntu 12.04 VM で OpenERP を試しましたが、OS がほぼフリーズする 100% の CPU 負荷の問題に遭遇しました (マウスの動きは毎秒 0.5 フレーム)。

関連ページの抜粋: Openerp の Onchange 機能 https://www.openerp.com/files/memento/OpenERP_Technical_Memento_latest.pdf (6 ページの動的ビューを参照) http://forum.openerp.com/forum/topic34853.html

4

1 に答える 1

1

viewcrm.crm_case_form_view_leadsを継承しているため、attribute 属性を使用して継承するビューのフィールドを指定する必要がありposition = replace/after/beforeます。あなたのコードを見ると、CRMon_changeのフィールドにイベントを追加しようとしていると思います。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ファイルの一部。

于 2013-11-01T05:46:18.503 に答える