How Can I show parent child together in many2one field lookup. For example product by category tree
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
I tried by applying a domain with 'not ilike' to display only the parent from partners and it worked.
I guess that you cand do this at python level too.
I will explain with default openerp core module addons\product\product.py
1) In Product screen category many2one
fields display with Category Name/ Parent Category Name
Based on this output Category name_get overridden
class product_category(osv.osv):
def name_get(self, cr, uid, ids, context=None):
if isinstance(ids, (list, tuple)) and not len(ids):
return []
if isinstance(ids, (long, int)):
ids = [ids]
reads = self.read(cr, uid, ids, ['name','parent_id'], context=context)
res = []
for record in reads:
name = record['name']
if record['parent_id']:
name = record['parent_id'][1]+' / '+name
res.append((record['id'], name))
return res
2) In Sale/Purchase order Product many2one
fields display with [Product code] Product Name
Based on this output Product name_get overridden
_name = "product.product"
def name_get(self, cr, user, ids, context=None):
if context is None:
context = {}
if isinstance(ids, (int, long)):
ids = [ids]
if not len(ids):
return []
def _name_get(d):
name = d.get('name','')
code = d.get('default_code',False)
if code:
name = '[%s] %s' % (code,name)
if d.get('variants'):
name = name + ' - %s' % (d['variants'],)
return (d['id'], name)
Hope this will help based on your requirement override name_get method.
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
3
Jul 24
|
22507 | ||
Highlight Records in Tree
Solved
|
|
3
May 23
|
1157 | |
|
1
Apr 23
|
2327 | ||
|
3
May 24
|
29271 | ||
|
1
Sep 18
|
9529 |
Override "name_get" method and many2one field shows product- Category. similar name_get example in the core module product/product.py available.
Thanks for the response. Can you please elaborate more how to override many2one field. For example i want to show something like below. parent -->child <newline> ->child2