[FIX] permission denied msgbox when creating stock.move in multicompany setting

lp bug: https://launchpad.net/bugs/1182111 fixed

bzr revid: alexandre.fayolle@camptocamp.com-20130521140631-k100itymc4qn0f2m
This commit is contained in:
Alexandre Fayolle 2013-05-21 16:06:31 +02:00
parent 39e99c1ce5
commit 46b8c95d99
2 changed files with 41 additions and 13 deletions

View File

@ -25,7 +25,7 @@ import time
from operator import itemgetter from operator import itemgetter
from itertools import groupby from itertools import groupby
from openerp.osv import fields, osv from openerp.osv import fields, osv, orm
from openerp.tools.translate import _ from openerp.tools.translate import _
from openerp import netsvc from openerp import netsvc
from openerp import tools from openerp import tools
@ -1700,7 +1700,11 @@ class stock_move(osv.osv):
elif picking_type == 'out': elif picking_type == 'out':
location_xml_id = 'stock_location_customers' location_xml_id = 'stock_location_customers'
if location_xml_id: if location_xml_id:
location_model, location_id = mod_obj.get_object_reference(cr, uid, 'stock', location_xml_id) try:
location_id = mod_obj.get_object(cr, uid, 'stock', location_xml_id).id
except (orm.except_orm, ValueError):
# likely the user does not have read access on the location
location_id = False
return location_id return location_id
def _default_location_source(self, cr, uid, context=None): def _default_location_source(self, cr, uid, context=None):
@ -1729,7 +1733,11 @@ class stock_move(osv.osv):
elif picking_type in ('out', 'internal'): elif picking_type in ('out', 'internal'):
location_xml_id = 'stock_location_stock' location_xml_id = 'stock_location_stock'
if location_xml_id: if location_xml_id:
location_model, location_id = mod_obj.get_object_reference(cr, uid, 'stock', location_xml_id) try:
location_id = mod_obj.get_object(cr, uid, 'stock', location_xml_id).id
except (orm.except_orm, ValueError):
# likely the user does not have read access on the location
location_id = False
return location_id return location_id
def _default_destination_address(self, cr, uid, context=None): def _default_destination_address(self, cr, uid, context=None):
@ -1947,9 +1955,17 @@ class stock_move(osv.osv):
elif type == 'out': elif type == 'out':
location_source_id = 'stock_location_stock' location_source_id = 'stock_location_stock'
location_dest_id = 'stock_location_customers' location_dest_id = 'stock_location_customers'
source_location = mod_obj.get_object_reference(cr, uid, 'stock', location_source_id) try:
dest_location = mod_obj.get_object_reference(cr, uid, 'stock', location_dest_id) source_location_id = mod_obj.get_object(cr, uid, 'stock', location_source_id).id
return {'value':{'location_id': source_location and source_location[1] or False, 'location_dest_id': dest_location and dest_location[1] or False}} except (orm.except_orm, ValueError):
# likely the user does not have read access on the location
source_location_id = False
try:
dest_location_id = mod_obj.get_object(cr, uid, 'stock', location_dest_id).id
except (orm.except_orm, ValueError):
# likely the user does not have read access on the location
dest_location_id = False
return {'value':{'location_id': source_location_id, 'location_dest_id': dest_location_id}}
def onchange_date(self, cr, uid, ids, date, date_expected, context=None): def onchange_date(self, cr, uid, ids, date, date_expected, context=None):
""" On change of Scheduled Date gives a Move date. """ On change of Scheduled Date gives a Move date.
@ -2883,8 +2899,12 @@ class stock_inventory_line(osv.osv):
} }
def _default_stock_location(self, cr, uid, context=None): def _default_stock_location(self, cr, uid, context=None):
stock_location = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_stock') try:
return stock_location.id stock_location_id = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_stock').id
except (ValueError, orm.except_orm):
# likely the user does not have read access on the location
stock_location_id = False
return stock_location_id
_defaults = { _defaults = {
'location_id': _default_stock_location 'location_id': _default_stock_location
@ -2923,12 +2943,20 @@ class stock_warehouse(osv.osv):
} }
def _default_lot_input_stock_id(self, cr, uid, context=None): 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') try:
return lot_input_stock.id lot_input_stock_id = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_stock').id
except (ValueError, orm.except_orm):
# likely the user does not have read access on the location
lot_input_stock_id = False
return lot_input_stock_id
def _default_lot_output_id(self, cr, uid, context=None): 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') try:
return lot_output.id lot_output_id = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_output').id
except (ValueError, orm.except_orm):
# likely the user does not have read access on the location
lot_output_id = False
return lot_output_id
_defaults = { _defaults = {
'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.inventory', context=c), 'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.inventory', context=c),

View File

@ -28,7 +28,7 @@ class stock_fill_inventory(osv.osv_memory):
def _default_location(self, cr, uid, ids, context=None): def _default_location(self, cr, uid, ids, context=None):
try: try:
loc_model, location_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'stock', 'stock_location_stock') location_id = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_stock').id
except ValueError, e: except ValueError, e:
return False return False
return location_id or False return location_id or False