OpenERP onchange事件从父表中获取详细信息

时间:2012-11-13 08:32:13

标签: python xml openerp

抱歉,这是一个初学者问题。

我在OpenERP中有以下表格:

付款表(父表)

---------------------------------
| ID | OR_DATE     | TRANS_TYPE |
---------------------------------
| 1  | 2010-10-15  | 1          |
---------------------------------
| 2  | 2010-10-30  | 2          |
---------------------------------
| 3  | 2010-10-15  | 1          |
---------------------------------

付款明细表(子表)

---------------------------------------------------------------------
| ID | OTH_PYMT_ID  | DESCRIPTION      | ACCOUNT_TITLE_ID  | AMOUNT |
---------------------------------------------------------------------
| 1  | 1            | Cash Payment  1  | 1                 |  1,000 |
---------------------------------------------------------------------
| 2  | 1            | Check Payment 1  | 2                 |  1,000 |
---------------------------------------------------------------------
| 3  | 2            | Cash Payment  2  | 1                 |  1,000 |
---------------------------------------------------------------------

付款方式表(参考表)

-----------------------------------------
| ID  | DESCRIPTION      | ACCOUNT_CODE | 
-----------------------------------------
| 1   | Cash             | ACCCODE001   |
-----------------------------------------
| 2   | Check            | ACCCODE002   |
-----------------------------------------
| 3   | Credit Card      | ACCCODE003   |
-----------------------------------------

我在OpenERP中有2个类,具有以下结构:

Python代码:

payment(osv.osv):
    """
    OpenERP Model : payment
    """

    _name = 'payment'
    _description = __doc__

    _columns = {
        'or_date': fields.date('OR Date'),
        'trans_type':fields.many2one('payment.type', "Transaction Type"),
        'oth_pymt_det_ids':fields.one2many('payment.detail', 'oth_pymt_id', 'Details'),
    }
class payment()

class payment_detail(osv.osv):
    """
    OpenERP Model : payment_detail
    """

    _name = 'payment.detail'
    _description = __doc__

    #onchange_description function goes here

    _columns = {
        'oth_pymt_id':fields.many2one('payment', 'Payment'),
        'description':fields.char('Description', size=100 ),
        'account_title_id':fields.char('Account Title', size=20),
        'amount': fields.float('Amount', digits=(16, 2)),
    }

payment_detail()

XML代码:

<record model="ir.ui.view" id="payment_form">
    <field name="name">Payments</field>
    <field name="model">payment</field>
    <field name="type">form</field>
    <field name="arch" type="xml">
        <form string="Payments">
            <group col="4" colspan="4">
                <field name="trans_type" />
                <field name="or_date" />                                              
                <field name="oth_pymt_det_ids" mode="tree" nolabel="1" colspan="4">
                    <tree string="Payment Details" editable="top">
                        <field name="description" on_change="onchange_description()"/>
                        <field name="account_title_id"/>
                        <field name="amount"/>
                    </tree>
                </field>
            </group> 
        </form>
    </field>
</record>

如何在onchange_description类中添加payment_detail事件,该事件会自动从“付款”表中提取并打印详细信息?

提前致谢!

1 个答案:

答案 0 :(得分:5)

您可以使用参数。您可以在sale modulepython file

中找到示例

在您的情况下,请尝试使用

之类的内容
<field name="description" on_change="onchange_description(description, parent.or_date)"/>