gpt4 book ai didi

python - 使用 on_change 更改选择字段的值

转载 作者:行者123 更新时间:2023-12-01 03:45:38 24 4
gpt4 key购买 nike

我正在尝试使用 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}

但我不知道如何将此数据附加到我的选择字段上的语法。有人可以帮助我吗?

最佳答案

您需要重写product_id_change方法并在value字典中指定price_select字段的值:

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

关于python - 使用 on_change 更改选择字段的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38969990/

24 4 0
文章推荐: javascript - 如何防止幻灯片循环回到开头?
文章推荐: google-compute-engine - 如何将永久性磁盘挂载到容器卷?
文章推荐: javascript - 选择要动态更新的
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com