From 071ae2713414e22f0e703129bb457e766b143de8 Mon Sep 17 00:00:00 2001 From: "Amit (OpenERP)" Date: Thu, 2 Jun 2011 12:25:59 +0530 Subject: [PATCH] [IMP]:product,stock:Added a field 'Stock of Warehouse' and rename 'extended filter' into 'Context' and also improved the code for method. bzr revid: apa@tinyerp.com-20110602065559-20u83owfgt32sb1o --- addons/product/product_view.xml | 6 +++--- addons/stock/product.py | 22 ++++++++++++++++++---- addons/stock/product_view.xml | 1 + 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/addons/product/product_view.xml b/addons/product/product_view.xml index 0a2a309ba92..bcbded962f0 100644 --- a/addons/product/product_view.xml +++ b/addons/product/product_view.xml @@ -19,7 +19,7 @@ - + @@ -201,8 +201,8 @@ product.product form {"search_default_filter_to_sell":1} - - + + You must define a Product for everything you buy or sell. Products can be raw materials, stockable products, consumables or services. The Product form contains detailed information about your products related to procurement logistics, sales price, product category, suppliers and so on. diff --git a/addons/stock/product.py b/addons/stock/product.py index 2a819ea89b2..76e499c454e 100644 --- a/addons/stock/product.py +++ b/addons/stock/product.py @@ -182,6 +182,10 @@ class product_product(osv.osv): """ if context is None: context = {} + + location_obj = self.pool.get('stock.location') + warehouse_obj = self.pool.get('stock.warehouse') + states = context.get('states',[]) what = context.get('what',()) if not ids: @@ -198,6 +202,15 @@ class product_product(osv.osv): context['warehouse'] = res2[0] if context.get('warehouse', False): + + # write code for added filter in product view. + if isinstance(context['warehouse'],str): + warehouse_id = warehouse_obj.search(cr, uid, [('name','ilike',context['warehouse'])], context=context) + if warehouse_id: + context['warehouse'] = warehouse_id[0] + else: + raise osv.except_osv(_('Warning!'),_('There is no warehouse defined name like: "%s"')%(context['warehouse'],)) + cr.execute('select lot_stock_id from stock_warehouse where id=%s', (int(context['warehouse']),)) res2 = cr.fetchone() if res2: @@ -207,18 +220,18 @@ class product_product(osv.osv): if type(context['location']) == type(1): location_ids = [context['location']] elif type(context['location']) in (type(''), type(u'')): - location_ids = self.pool.get('stock.location').search(cr, uid, [('name','ilike',context['location'])], context=context) + location_ids = location_obj.search(cr, uid, [('name','ilike',context['location'])], context=context) else: location_ids = context['location'] else: location_ids = [] - wids = self.pool.get('stock.warehouse').search(cr, uid, [], context=context) - for w in self.pool.get('stock.warehouse').browse(cr, uid, wids, context=context): + wids = warehouse_obj.search(cr, uid, [], context=context) + for w in warehouse_obj.browse(cr, uid, wids, context=context): location_ids.append(w.lot_stock_id.id) # build the list of ids of children of the location given by id if context.get('compute_child',True): - child_location_ids = self.pool.get('stock.location').search(cr, uid, [('location_id', 'child_of', location_ids)]) + child_location_ids = location_obj.search(cr, uid, [('location_id', 'child_of', location_ids)]) location_ids = child_location_ids or location_ids else: location_ids = location_ids @@ -334,6 +347,7 @@ class product_product(osv.osv): 'track_incoming': fields.boolean('Track Incoming Lots', help="Forces to specify a Production Lot for all moves containing this product and coming from a Supplier Location"), 'track_outgoing': fields.boolean('Track Outgoing Lots', help="Forces to specify a Production Lot for all moves containing this product and going to a Customer Location"), 'location_id': fields.dummy(string='Stock Location', relation='stock.location', type='many2one'), + 'warehouse_id': fields.dummy(string='Stock of Warehouse', relation='stock.warehouse', type='many2one'), 'valuation':fields.selection([('manual_periodic', 'Periodical (manual)'), ('real_time','Real Time (automated)'),], 'Inventory Valuation', help="If real-time valuation is enabled for a product, the system will automatically write journal entries corresponding to stock moves." \ diff --git a/addons/stock/product_view.xml b/addons/stock/product_view.xml index def92fe79eb..af660ab74d4 100644 --- a/addons/stock/product_view.xml +++ b/addons/stock/product_view.xml @@ -10,6 +10,7 @@ +