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

时间:2022-11-15 20:05:44

python code:

python代码:

_name = 'res.partner.table2'

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

XML:

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>

I need search by other field instead "name". How is it possible?

我需要通过其他字段搜索“name”。这怎么可能?

1 个解决方案

#1


1  

We can achieve with following:

我们可以实现以下目标:

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

We add context to make sure functionality will effect to particular field and not disturb existing functionality.

我们添加上下文以确保功能将对特定字段产生影响,而不会干扰现有功能。

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)

#1


1  

We can achieve with following:

我们可以实现以下目标:

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

We add context to make sure functionality will effect to particular field and not disturb existing functionality.

我们添加上下文以确保功能将对特定字段产生影响,而不会干扰现有功能。

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)