From 46b8c95d9993f70de73e6e5f91911f1b012e8136 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Tue, 21 May 2013 16:06:31 +0200 Subject: [PATCH 01/20] [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 --- addons/stock/stock.py | 52 ++++++++++++++++----- addons/stock/wizard/stock_fill_inventory.py | 2 +- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index fca3d9ff073..93b05cd0b40 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -25,7 +25,7 @@ import time from operator import itemgetter from itertools import groupby -from openerp.osv import fields, osv +from openerp.osv import fields, osv, orm from openerp.tools.translate import _ from openerp import netsvc from openerp import tools @@ -1700,7 +1700,11 @@ class stock_move(osv.osv): elif picking_type == 'out': location_xml_id = 'stock_location_customers' 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 def _default_location_source(self, cr, uid, context=None): @@ -1729,7 +1733,11 @@ class stock_move(osv.osv): elif picking_type in ('out', 'internal'): location_xml_id = 'stock_location_stock' 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 def _default_destination_address(self, cr, uid, context=None): @@ -1947,9 +1955,17 @@ class stock_move(osv.osv): elif type == 'out': location_source_id = 'stock_location_stock' location_dest_id = 'stock_location_customers' - source_location = mod_obj.get_object_reference(cr, uid, 'stock', location_source_id) - dest_location = mod_obj.get_object_reference(cr, uid, 'stock', location_dest_id) - return {'value':{'location_id': source_location and source_location[1] or False, 'location_dest_id': dest_location and dest_location[1] or False}} + try: + source_location_id = mod_obj.get_object(cr, uid, 'stock', location_source_id).id + 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): """ 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): - stock_location = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_stock') - return stock_location.id + try: + 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 = { '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): - 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_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): - lot_output = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_output') - return lot_output.id + try: + 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 = { '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/wizard/stock_fill_inventory.py b/addons/stock/wizard/stock_fill_inventory.py index 237033bb7b0..dc44316b5d7 100644 --- a/addons/stock/wizard/stock_fill_inventory.py +++ b/addons/stock/wizard/stock_fill_inventory.py @@ -28,7 +28,7 @@ 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') + location_id = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_stock').id except ValueError, e: return False return location_id or False From 68b3155d2064413883b8db62ab6b77ce096dba21 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Tue, 21 May 2013 16:44:18 +0200 Subject: [PATCH 02/20] [TEST] add test for issue 1182111 bzr revid: alexandre.fayolle@camptocamp.com-20130521144418-x8pqpk632g3ew87j --- addons/stock/__openerp__.py | 1 + addons/stock/stock_demo.xml | 10 ++++++++++ addons/stock/test/multicompany.yml | 14 ++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 addons/stock/test/multicompany.yml 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_demo.xml b/addons/stock/stock_demo.xml index eb5a6c46380..d770ecc90fa 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..66e88d98ff1 --- /dev/null +++ b/addons/stock/test/multicompany.yml @@ -0,0 +1,14 @@ + +- + Set the current user as multicompany user +- + !context + 'uid': 'stock.multicompany_user' +- + check no error on getting default stock.move values for internal move +- + !python {model: stock.move}: + context['picking_type'] = 'internal' + defaults = self.default_get(cr, uid, ['location_id', 'location_dest_id', 'type'], context) + assert defaults == {'location_id': False, 'location_dest_id': False, 'type': 'internal'} + From af6335c44af18ca1e9a56b7e27278aa9b45ddf9f Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Tue, 21 May 2013 17:11:01 +0200 Subject: [PATCH 03/20] [FIX] fix stock demo data used by new test bzr revid: alexandre.fayolle@camptocamp.com-20130521151101-fjhr2q6t7g0jf9au --- addons/stock/stock_demo.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/stock/stock_demo.xml b/addons/stock/stock_demo.xml index d770ecc90fa..94844ee8904 100644 --- a/addons/stock/stock_demo.xml +++ b/addons/stock/stock_demo.xml @@ -291,8 +291,8 @@ multicomp multicomp multicomp - - + + From 92b2d800728d55690b7344d45656ad0227d0dbdc Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Wed, 22 May 2013 08:25:30 +0200 Subject: [PATCH 04/20] [FIX] yaml syntax error bzr revid: alexandre.fayolle@camptocamp.com-20130522062530-jqya3wbwka91ydor --- addons/stock/test/multicompany.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/stock/test/multicompany.yml b/addons/stock/test/multicompany.yml index 66e88d98ff1..e7918647db4 100644 --- a/addons/stock/test/multicompany.yml +++ b/addons/stock/test/multicompany.yml @@ -7,7 +7,7 @@ - check no error on getting default stock.move values for internal move - - !python {model: stock.move}: + !python {model: stock.move}: | context['picking_type'] = 'internal' defaults = self.default_get(cr, uid, ['location_id', 'location_dest_id', 'type'], context) assert defaults == {'location_id': False, 'location_dest_id': False, 'type': 'internal'} From 51a96dc5cd84d852e56adaf9dccd3ab00a8414b1 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Wed, 22 May 2013 08:57:22 +0200 Subject: [PATCH 05/20] [TEST] enhance error message bzr revid: alexandre.fayolle@camptocamp.com-20130522065722-vuxha3lht56as98o --- addons/stock/test/multicompany.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/stock/test/multicompany.yml b/addons/stock/test/multicompany.yml index e7918647db4..35df6c67b83 100644 --- a/addons/stock/test/multicompany.yml +++ b/addons/stock/test/multicompany.yml @@ -10,5 +10,5 @@ !python {model: stock.move}: | context['picking_type'] = 'internal' defaults = self.default_get(cr, uid, ['location_id', 'location_dest_id', 'type'], context) - assert defaults == {'location_id': False, 'location_dest_id': False, 'type': 'internal'} + assert defaults == {'location_id': False, 'location_dest_id': False, 'type': 'internal'}, "did not get the correct default (got: %s)" % defaults From 0e3d497beb923af1063ffc93ae8dc113ef735a16 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Wed, 22 May 2013 13:06:08 +0200 Subject: [PATCH 06/20] enhanced tests bzr revid: alexandre.fayolle@camptocamp.com-20130522110608-acb2odz0tksm6sc2 --- addons/stock/test/multicompany.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/addons/stock/test/multicompany.yml b/addons/stock/test/multicompany.yml index 35df6c67b83..962bb825dac 100644 --- a/addons/stock/test/multicompany.yml +++ b/addons/stock/test/multicompany.yml @@ -3,12 +3,21 @@ Set the current user as multicompany user - !context - 'uid': 'stock.multicompany_user' + uid: 'stock.multicompany_user' - check no error on getting default stock.move values for internal move - !python {model: stock.move}: | + multicomp_user = ref('stock.multicompany_user') context['picking_type'] = 'internal' + log('multicompany user: %s, uid: %s', multicomp_user, uid) + log('current context: %s', context) + defaults = self.default_get(cr, multicomp_user, ['location_id', 'location_dest_id', 'type'], context) + assertion_msg = "did not get the correct default (got: %s)" % defaults + log('got defaults: %s', defaults) + assert defaults == {'location_id': False, 'location_dest_id': False, 'type': 'internal'}, assertion_msg defaults = self.default_get(cr, uid, ['location_id', 'location_dest_id', 'type'], context) - assert defaults == {'location_id': False, 'location_dest_id': False, 'type': 'internal'}, "did not get the correct default (got: %s)" % defaults + assertion_msg = "did not get the correct default with uid %s (got: %s)" % (uid, defaults) + log('got defaults: %s', defaults) + assert defaults == {'location_id': False, 'location_dest_id': False, 'type': 'internal'}, assertion_msg From 1658325f392ba60bd58b486aaebcda1f5765b405 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Wed, 22 May 2013 17:12:16 +0200 Subject: [PATCH 07/20] [FIX] actually fix lp:118211 by adding an explicit call to check_access_rule bzr revid: alexandre.fayolle@camptocamp.com-20130522151216-6cz0kb6abwwr5zsv --- addons/mrp/mrp.py | 18 ++++++++++--- addons/stock/stock.py | 28 +++++++++++++++------ addons/stock/wizard/stock_fill_inventory.py | 4 ++- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 44fbaafbcfe..77e3dd4965a 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -409,12 +409,22 @@ class mrp_production(osv.osv): return result def _src_id_default(self, cr, uid, ids, context=None): - src_location_id = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_stock', context=context) - return src_location_id.id + try: + src_location = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_stock', context=context) + src_location.check_access_rule('read', context=context) + except (orm.except_orm, ValueError): + # no read access + return False + return src_location.id def _dest_id_default(self, cr, uid, ids, context=None): - dest_location_id = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_stock', context=context) - return dest_location_id.id + try: + dest_location = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_stock', context=context) + dest_location.check_access_rule('read', context=context) + except (orm.except_orm, ValueError): + # no read access + return False + return dest_location.id _columns = { 'name': fields.char('Reference', size=64, required=True, readonly=True, states={'draft': [('readonly', False)]}), diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 93b05cd0b40..172d8bd9c27 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1701,7 +1701,9 @@ class stock_move(osv.osv): location_xml_id = 'stock_location_customers' if location_xml_id: try: - location_id = mod_obj.get_object(cr, uid, 'stock', location_xml_id).id + location = mod_obj.get_object(cr, uid, 'stock', location_xml_id, context=context) + location.check_access_rule('read', context=context) + location_id = location.id except (orm.except_orm, ValueError): # likely the user does not have read access on the location location_id = False @@ -1734,7 +1736,9 @@ class stock_move(osv.osv): location_xml_id = 'stock_location_stock' if location_xml_id: try: - location_id = mod_obj.get_object(cr, uid, 'stock', location_xml_id).id + location = mod_obj.get_object(cr, uid, 'stock', location_xml_id) + location.check_access_rule('read', context=context) + location_id = location.id except (orm.except_orm, ValueError): # likely the user does not have read access on the location location_id = False @@ -1956,12 +1960,16 @@ class stock_move(osv.osv): location_source_id = 'stock_location_stock' location_dest_id = 'stock_location_customers' try: - source_location_id = mod_obj.get_object(cr, uid, 'stock', location_source_id).id + location = mod_obj.get_object(cr, uid, 'stock', location_source_id) + location.check_access_rule('read', context=context) + source_location_id = location.id 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 + location = mod_obj.get_object(cr, uid, 'stock', location_dest_id) + location.check_access_rule('read', context=context) + dest_location_id = location.id except (orm.except_orm, ValueError): # likely the user does not have read access on the location dest_location_id = False @@ -2900,7 +2908,9 @@ class stock_inventory_line(osv.osv): def _default_stock_location(self, cr, uid, context=None): try: - stock_location_id = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_stock').id + location = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_stock') + location.check_access_rule('read', context=context) + stock_location_id = location.id except (ValueError, orm.except_orm): # likely the user does not have read access on the location stock_location_id = False @@ -2944,7 +2954,9 @@ class stock_warehouse(osv.osv): def _default_lot_input_stock_id(self, cr, uid, context=None): try: - lot_input_stock_id = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_stock').id + lot_input_stock = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_stock') + lot_input_stock.check_access_rule('read', context=context) + lot_input_stock_id = lot_input_stock.id except (ValueError, orm.except_orm): # likely the user does not have read access on the location lot_input_stock_id = False @@ -2952,7 +2964,9 @@ class stock_warehouse(osv.osv): def _default_lot_output_id(self, cr, uid, context=None): try: - lot_output_id = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_output').id + lot_output = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_output') + lot_output.check_access_rule('read', context=context) + lot_output_id = lot_output.id except (ValueError, orm.except_orm): # likely the user does not have read access on the location lot_output_id = False diff --git a/addons/stock/wizard/stock_fill_inventory.py b/addons/stock/wizard/stock_fill_inventory.py index dc44316b5d7..d0062c82538 100644 --- a/addons/stock/wizard/stock_fill_inventory.py +++ b/addons/stock/wizard/stock_fill_inventory.py @@ -28,7 +28,9 @@ class stock_fill_inventory(osv.osv_memory): def _default_location(self, cr, uid, ids, context=None): try: - location_id = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_stock').id + 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, e: return False return location_id or False From 486116588f04251d724a8fd2aa4938165f8a262b Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Wed, 22 May 2013 17:32:03 +0200 Subject: [PATCH 08/20] [TEST] add new tests and refactor bzr revid: alexandre.fayolle@camptocamp.com-20130522153203-wp45pyicciktg8m8 --- addons/stock/test/multicompany.yml | 55 +++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/addons/stock/test/multicompany.yml b/addons/stock/test/multicompany.yml index 962bb825dac..8c5df8fe5c2 100644 --- a/addons/stock/test/multicompany.yml +++ b/addons/stock/test/multicompany.yml @@ -4,20 +4,49 @@ - !context uid: 'stock.multicompany_user' + - - check no error on getting default stock.move values for internal move + check no error on getting default stock.move values in multicompany setting - !python {model: stock.move}: | - multicomp_user = ref('stock.multicompany_user') - context['picking_type'] = 'internal' - log('multicompany user: %s, uid: %s', multicomp_user, uid) - log('current context: %s', context) - defaults = self.default_get(cr, multicomp_user, ['location_id', 'location_dest_id', 'type'], context) - assertion_msg = "did not get the correct default (got: %s)" % defaults - log('got defaults: %s', defaults) - assert defaults == {'location_id': False, 'location_dest_id': False, 'type': 'internal'}, assertion_msg - defaults = self.default_get(cr, uid, ['location_id', 'location_dest_id', 'type'], context) - assertion_msg = "did not get the correct default with uid %s (got: %s)" % (uid, defaults) - log('got defaults: %s', defaults) - assert defaults == {'location_id': False, 'location_dest_id': False, 'type': 'internal'}, assertion_msg + 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) + for field in fields: + if defaults[field] != False: + assert location_obj.check_access_rule(cr, uid, defaults[field], 'read', context), "unreadable location %s" % field + 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'] + for field in fields: + if defaults[field] != False: + assert location_obj.check_access_rule(cr, uid, defaults[field], 'read', context), "unreadable default %s" % field + +- + 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) + if defaults['location_id'] != False: + assert location_obj.check_access_rule(cr, uid, defaults['location_id'], 'read', context), "unreadable default source location" + +- + check default locations for warehouse in multicompany setting +- + !python {model: stock.warehouse}: | + fields = ['lot_input_id', 'lot_stock_id', 'lot_output_id'] + defaults = self.default_get(cr, uid, fields, context) + for field in fields: + for field in fields: + if defaults[field] != False: + assert location_obj.check_access_rule(cr, uid, defaults[field], 'read', context), "unreadable default %s" % field From 0418aee3c7b8fd1cc73f42846cfd91040dd136d6 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Wed, 22 May 2013 17:37:05 +0200 Subject: [PATCH 09/20] [TEST] new tests for lp:118211 on mrp bzr revid: alexandre.fayolle@camptocamp.com-20130522153705-vivt0a2wb4xwesco --- addons/mrp/__openerp__.py | 1 + addons/mrp/test/multicompany.yml | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 addons/mrp/test/multicompany.yml 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..06d927afc65 --- /dev/null +++ b/addons/mrp/test/multicompany.yml @@ -0,0 +1,16 @@ +- + 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) + for field in fields: + if defaults[field] != False: + assert location_obj.check_access_rule(cr, uid, defaults[field], 'read', context), "unreadable location %s" % field From d46d9882348d45b3e379dbef31bdd1bd5f23d0a7 Mon Sep 17 00:00:00 2001 From: "alexandre.fayolle@camptocamp.com" <> Date: Wed, 22 May 2013 22:21:08 +0200 Subject: [PATCH 10/20] [FIX] syntax error in test bzr revid: alexandre.fayolle@camptocamp.com-20130522202108-kv2oasnuxuf7erke --- addons/stock/test/multicompany.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/stock/test/multicompany.yml b/addons/stock/test/multicompany.yml index 8c5df8fe5c2..8b65849cbff 100644 --- a/addons/stock/test/multicompany.yml +++ b/addons/stock/test/multicompany.yml @@ -17,7 +17,7 @@ for field in fields: if defaults[field] != False: assert location_obj.check_access_rule(cr, uid, defaults[field], 'read', context), "unreadable location %s" % field - assert defaults['type'] == type}, "wrong move type" + assert defaults['type'] == type, "wrong move type" - check onchange_move_type does not return unreadable in multicompany setting From 653495b23f35fe36153234556e6361ea72a00157 Mon Sep 17 00:00:00 2001 From: "alexandre.fayolle@camptocamp.com" <> Date: Thu, 23 May 2013 07:39:49 +0200 Subject: [PATCH 11/20] [FIX] missing import in previous commmit bzr revid: alexandre.fayolle@camptocamp.com-20130523053949-cvvc8k9y0clx5pot --- addons/mrp/mrp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 77e3dd4965a..b99a91e9633 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -23,7 +23,7 @@ import time from datetime import datetime import openerp.addons.decimal_precision as dp -from openerp.osv import fields, osv +from openerp.osv import fields, osv, orm from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT, DATETIME_FORMATS_MAP from openerp.tools import float_compare from openerp.tools.translate import _ From aa33867973a9bb5e202800ead379ce21155bd4c4 Mon Sep 17 00:00:00 2001 From: "alexandre.fayolle@camptocamp.com" <> Date: Thu, 23 May 2013 07:53:45 +0200 Subject: [PATCH 12/20] [FIX] check_access does not return bool, it raises bzr revid: alexandre.fayolle@camptocamp.com-20130523055345-gg007ad9j457l0gl --- addons/mrp/test/multicompany.yml | 5 ++++- addons/stock/test/multicompany.yml | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/addons/mrp/test/multicompany.yml b/addons/mrp/test/multicompany.yml index 06d927afc65..95a499aba50 100644 --- a/addons/mrp/test/multicompany.yml +++ b/addons/mrp/test/multicompany.yml @@ -13,4 +13,7 @@ defaults = self.default_get(cr, uid, ['location_id', 'location_dest_id', 'type'], context) for field in fields: if defaults[field] != False: - assert location_obj.check_access_rule(cr, uid, defaults[field], 'read', context), "unreadable location %s" % 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/test/multicompany.yml b/addons/stock/test/multicompany.yml index 8b65849cbff..bab3638765f 100644 --- a/addons/stock/test/multicompany.yml +++ b/addons/stock/test/multicompany.yml @@ -16,7 +16,10 @@ defaults = self.default_get(cr, uid, ['location_id', 'location_dest_id', 'type'], context) for field in fields: if defaults[field] != False: - assert location_obj.check_access_rule(cr, uid, defaults[field], 'read', context), "unreadable location %s" % 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" - @@ -29,7 +32,10 @@ result = self.onchange_move_type(cr, uid, [], type, context)['value'] for field in fields: if defaults[field] != False: - assert location_obj.check_access_rule(cr, uid, defaults[field], 'read', context), "unreadable default %s" % field + try: + location_obj.check_access_rule(cr, uid, defaults[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 @@ -38,7 +44,10 @@ location_obj = self.pool.get('stock.location') defaults = self.default_get(cr, uid, ['location_id'], context) if defaults['location_id'] != False: - assert location_obj.check_access_rule(cr, uid, defaults['location_id'], 'read', context), "unreadable default source location" + try: + location_obj.check_access_rule(cr, uid, defaults['location_id'], 'read' + except Exception, exc: + assert False, "unreadable source location: %s" % exc - check default locations for warehouse in multicompany setting @@ -49,4 +58,7 @@ for field in fields: for field in fields: if defaults[field] != False: - assert location_obj.check_access_rule(cr, uid, defaults[field], 'read', context), "unreadable default %s" % field + try: + location_obj.check_access_rule(cr, uid, defaults[field], 'read', context) + except Exception, exc: + assert False, "unreadable default %s: %s" % (field, exc) From a1c18b87f22268f0d423e97caba157ff4e75e1b6 Mon Sep 17 00:00:00 2001 From: "alexandre.fayolle@camptocamp.com" <> Date: Thu, 23 May 2013 08:17:48 +0200 Subject: [PATCH 13/20] [TEST] fix name error in test bzr revid: alexandre.fayolle@camptocamp.com-20130523061748-0dzsi5hk18u3cdv2 --- addons/stock/test/multicompany.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/stock/test/multicompany.yml b/addons/stock/test/multicompany.yml index bab3638765f..0c90b47c96c 100644 --- a/addons/stock/test/multicompany.yml +++ b/addons/stock/test/multicompany.yml @@ -31,9 +31,9 @@ for type in ('in', 'internal', 'out'): result = self.onchange_move_type(cr, uid, [], type, context)['value'] for field in fields: - if defaults[field] != False: + if result[field] != False: try: - location_obj.check_access_rule(cr, uid, defaults[field], 'read', context) + location_obj.check_access_rule(cr, uid, result[field], 'read', context) except Exception, exc: assert False, "unreadable location %s: %s" % (field, exc) From eeb9d9149470c50735dfa807821c58a22f51e529 Mon Sep 17 00:00:00 2001 From: "alexandre.fayolle@camptocamp.com" <> Date: Thu, 23 May 2013 08:18:09 +0200 Subject: [PATCH 14/20] [FIX] bad call to check_access_rules bzr revid: alexandre.fayolle@camptocamp.com-20130523061809-jf3qt56ruiwjnpg4 --- addons/mrp/mrp.py | 4 ++-- addons/stock/stock.py | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index b99a91e9633..a6fab88c7d3 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -411,7 +411,7 @@ class mrp_production(osv.osv): def _src_id_default(self, cr, uid, ids, context=None): try: src_location = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_stock', context=context) - src_location.check_access_rule('read', context=context) + src_location._model.check_access_rule(cr, uid, [src_location.id], 'read', context=context) except (orm.except_orm, ValueError): # no read access return False @@ -420,7 +420,7 @@ class mrp_production(osv.osv): def _dest_id_default(self, cr, uid, ids, context=None): try: dest_location = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_stock', context=context) - dest_location.check_access_rule('read', context=context) + dest_location._model.check_access_rule(cr, uid, [dest_location.id], 'read', context=context) except (orm.except_orm, ValueError): # no read access return False diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 172d8bd9c27..360845d1a5c 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1737,7 +1737,7 @@ class stock_move(osv.osv): if location_xml_id: try: location = mod_obj.get_object(cr, uid, 'stock', location_xml_id) - location.check_access_rule('read', context=context) + location._model.check_access_rule(cr, uid, [location.id], 'read', context=context) location_id = location.id except (orm.except_orm, ValueError): # likely the user does not have read access on the location @@ -1961,14 +1961,14 @@ class stock_move(osv.osv): location_dest_id = 'stock_location_customers' try: location = mod_obj.get_object(cr, uid, 'stock', location_source_id) - location.check_access_rule('read', context=context) + location._model.check_access_rule(cr, uid, [location.id], 'read', context=context) source_location_id = location.id except (orm.except_orm, ValueError): # likely the user does not have read access on the location source_location_id = False try: location = mod_obj.get_object(cr, uid, 'stock', location_dest_id) - location.check_access_rule('read', context=context) + location._model.check_access_rule(cr, uid, [location.id], 'read', context=context) dest_location_id = location.id except (orm.except_orm, ValueError): # likely the user does not have read access on the location @@ -2909,7 +2909,7 @@ class stock_inventory_line(osv.osv): def _default_stock_location(self, cr, uid, context=None): try: location = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_stock') - location.check_access_rule('read', context=context) + location._model.check_access_rule(cr, uid, [location.id], 'read', context=context) stock_location_id = location.id except (ValueError, orm.except_orm): # likely the user does not have read access on the location @@ -2955,7 +2955,7 @@ class stock_warehouse(osv.osv): def _default_lot_input_stock_id(self, cr, uid, context=None): try: lot_input_stock = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_stock') - lot_input_stock.check_access_rule('read', context=context) + lot_input_stock._model.check_access_rule(cr, uid, [lot_input_stock.id], 'read', context=context) lot_input_stock_id = lot_input_stock.id except (ValueError, orm.except_orm): # likely the user does not have read access on the location @@ -2965,7 +2965,7 @@ class stock_warehouse(osv.osv): def _default_lot_output_id(self, cr, uid, context=None): try: lot_output = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_output') - lot_output.check_access_rule('read', context=context) + lot_output._model.check_access_rule(cr, uid, [lot_output.id], 'read', context=context) lot_output_id = lot_output.id except (ValueError, orm.except_orm): # likely the user does not have read access on the location From def3ef900371e2dd9068b7658b379275989b216c Mon Sep 17 00:00:00 2001 From: "alexandre.fayolle@camptocamp.com" <> Date: Thu, 23 May 2013 08:20:22 +0200 Subject: [PATCH 15/20] [FIX] bad call to check_access_rules bzr revid: alexandre.fayolle@camptocamp.com-20130523062022-u5bqrgpc3ctffhmi --- addons/stock/stock.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 360845d1a5c..bd79cea8a89 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1702,7 +1702,7 @@ class stock_move(osv.osv): if location_xml_id: try: location = mod_obj.get_object(cr, uid, 'stock', location_xml_id, context=context) - location.check_access_rule('read', context=context) + location._model.check_access_rule(cr, uid, [location.id], 'read', context=context) location_id = location.id except (orm.except_orm, ValueError): # likely the user does not have read access on the location From cebc5dd29c8ad582c2569e33fc2dfcf59d7df70e Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Thu, 23 May 2013 10:34:30 +0200 Subject: [PATCH 16/20] [TEST] more test fixing bzr revid: alexandre.fayolle@camptocamp.com-20130523083430-r8towg1vxicmjkhw --- addons/mrp/test/multicompany.yml | 3 ++- addons/stock/test/multicompany.yml | 24 ++++++++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/addons/mrp/test/multicompany.yml b/addons/mrp/test/multicompany.yml index 95a499aba50..66f06fd1206 100644 --- a/addons/mrp/test/multicompany.yml +++ b/addons/mrp/test/multicompany.yml @@ -11,8 +11,9 @@ 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[field] != False: + if defaults.get(field): try: location_obj.check_access_rule(cr, uid, defaults[field], 'read', context) except Exception, exc: diff --git a/addons/stock/test/multicompany.yml b/addons/stock/test/multicompany.yml index 0c90b47c96c..c4d50a45d79 100644 --- a/addons/stock/test/multicompany.yml +++ b/addons/stock/test/multicompany.yml @@ -14,8 +14,9 @@ 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[field] != False: + if defaults.get(field): try: location_obj.check_access_rule(cr, uid, defaults[field], 'read', context) except Exception, exc: @@ -30,8 +31,9 @@ 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[field] != False: + if result.get(field): try: location_obj.check_access_rule(cr, uid, result[field], 'read', context) except Exception, exc: @@ -43,9 +45,10 @@ !python {model: stock.fill.inventory}: | location_obj = self.pool.get('stock.location') defaults = self.default_get(cr, uid, ['location_id'], context) - if defaults['location_id'] != False: + log('got defaults: %s', defaults) + if defaults.get('location_id'): try: - location_obj.check_access_rule(cr, uid, defaults['location_id'], 'read' + location_obj.check_access_rule(cr, uid, defaults['location_id'], 'read', context) except Exception, exc: assert False, "unreadable source location: %s" % exc @@ -53,12 +56,13 @@ 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: - for field in fields: - if defaults[field] != False: - try: - location_obj.check_access_rule(cr, uid, defaults[field], 'read', context) - except Exception, exc: - assert False, "unreadable default %s: %s" % (field, exc) + 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) From cea92690f76942583dfc82ef49660de362c33c32 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Thu, 23 May 2013 11:00:55 +0200 Subject: [PATCH 17/20] [FIX] fix exception check bzr revid: alexandre.fayolle@camptocamp.com-20130523090055-4m418aninaczbzcy --- addons/stock/wizard/stock_fill_inventory.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/stock/wizard/stock_fill_inventory.py b/addons/stock/wizard/stock_fill_inventory.py index d0062c82538..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): @@ -31,7 +31,7 @@ class stock_fill_inventory(osv.osv_memory): 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, e: + except (ValueError, orm.except_orm), e: return False return location_id or False From 1bf62e51a74926b441bf8361c1267f2618ff4217 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Thu, 23 May 2013 11:01:23 +0200 Subject: [PATCH 18/20] [TEST] [FIX] check_access_rules does not cope with a single id bzr revid: alexandre.fayolle@camptocamp.com-20130523090123-e2o2fzekgy7zqtl8 --- addons/mrp/test/multicompany.yml | 2 +- addons/stock/stock.py | 2 +- addons/stock/test/multicompany.yml | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/addons/mrp/test/multicompany.yml b/addons/mrp/test/multicompany.yml index 66f06fd1206..7ed9cf86023 100644 --- a/addons/mrp/test/multicompany.yml +++ b/addons/mrp/test/multicompany.yml @@ -15,6 +15,6 @@ for field in fields: if defaults.get(field): try: - location_obj.check_access_rule(cr, uid, defaults[field], 'read', context) + 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/stock.py b/addons/stock/stock.py index bd79cea8a89..9ac610dec83 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1704,7 +1704,7 @@ class stock_move(osv.osv): location = mod_obj.get_object(cr, uid, 'stock', location_xml_id, context=context) location._model.check_access_rule(cr, uid, [location.id], 'read', context=context) location_id = location.id - except (orm.except_orm, ValueError): + except (orm.except_orm, ValueError), exc: # likely the user does not have read access on the location location_id = False return location_id diff --git a/addons/stock/test/multicompany.yml b/addons/stock/test/multicompany.yml index c4d50a45d79..2c0353aa71d 100644 --- a/addons/stock/test/multicompany.yml +++ b/addons/stock/test/multicompany.yml @@ -18,7 +18,7 @@ for field in fields: if defaults.get(field): try: - location_obj.check_access_rule(cr, uid, defaults[field], 'read', context) + 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" @@ -35,7 +35,7 @@ for field in fields: if result.get(field): try: - location_obj.check_access_rule(cr, uid, result[field], 'read', context) + location_obj.check_access_rule(cr, uid, [result[field]], 'read', context) except Exception, exc: assert False, "unreadable location %s: %s" % (field, exc) @@ -48,7 +48,7 @@ log('got defaults: %s', defaults) if defaults.get('location_id'): try: - location_obj.check_access_rule(cr, uid, defaults['location_id'], 'read', context) + location_obj.check_access_rule(cr, uid, [defaults['location_id']], 'read', context) except Exception, exc: assert False, "unreadable source location: %s" % exc @@ -63,6 +63,6 @@ for field in fields: if defaults.get(field): try: - location_obj.check_access_rule(cr, uid, defaults[field], 'read', context) + location_obj.check_access_rule(cr, uid, [defaults[field]], 'read', context) except Exception, exc: assert False, "unreadable default %s: %s" % (field, exc) From a0fa40ac165cc9b564ac4423160060e0be69d9f8 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Fri, 23 Aug 2013 13:52:48 +0200 Subject: [PATCH 19/20] [IMP] mrp: convert yml test to python bzr revid: mat@openerp.com-20130823115248-5a7z35xge3ogpyvc --- addons/mrp/__openerp__.py | 1 - addons/mrp/test/multicompany.yml | 20 ----------- addons/mrp/tests/__init__.py | 28 +++++++++++++++ addons/mrp/tests/test_multicompany.py | 50 +++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 21 deletions(-) delete mode 100644 addons/mrp/test/multicompany.yml create mode 100644 addons/mrp/tests/__init__.py create mode 100644 addons/mrp/tests/test_multicompany.py diff --git a/addons/mrp/__openerp__.py b/addons/mrp/__openerp__.py index 2fde404bf12..6e025ae2d90 100644 --- a/addons/mrp/__openerp__.py +++ b/addons/mrp/__openerp__.py @@ -77,7 +77,6 @@ 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 deleted file mode 100644 index 7ed9cf86023..00000000000 --- a/addons/mrp/test/multicompany.yml +++ /dev/null @@ -1,20 +0,0 @@ -- - 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/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) From 22a3ba7d66926b9d1fcef07b4a8322da88b28002 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Fri, 23 Aug 2013 13:58:51 +0200 Subject: [PATCH 20/20] [IMP] stock: convert yml test to python bzr revid: mat@openerp.com-20130823115851-36tcrj17n5bme3uu --- addons/stock/__openerp__.py | 1 - addons/stock/test/multicompany.yml | 68 ------------------ addons/stock/tests/__init__.py | 28 ++++++++ addons/stock/tests/test_multicompany.py | 92 +++++++++++++++++++++++++ 4 files changed, 120 insertions(+), 69 deletions(-) delete mode 100644 addons/stock/test/multicompany.yml create mode 100644 addons/stock/tests/__init__.py create mode 100644 addons/stock/tests/test_multicompany.py diff --git a/addons/stock/__openerp__.py b/addons/stock/__openerp__.py index db7117ce2b3..b3d7e30f1ce 100644 --- a/addons/stock/__openerp__.py +++ b/addons/stock/__openerp__.py @@ -94,7 +94,6 @@ 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/test/multicompany.yml b/addons/stock/test/multicompany.yml deleted file mode 100644 index 2c0353aa71d..00000000000 --- a/addons/stock/test/multicompany.yml +++ /dev/null @@ -1,68 +0,0 @@ - -- - 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/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)