如何使用onchange功能更改帐户发票行price_unit的价格

时间:2012-10-02 09:47:04

标签: openerp

我想使用onchange将帐户发票价格设置为res.partner中设置的默认价格。谁能举个例子呢?

谢谢, 乔

2 个答案:

答案 0 :(得分:1)

插件中有很多onchange的例子。
例如,如果要更改“名称”字段的值,并希望根据所选产品设置产品名称:

def onchange_product_id(self, cr, uid, ids, product_id, context=None):
    if product_id:
        prod = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
        return {'value': {'name': prod.name}}
    return {}

答案 1 :(得分:0)

将此内容写入your_invoice_view.xml:

<field name="product_id" on_change="product_id_change(product_id, parent.partner_id, context)"/>

在“invoice_line”模型(类)下的your_invoice.py中写入onchange:

def onchange_product_id_change(self, cr, uid, ids, product_id, partner_id context=None):
if product_id and partner_id:
    product_brw = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
    partner_brw = self.pool.get('res.partner').browse(cr, uid, partner_id, context=context)
    /*write your logic */
    return {'value': {'price_unit': your calculated value}}
return {}