[ADD] configurable stock level

(lp:c2c-addons/6.1  rev 28.1.9)
This commit is contained in:
unknown
2012-04-04 13:20:48 +02:00
parent 7e31a4f5b6
commit 5fc2ecb473
7 changed files with 184 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
from openerp.addons.configurable_stock_level import product
from openerp.addons.configurable_stock_level import stock_level_configuration

View File

@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
{'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}

View File

@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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')}

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="view_normal_stock_active_qty_form">
<field name="name">product.normal.stock.active.qty.form.inherit.configurable</field>
<field name="model">product.product</field>
<field name="type">form</field>
<field name="inherit_id" ref="stock.view_normal_stock_property_form"/>
<field name="arch" type="xml">
<field name="virtual_available" position="after">
<newline/>
<field name="configurable_stock_level" />
</field>
</field>
</record>
</data>
</openerp>

View File

@@ -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
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 stock_level_configuration stock.level.configuration stock_manager model_stock_level_configuration stock.group_stock_manager 1 1 1 1

View File

@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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")}

View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="configuration_stock_level_view">
<field name="name">stock.level.configuration.form</field>
<field name="model">stock.level.configuration</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form>
<field name="stock_location_id" />
<field name="product_field" domain="[('model', 'in', ['product.product', 'product.tempalte'])]" />
</form>
</field>
</record>
<record model="ir.ui.view" id="configuration_stock_level_view_tree">
<field name="name">stock.level.configuration.tree</field>
<field name="model">stock.level.configuration</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree>
<field name="stock_location_id" />
<field name="product_field" domain="[('model', 'in', ['product.product', 'product.tempalte'])]" />
</tree>
</field>
</record>
<record id="action_configuration_stock_level" model="ir.actions.act_window">
<field name="name">Custom Stock Level configuration</field>
<field name="res_model">stock.level.configuration</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field eval="configuration_stock_level_view_tree" name="view_id"/>
</record>
<menuitem
name="Custom Stock Level configuration"
id="action_configuration_stock_level_menu"
parent="stock.menu_stock_inventory_control"
action="action_configuration_stock_level"
/>
</data>
</openerp>