mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
Add stock_location_search_stock
stock_real and stock_virtual on stock.location can be searched
This commit is contained in:
22
stock_location_search_stock/__init__.py
Normal file
22
stock_location_search_stock/__init__.py
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from . import stock_location
|
||||
52
stock_location_search_stock/__openerp__.py
Normal file
52
stock_location_search_stock/__openerp__.py
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
{'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,
|
||||
}
|
||||
68
stock_location_search_stock/stock_location.py
Normal file
68
stock_location_search_stock/stock_location.py
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
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"),
|
||||
}
|
||||
20
stock_location_search_stock/stock_location_view.xml
Normal file
20
stock_location_search_stock/stock_location_view.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data noupdate="0">
|
||||
<record id="view_location_search" model="ir.ui.view">
|
||||
<field name="name">stock.location.search</field>
|
||||
<field name="model">stock.location</field>
|
||||
<field name="inherit_id" ref="stock.view_location_search"/>
|
||||
<field name="arch" type="xml">
|
||||
<filter name="supplier" position="after">
|
||||
<separator/>
|
||||
<filter name="has_stock_real" string="Has Real Stock" domain="[('stock_real', '!=', 0.0)]" help="The location contains the product"/>
|
||||
</filter>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="stock.act_stock_product_location_open" model="ir.actions.act_window">
|
||||
<field name="context">{'product_id': active_id, 'search_default_has_stock_real': 1}</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
||||
Reference in New Issue
Block a user