~sebastien.beau/openobject-addons/on-change-support-extra-addons

« back to all changes in this revision

Viewing changes to product_search_reference/product.py

  • Committer: ced
  • Date: 2008-02-01 11:22:52 UTC
  • Revision ID: ced-2d060f7577c3a7f62ed46c5e75b6f2328a137d41
New module to search product base on partner code

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from osv import osv, fields
 
2
 
 
3
 
 
4
class Product(osv.osv):
 
5
        _inherit = 'product.product'
 
6
 
 
7
        def _partner_ref2(self, cursor, user, ids, name, arg, context=None):
 
8
                res = {}
 
9
                for product in self.browse(cursor, user, ids, context=context):
 
10
                        res[product.id] = '\n'.join([x.product_code \
 
11
                                        for x in product.seller_ids if x.product_code]) or ''
 
12
                return res
 
13
 
 
14
        def _partner_ref2_search(self, cursor, user, obj, name, args):
 
15
                supplierinfo_obj = self.pool.get('product.supplierinfo')
 
16
                args = args[:]
 
17
                i = 0
 
18
                while i < len(args):
 
19
                        args[i] = ('product_code', args[i][1], args[i][2])
 
20
                        i += 1
 
21
                supplierinfo_ids = supplierinfo_obj.search(cursor, user, args)
 
22
                product_ids = [ x.product_id.id for x in supplierinfo_obj.browse(cursor, user,
 
23
                                supplierinfo_ids) if x.product_id]
 
24
                return [('id', 'in', product_ids)]
 
25
 
 
26
        _columns = {
 
27
                'partner_ref2': fields.function(_partner_ref2, method=True,
 
28
                        type='char', string='Customer ref', fnct_search=_partner_ref2_search,
 
29
                        select=2),
 
30
        }
 
31
 
 
32
        def name_search(self, cursor, user, name='', args=None, operator='ilike',
 
33
                        context=None, limit=80):
 
34
                ids = self.search(cursor, user, [('partner_ref2', '=', name)] + args,
 
35
                                limit=limit, context=context)
 
36
                if ids:
 
37
                        return self.name_get(cursor, user, ids, context=context)
 
38
                return super(Product, self).name_search(cursor, user, name=name, args=args,
 
39
                                operator=operator, context=context, limit=limit)
 
40
 
 
41
Product()