gpt4 book ai didi

python - 如何在many2one中搜索其他字段?

转载 作者:太空宇宙 更新时间:2023-11-03 14:17:48 25 4
gpt4 key购买 nike

Python 代码:

_name = 'res.partner.table2'

customer_id = fields.Many2one('res.partner', required=True ,string="Customer ID")

XML:

<field name="arch" type="xml">
<form string="Reward Points">
<field name="customer_id"/> //how can i search by res.partner customer_id in here
</form>
</field>

我需要通过其他字段而不是“名称”进行搜索。怎么可能?

最佳答案

我们可以通过以下方式实现:

<field name="customer_id" context="{'my_custom_search': True}"/>

我们添加上下文以确保功能会影响特定领域并且不会干扰现有功能。

class res_partner(models.Model):
_inherit = 'res.partner'

def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=100):
if not args:
args = []
if not context:
context = {}
if context.has_key('my_custom_search'):
domain = [('field_name', 'operator', value)]
ids = self.search(domain)
else:
return super(res_partner, self).name_search(cr, user, name, args=args, operator='ilike', context=context, limit=limit)
return self.name_get(cr, uid, ids, context)

关于python - 如何在many2one中搜索其他字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48144925/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com