2016-08-16 2 views
1

on_changeを使用して選択フィールドの値を変更しようとしています。私は以下のコードを持っています。on_changeを使用して選択フィールドの値を変更します。

の.xml

<field name="product_id" on_change="onchange_partner_id_override(product_id, context)" 

の.py

class sale_order_line(osv.osv): 
    _inherit = "sale.order.line" 
    _columns = { 
     'product_id': fields.many2one('product.product', "Product"), 
     'price_select': fields.selection(SELECT_PRICE, "Unit Price"), 
    } 
    def product_id_change_override(self, cr, uid, ids, product, context=None): 
     result = [] 
     product_obj = self.pool.get('product.product') 
     product_obj = product_obj.browse(cr, uid, product, context=context_partner) 

     global SELECT_PRICE 
     SELECT_PRICE = [ 
      ('sale_price', product_obj.list_price), 
      ('dist_price', product_obj.distributor_price), 
      ('emp_price', product_obj.employee_price), 
     ] 

     # How could I change the value of my selection field 'price_select' 

     return {'value': result} 

しかし、私は私の選択フィールドにこのデータを追加する方法についての構文を知りません。 誰かが私を助けてくれますか!

答えて

2

あなたがproduct_id_changeメソッドをオーバーライドし、value辞書にprice_selectフィールドの値を指定する必要がありますラインRES =スーパー(...)上の

def product_id_change(self, cr, uid, ids, pricelist, product, qty=0, 
     uom=False, qty_uos=0, uos=False, name='', partner_id=False, 
     lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False, context=None): 

    res = super(sale_order_line, self).product_id_change(cr, uid, ids, pricelist, product, qty, 
     uom, qty_uos, uos, name, partner_id, 
     lang, update_tax, date_order, packaging, fiscal_position, flag, context) 

    res['value'].update({'price_select': 'emp_price'}) 

    return res 
+0

。 product_id_changeは私にエラーを与えます。 AttributeError: 'super'オブジェクトに 'product_id_change'属性がありません – weelDaw

+0

@weelDawエラーログを貼り付けてください。 – Zety

+0

この質問は既に解決されています。しかし、解決策が私の質問からあまりにも遠いので、投稿できません。 :) .. – weelDaw

関連する問題