Skip to content

Instantly share code, notes, and snippets.

@drkpkg
Last active May 11, 2018 00:10
Show Gist options
  • Save drkpkg/7583303feaecd19c7233f610248aaab0 to your computer and use it in GitHub Desktop.
Save drkpkg/7583303feaecd19c7233f610248aaab0 to your computer and use it in GitHub Desktop.
# This came up with a huge problem for days, but i resolve it.
# The main problem is the limitation in form in odoo. Mostly of this are not in the official documentation,
# so maybe you will feel a bit blind sometimes, but I feel you bro.
# Basically works for partner_id relation for many2one
# PART ONE
# Create a class res_partner.py
class ResPartner(models.Model):
"""This part is the easy part, @api.model overrides to name_get (optional) and name_search."""
_inherit = 'res.partner'
@api.model
def name_get(self):
result = []
for record in self:
name = '[' + str(record.client_code) + ']' + ' ' + record.name
result.append((record.id, name))
return result
@api.model
def name_search(self, name='', args=None, operator='ilike', limit=100):
try:
int(name) # Special case: I need to filter in case the input us integer only
args = args if args else []
args.extend([['client_code', 'ilike', name]])
name = ''
except:
pass # Do nothing
return super(ResPartner, self).name_search(name=name, args=args, operator=operator, limit=limit)
# SECOND PART
# Put the filter in the xml
# res_partner_filter.xml
<odoo>
<data>
<record id="view_res_partner_filter" model="ir.ui.view">
<field name="name">view.res.partner.filter.inherit</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_res_partner_filter"/>
<field name="arch" type="xml">
<field name="name" position="after">
<field name="client_code"/>
</field>
</field>
</record>
</data>
</odoo>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment