~unifield-team/unifield-wm/us-826

« back to all changes in this revision

Viewing changes to product_attributes/product_attributes.py

  • Committer: jf
  • Date: 2011-11-14 15:34:27 UTC
  • mfrom: (374.3.1 uf-585)
  • Revision ID: jf@tempo4-20111114153427-bcc5os034csl9vu2
UF-585 [MERGE]  Product list should be limitated by the parent list

Show diffs side-by-side

added added

removed removed

Lines of Context:
73
73
class product_attributes(osv.osv):
74
74
    _inherit = "product.product"
75
75
    
76
 
    def _get_list_sublist(self, cr, uid, ids, field_name, arg, context={}):
77
 
        '''
78
 
        Returns all lists/sublists where the product is in
79
 
        '''
80
 
        if not context:
81
 
            context = {}
82
 
            
83
 
        if isinstance(ids, (long,int)):
84
 
            ids = [ids]
85
 
            
86
 
        res = {}
87
 
            
88
 
        for product in self.browse(cr, uid, ids, context=context):
89
 
            res[product.id] = []
90
 
            line_ids = self.pool.get('product.list.line').search(cr, uid, [('name', '=', product.id)], context=context)
91
 
            for line in self.pool.get('product.list.line').browse(cr, uid, line_ids, context=context):
92
 
                if line.list_id and line.list_id.id not in res[product.id]:
93
 
                    res[product.id].append(line.list_id.id)
94
 
                    
95
 
        return res
96
 
    
97
 
    def _search_list_sublist(self, cr, uid, obj, name, args, context={}):
98
 
        '''
99
 
        Filter the search according to the args parameter
100
 
        '''
101
 
        if not context:
102
 
            context = {}
103
 
            
104
 
        ids = []
105
 
            
106
 
        for arg in args:
107
 
            if arg[0] == 'list_ids' and arg[1] == '=' and arg[2]:
108
 
                list = self.pool.get('product.list').browse(cr, uid, int(arg[2]), context=context)
109
 
                for line in list.product_ids:
110
 
                    ids.append(line.name.id)
111
 
            elif arg[0] == 'list_ids' and arg[1] == 'in' and arg[2]:
112
 
                for list in self.pool.get('product.list').browse(cr, uid, arg[2], context=context):
113
 
                    for line in list.product_ids:
114
 
                        ids.append(line.name.id)
115
 
            else:
116
 
                return []
117
 
            
118
 
        return [('id', 'in', ids)]
119
 
    
120
76
    def _get_nomen(self, cr, uid, ids, field_name, args, context={}):
121
77
        res = {}
122
78
        
252
208
        'removal_time': fields.integer('Product Removal Time',
253
209
            help='The number of months before a production lot should be removed.'),
254
210
        'alert_time': fields.integer('Product Alert Time', help="The number of months after which an alert should be notified about the production lot."),
255
 
        'list_ids': fields.function(_get_list_sublist, fnct_search=_search_list_sublist, 
256
 
                                    type='many2many', relation='product.list', method=True, string='Lists'),
257
211
        'nomen_ids': fields.function(_get_nomen, fnct_search=_search_nomen,
258
212
                             type='many2many', relation='product.nomenclature', method=True, string='Nomenclatures'),
259
213
    }