diff --git a/addons/mrp/tests/__init__.py b/addons/mrp/tests/__init__.py new file mode 100644 index 00000000000..39ebd5e451f --- /dev/null +++ b/addons/mrp/tests/__init__.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Business Applications +# Copyright (c) 2012-TODAY OpenERP S.A. +# +# 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 test_multicompany + +checks = [ + test_multicompany, +] + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/mrp/tests/test_multicompany.py b/addons/mrp/tests/test_multicompany.py new file mode 100644 index 00000000000..78986bd41b2 --- /dev/null +++ b/addons/mrp/tests/test_multicompany.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Business Applications +# Copyright (c) 2012-TODAY OpenERP S.A. +# +# 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.tests import common + + +class TestMrpMulticompany(common.TransactionCase): + + def setUp(self): + super(TestMrpMulticompany, self).setUp() + cr, uid = self.cr, self.uid + + # Usefull models + self.ir_model_data = self.registry('ir.model.data') + self.res_users = self.registry('res.users') + self.stock_location = self.registry('stock.location') + + model, self.multicompany_user_id = self.ir_model_data.get_object_reference(cr, uid, 'stock', 'multicompany_user') + + + def test_00_multicompany_user(self): + """check no error on getting default mrp.production values in multicompany setting""" + cr, uid, context = self.cr, self.multicompany_user_id, {} + fields = ['location_src_id', 'location_dest_id'] + defaults = self.stock_location.default_get(cr, uid, ['location_id', 'location_dest_id', 'type'], context) + for field in fields: + print field, uid, defaults + if defaults.get(field): + try: + self.stock_location.check_access_rule(cr, uid, [defaults[field]], 'read', context) + except Exception, exc: + assert False, "unreadable location %s: %s" % (field, exc) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 23edf443760..1f89cc3dc6a 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -2945,12 +2945,22 @@ class stock_warehouse(osv.osv): } def _default_lot_input_stock_id(self, cr, uid, context=None): - lot_input_stock = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_stock') - return lot_input_stock.id + try: + lot_input_stock_model, lot_input_stock_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'stock', 'stock_location_stock') + self.pool.get('stock.location').check_access_rule(cr, uid, [lot_input_stock_id], 'read', context=context) + except (ValueError, orm.except_orm): + # the user does not have read access on the location or it does not exists + lot_input_stock_id = False + return lot_input_stock_id def _default_lot_output_id(self, cr, uid, context=None): - lot_output = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_output') - return lot_output.id + try: + lot_input_stock_model, lot_input_stock_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'stock', 'stock_location_output') + self.pool.get('stock.location').check_access_rule(cr, uid, [lot_input_stock_id], 'read', context=context) + except (ValueError, orm.except_orm): + # the user does not have read access on the location or it does not exists + lot_output_id = False + return lot_output_id _defaults = { 'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.inventory', context=c), diff --git a/addons/stock/stock_demo.xml b/addons/stock/stock_demo.xml index eb5a6c46380..94844ee8904 100644 --- a/addons/stock/stock_demo.xml +++ b/addons/stock/stock_demo.xml @@ -287,6 +287,16 @@ + + multicomp + multicomp + multicomp + + + + + + diff --git a/addons/stock/tests/__init__.py b/addons/stock/tests/__init__.py new file mode 100644 index 00000000000..39ebd5e451f --- /dev/null +++ b/addons/stock/tests/__init__.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Business Applications +# Copyright (c) 2012-TODAY OpenERP S.A. +# +# 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 test_multicompany + +checks = [ + test_multicompany, +] + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/stock/tests/test_multicompany.py b/addons/stock/tests/test_multicompany.py new file mode 100644 index 00000000000..d30e7d0ef2b --- /dev/null +++ b/addons/stock/tests/test_multicompany.py @@ -0,0 +1,92 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Business Applications +# Copyright (c) 2012-TODAY OpenERP S.A. +# +# 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.tests import common + + +class TestStockMulticompany(common.TransactionCase): + + def setUp(self): + super(TestStockMulticompany, self).setUp() + cr, uid = self.cr, self.uid + + # Usefull models + self.ir_model_data = self.registry('ir.model.data') + self.res_users = self.registry('res.users') + self.stock_location = self.registry('stock.location') + self.stock_move = self.registry('stock.move') + self.stock_fill_inventory = self.registry('stock.fill.inventory') + self.stock_warehouse = self.registry('stock.warehouse') + + model, self.multicompany_user_id = self.ir_model_data.get_object_reference(cr, uid, 'stock', 'multicompany_user') + + def test_00_multicompany_default_stock_move(self): + """check no error on getting default stock.move values in multicompany setting""" + cr, uid, context = self.cr, self.multicompany_user_id, {} + fields = ['location_id', 'location_dest_id'] + for type in ('in', 'internal', 'out'): + context['picking_type'] = type + defaults = self.stock_move.default_get(cr, uid, ['location_id', 'location_dest_id', 'type'], context) + for field in fields: + if defaults.get(field): + try: + self.stock_location.check_access_rule(cr, uid, [defaults[field]], 'read', context) + except Exception, exc: + assert False, "unreadable location %s: %s" % (field, exc) + self.assertEqual(defaults['type'], type, "wrong move type") + + + def test_10_multicompany_onchange_move_type(self): + """check onchange_move_type does not return unreadable in multicompany setting""" + cr, uid, context = self.cr, self.multicompany_user_id, {} + fields = ['location_id', 'location_dest_id'] + for type in ('in', 'internal', 'out'): + result = self.stock_move.onchange_move_type(cr, uid, [], type, context)['value'] + for field in fields: + if result.get(field): + try: + self.stock_location.check_access_rule(cr, uid, [result[field]], 'read', context) + except Exception, exc: + assert False, "unreadable location %s: %s" % (field, exc) + + + def test_20_multicompany_default_stock_fill_inventory(self): + """check default location readability for stock_fill_inventory in multicompany setting""" + cr, uid, context = self.cr, self.multicompany_user_id, {} + defaults = self.stock_fill_inventory.default_get(cr, uid, ['location_id'], context) + if defaults.get('location_id'): + try: + self.stock_location.check_access_rule(cr, uid, [defaults['location_id']], 'read', context) + except Exception, exc: + assert False, "unreadable source location: %s" % exc + + + def test_30_multicompany_default_warehouse_location(self): + """check default locations for warehouse in multicompany setting""" + cr, uid, context = self.cr, self.multicompany_user_id, {} + fields = ['lot_input_id', 'lot_stock_id', 'lot_output_id'] + defaults = self.stock_warehouse.default_get(cr, uid, fields, context) + for field in fields: + if defaults.get(field): + try: + self.stock_location.check_access_rule(cr, uid, [defaults[field]], 'read', context) + except Exception, exc: + assert False, "unreadable default %s: %s" % (field, exc) diff --git a/addons/stock/wizard/stock_fill_inventory.py b/addons/stock/wizard/stock_fill_inventory.py index 237033bb7b0..07dcb3965d7 100644 --- a/addons/stock/wizard/stock_fill_inventory.py +++ b/addons/stock/wizard/stock_fill_inventory.py @@ -19,7 +19,7 @@ # ############################################################################## -from openerp.osv import fields, osv +from openerp.osv import fields, osv, orm from openerp.tools.translate import _ class stock_fill_inventory(osv.osv_memory): @@ -28,8 +28,10 @@ class stock_fill_inventory(osv.osv_memory): def _default_location(self, cr, uid, ids, context=None): try: - loc_model, location_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'stock', 'stock_location_stock') - except ValueError, e: + location = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_stock') + location.check_access_rule('read', context=context) + location_id = location.id + except (ValueError, orm.except_orm), e: return False return location_id or False