From dbbff25c254656d0d50a3d7d41c4abb98deb2f44 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 15 Sep 2014 15:23:16 +0200 Subject: [PATCH] Add stock_location_search_stock stock_real and stock_virtual on stock.location can be searched --- stock_location_search_stock/__init__.py | 22 ++++++ stock_location_search_stock/__openerp__.py | 52 ++++++++++++++ stock_location_search_stock/stock_location.py | 68 +++++++++++++++++++ .../stock_location_view.xml | 20 ++++++ 4 files changed, 162 insertions(+) create mode 100644 stock_location_search_stock/__init__.py create mode 100644 stock_location_search_stock/__openerp__.py create mode 100644 stock_location_search_stock/stock_location.py create mode 100644 stock_location_search_stock/stock_location_view.xml diff --git a/stock_location_search_stock/__init__.py b/stock_location_search_stock/__init__.py new file mode 100644 index 000000000..78b64f475 --- /dev/null +++ b/stock_location_search_stock/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Guewen Baconnier +# Copyright 2014 Camptocamp SA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from . import stock_location diff --git a/stock_location_search_stock/__openerp__.py b/stock_location_search_stock/__openerp__.py new file mode 100644 index 000000000..b7b1d66a8 --- /dev/null +++ b/stock_location_search_stock/__openerp__.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Guewen Baconnier +# Copyright 2014 Camptocamp SA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +{'name': 'Stock Location Search Stock Quantities', + 'version': '1.0', + 'author': 'Camptocamp', + 'maintainer': 'Camptocamp', + 'license': 'AGPL-3', + 'category': 'Warehouse Management', + 'depends': ['stock', + ], + 'description': """ +Stock Location Search Stock Quantities +====================================== + +Add search functions on Products' Real and Virtual Stock on Stock Locations. + +The "Stock by Location" view that is accessed from a product shows the +list of locations, each one with the Real and Virtual Stock for the +product. However, there is no way to filter out the locations which +doesn't contain the product so the view is cluttered with a lot of +lines with a 0.0 quantity. This module adds search functions on the quantity +fields. + +Also, by default, a filter hides the locations without quantity at all. + + """, + 'website': 'http://www.camptocamp.com', + 'data': ['stock_location_view.xml', + ], + 'test': [], + 'installable': True, + 'auto_install': False, +} diff --git a/stock_location_search_stock/stock_location.py b/stock_location_search_stock/stock_location.py new file mode 100644 index 000000000..1cfac58de --- /dev/null +++ b/stock_location_search_stock/stock_location.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Guewen Baconnier +# Copyright 2014 Camptocamp SA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +import operator +from openerp.osv import orm, fields + + +class StockLocation(orm.Model): + _inherit = 'stock.location' + + def _product_value(self, cr, uid, ids, field_names, arg, context=None): + _super = super(StockLocation, self) + return _super._product_value(cr, uid, ids, field_names, arg, + context=context) + + def _stock_search(self, cr, uid, obj, name, args, context=None): + if not len(args): + return [] + ops = {'<': operator.lt, + '>': operator.gt, + '=': operator.eq, + '!=': operator.ne, + '<=': operator.le, + '>=': operator.ge, + } + location_ids = set() + for field, symbol, value in args: + if symbol not in ops: + raise orm.except_orm( + _('Error'), + _('Operator %s not supported in ' + 'searches for Stock on Locations' % symbol)) + loc_ids = self.search(cr, uid, [], context=context) + locations = self.read(cr, uid, loc_ids, [name], + context=context) + for location in locations: + if ops[symbol](location[name], value): + location_ids.add(location['id']) + return [('id', 'in', tuple(location_ids))] + + _columns = { + 'stock_real': fields.function(_product_value, type='float', + fnct_search=_stock_search, + string='Real Stock', + multi="stock"), + 'stock_virtual': fields.function(_product_value, type='float', + fnct_search=_stock_search, + string='Virtual Stock', + multi="stock"), + } diff --git a/stock_location_search_stock/stock_location_view.xml b/stock_location_search_stock/stock_location_view.xml new file mode 100644 index 000000000..1370aaffa --- /dev/null +++ b/stock_location_search_stock/stock_location_view.xml @@ -0,0 +1,20 @@ + + + + + stock.location.search + stock.location + + + + + + + + + + + {'product_id': active_id, 'search_default_has_stock_real': 1} + + +