diff --git a/addons/mrp/__openerp__.py b/addons/mrp/__openerp__.py
index 6e025ae2d90..2fde404bf12 100644
--- a/addons/mrp/__openerp__.py
+++ b/addons/mrp/__openerp__.py
@@ -77,6 +77,7 @@ Dashboard / Reports for MRP will include:
#TODO: This yml tests are needed to be completely reviewed again because the product wood panel is removed in product demo as it does not suit for new demo context of computer and consultant company
# so the ymls are too complex to change at this stage
'test': [
+ 'test/multicompany.yml',
# 'test/order_demo.yml',
# 'test/order_process.yml',
# 'test/cancel_order.yml',
diff --git a/addons/mrp/test/multicompany.yml b/addons/mrp/test/multicompany.yml
new file mode 100644
index 00000000000..7ed9cf86023
--- /dev/null
+++ b/addons/mrp/test/multicompany.yml
@@ -0,0 +1,20 @@
+-
+ Set the current user as multicompany user
+-
+ !context
+ uid: 'stock.multicompany_user'
+
+-
+ check no error on getting default mrp.production values in multicompany setting
+-
+ !python {model: mrp.production}: |
+ location_obj = self.pool.get('stock.location')
+ fields = ['location_src_id', 'location_dest_id']
+ defaults = self.default_get(cr, uid, ['location_id', 'location_dest_id', 'type'], context)
+ log('got defaults: %s', defaults)
+ for field in fields:
+ if defaults.get(field):
+ try:
+ location_obj.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/__openerp__.py b/addons/stock/__openerp__.py
index b3d7e30f1ce..db7117ce2b3 100644
--- a/addons/stock/__openerp__.py
+++ b/addons/stock/__openerp__.py
@@ -94,6 +94,7 @@ Dashboard / Reports for Warehouse Management will include:
# 'test/opening_stock.yml',
# 'test/shipment.yml',
# 'test/stock_report.yml',
+ 'test/multicompany.yml'
],
'installable': True,
'application': True,
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/test/multicompany.yml b/addons/stock/test/multicompany.yml
new file mode 100644
index 00000000000..2c0353aa71d
--- /dev/null
+++ b/addons/stock/test/multicompany.yml
@@ -0,0 +1,68 @@
+
+-
+ Set the current user as multicompany user
+-
+ !context
+ uid: 'stock.multicompany_user'
+
+-
+ check no error on getting default stock.move values in multicompany setting
+-
+ !python {model: stock.move}: |
+ location_obj = self.pool.get('stock.location')
+ fields = ['location_id', 'location_dest_id']
+ for type in ('in', 'internal', 'out'):
+ context['picking_type'] = type
+ defaults = self.default_get(cr, uid, ['location_id', 'location_dest_id', 'type'], context)
+ log('type: %s got defaults: %s', type, defaults)
+ for field in fields:
+ if defaults.get(field):
+ try:
+ location_obj.check_access_rule(cr, uid, [defaults[field]], 'read', context)
+ except Exception, exc:
+ assert False, "unreadable location %s: %s" % (field, exc)
+ assert defaults['type'] == type, "wrong move type"
+
+-
+ check onchange_move_type does not return unreadable in multicompany setting
+-
+ !python {model: stock.move}: |
+ location_obj = self.pool.get('stock.location')
+ fields = ['location_id', 'location_dest_id']
+ for type in ('in', 'internal', 'out'):
+ result = self.onchange_move_type(cr, uid, [], type, context)['value']
+ log('type: %s got: %s', type, result)
+ for field in fields:
+ if result.get(field):
+ try:
+ location_obj.check_access_rule(cr, uid, [result[field]], 'read', context)
+ except Exception, exc:
+ assert False, "unreadable location %s: %s" % (field, exc)
+
+-
+ check default location readability for stock_fill_inventory in multicompany setting
+-
+ !python {model: stock.fill.inventory}: |
+ location_obj = self.pool.get('stock.location')
+ defaults = self.default_get(cr, uid, ['location_id'], context)
+ log('got defaults: %s', defaults)
+ if defaults.get('location_id'):
+ try:
+ location_obj.check_access_rule(cr, uid, [defaults['location_id']], 'read', context)
+ except Exception, exc:
+ assert False, "unreadable source location: %s" % exc
+
+-
+ check default locations for warehouse in multicompany setting
+-
+ !python {model: stock.warehouse}: |
+ location_obj = self.pool.get('stock.location')
+ fields = ['lot_input_id', 'lot_stock_id', 'lot_output_id']
+ defaults = self.default_get(cr, uid, fields, context)
+ log('got defaults: %s', defaults)
+ for field in fields:
+ if defaults.get(field):
+ try:
+ location_obj.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