As described here, I have created a many2one field with custom selection function:
def _buyer_selection(self, cr, uid, context=None):
partner_obj = self.pool.get('res.partner');
res = [];
partner_ids = partner_obj.search(cr, uid, [('buyer','=',True)]);
for partner in partner_obj.browse(cr, uid, partner_ids, context=context):
res.append((partner.id, partner.buyer_code))
return res;
_columns = {
'buyer_id': fields.many2one('res.partner', 'Buyer', selection=_buyer_selection),
}
But in the view
<field name="buyer_id"/>
It still acts like a normal many2one field. All partners selectable, no buyer_code displayed.
Although:
The debug view shows a perfectly working selection...
What am I missing?!
EDIT:
<field name="buyer_id" widget="selection"/>
Selection widget doesn't work.
The field will become a selection field indeed, but the custom selection function seems to be overridden:
I think based on your requirement to override name_get method and shows buyer_code
Thanks for your reply.
I only need the buyer_code in this single case. All other modules should show the partner.name.
For your situation i think you should use fields.related