diff --git a/configurable_stock_level/__init__.py b/configurable_stock_level/__init__.py
new file mode 100644
index 000000000..cd2ed783a
--- /dev/null
+++ b/configurable_stock_level/__init__.py
@@ -0,0 +1,2 @@
+from openerp.addons.configurable_stock_level import product
+from openerp.addons.configurable_stock_level import stock_level_configuration
diff --git a/configurable_stock_level/__openerp__.py b/configurable_stock_level/__openerp__.py
new file mode 100644
index 000000000..ce4a71610
--- /dev/null
+++ b/configurable_stock_level/__openerp__.py
@@ -0,0 +1,40 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# Author: Nicolas Bessi
+# Copyright 2012 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' : 'name',
+ 'version' : '0.1',
+ 'author' : 'Camptocamp',
+ 'maintainer': 'Camptocamp',
+ 'category': 'Warehouse',
+ 'complexity': "normal", # easy, normal, expert
+ 'depends' : ['stock', 'product'],
+ 'description': """Allows to set a stock level composed by
+ a configuration using the sum of stock location + product fields""",
+ 'website': 'http://www.camptocamp.com',
+ 'init_xml': [],
+ 'update_xml': ['stock_level_configuration_view.xml',
+ 'product_view.xml',
+ 'security/ir.model.access.csv'],
+ 'demo_xml': [],
+ 'tests': [],
+ 'installable': True,
+ 'auto_install': False,
+ 'license': 'AGPL-3',
+ 'application': True}
diff --git a/configurable_stock_level/product.py b/configurable_stock_level/product.py
new file mode 100644
index 000000000..598c9bc00
--- /dev/null
+++ b/configurable_stock_level/product.py
@@ -0,0 +1,55 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# Author: Nicolas Bessi
+# Copyright 2012 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 openerp.osv.orm import Model, fields
+import decimal_precision as dp
+
+class product_product(Model):
+ _inherit = "product.product"
+
+ def _compute_configurable_level(self, cursor, uid, pids, field_name, args, context=None):
+ """We compute a custom stock level"""
+ # we do not override _product_available once agin to avoid MRO troubles
+ conf_obj = self.pool.get('stock.level.configuration')
+ prod_obj = self.pool.get('product.product')
+ conf_list = []
+ conf_ids = conf_obj.search(cursor, uid, [])
+ for conf in conf_obj.browse(cursor, uid, conf_ids):
+ conf_list.append((conf.stock_location_id.id, conf.product_field.name))
+ if not isinstance(pids, list):
+ pids = [pids]
+ res = dict.fromkeys(pids, 0.0)
+ for conf in conf_list:
+ local_context = context.copy()
+ local_context['location'] = [conf[0]]
+ interm = prod_obj._product_available(cursor, uid, pids, field_names=[conf[1]], arg=False, context=local_context)
+ for key, val in interm.items():
+ res.setdefault(key, 0.0) # this should not be usefull but we never know
+ res[key] += val.get(conf[1], 0.0)
+ return res
+
+
+ _columns = {'configurable_stock_level': fields.function(_compute_configurable_level,
+ type='float',
+ digits_compute=dp.get_precision('Product UoM'),
+ string='Custom level')}
+
+
+
diff --git a/configurable_stock_level/product_view.xml b/configurable_stock_level/product_view.xml
new file mode 100644
index 000000000..e325c4d34
--- /dev/null
+++ b/configurable_stock_level/product_view.xml
@@ -0,0 +1,17 @@
+
+
+
+
+ product.normal.stock.active.qty.form.inherit.configurable
+ product.product
+ form
+
+
+
+
+
+
+
+
+
+
diff --git a/configurable_stock_level/security/ir.model.access.csv b/configurable_stock_level/security/ir.model.access.csv
new file mode 100644
index 000000000..f30d75b3a
--- /dev/null
+++ b/configurable_stock_level/security/ir.model.access.csv
@@ -0,0 +1,2 @@
+"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
+stock_level_configuration,stock.level.configuration stock_manager,model_stock_level_configuration,stock.group_stock_manager,1,1,1,1
diff --git a/configurable_stock_level/stock_level_configuration.py b/configurable_stock_level/stock_level_configuration.py
new file mode 100644
index 000000000..437a30170
--- /dev/null
+++ b/configurable_stock_level/stock_level_configuration.py
@@ -0,0 +1,27 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# Author: Nicolas Bessi
+# Copyright 2012 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 openerp.osv.orm import Model, fields
+
+class StockLevelConfig(Model):
+ _name ='stock.level.configuration'
+ _columns = {'stock_location_id': fields.many2one('stock.location', 'Location to use', required=True),
+ 'product_field': fields.many2one('ir.model.fields', 'Fields to use', required=True,
+ help="Field of product form to sum")}
diff --git a/configurable_stock_level/stock_level_configuration_view.xml b/configurable_stock_level/stock_level_configuration_view.xml
new file mode 100644
index 000000000..dc92ebb5c
--- /dev/null
+++ b/configurable_stock_level/stock_level_configuration_view.xml
@@ -0,0 +1,41 @@
+
+
+
+
+ stock.level.configuration.form
+ stock.level.configuration
+ form
+
+
+
+
+
+ stock.level.configuration.tree
+ stock.level.configuration
+ tree
+
+
+
+
+
+
+
+
+ Custom Stock Level configuration
+ stock.level.configuration
+ form
+ tree,form
+
+
+
+
+
+