Merge lp:~openerp-dev/openobject-addons/7.0-opw-596679-rgo into lp:openobject-addons/7.0

Proposed by Ravi Gohil (OpenERP)
Status: Merged
Merged at revision: 10007
Proposed branch: lp:~openerp-dev/openobject-addons/7.0-opw-596679-rgo
Merge into: lp:openobject-addons/7.0
Diff against target: 31 lines (+5/-5)
1 file modified
procurement/procurement.py (+5/-5)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/7.0-opw-596679-rgo
Reviewer Review Type Date Requested Status
Martin Trigaux (OpenERP) (community) Approve
Naresh(OpenERP) Pending
Review via email: mp+186294@code.launchpad.net

Description of the change

Hi,

This branch fixes the issue faced when user, who belongs to the company other than the 'Your Company', tries to create record for object stock.warehouse.orderpoint(Warehouse/Configuration/Reordering Rules), it says, "Access denied - Document type: Warehouse, Operation: read"

The reason is the xml_id(warehouse0) used to set the default warehouse for stock.warehouse.orderpoint object, which may not belong to current user's company.

I fixed this issue by searching the warehouse belonging to current user's company and set accordingly.

Kindly review the fix.

Thanks.

To post a comment you must log in.
Revision history for this message
Romain Deheele - Camptocamp (romaindeheele) wrote :

Hi,

I've tested your branch.
It leads to the next traceback :
2013-10-17 11:24:42,490 3719 ERROR rhonalia openerp.netsvc: company_id
Traceback (most recent call last):
  File "/home/rdeheele/oerp/sandbox/parts/server/openerp/netsvc.py", line 292, in dispatch_rpc
    result = ExportService.getService(service_name).dispatch(method, params)
  File "/home/rdeheele/oerp/sandbox/parts/server/openerp/service/web_services.py", line 626, in dispatch
    res = fn(db, uid, *params)
  File "/home/rdeheele/oerp/sandbox/parts/server/openerp/osv/osv.py", line 188, in execute_kw
    return self.execute(db, uid, obj, method, *args, **kw or {})
  File "/home/rdeheele/oerp/sandbox/parts/server/openerp/osv/osv.py", line 131, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/home/rdeheele/oerp/sandbox/parts/server/openerp/osv/osv.py", line 197, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/home/rdeheele/oerp/sandbox/parts/server/openerp/osv/osv.py", line 185, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/home/rdeheele/oerp/sandbox/parts/addons/product/product.py", line 752, in copy
    context=context)
  File "/home/rdeheele/oerp/sandbox/parts/addons/mail/mail_thread.py", line 302, in copy
    return super(mail_thread, self).copy(cr, uid, id, default=default, context=context)
  File "/home/rdeheele/oerp/sandbox/parts/server/openerp/osv/orm.py", line 5038, in copy
    new_id = self.create(cr, uid, data, context)
  File "/home/rdeheele/oerp/sandbox/parts/addons/mail/mail_thread.py", line 242, in create
    thread_id = super(mail_thread, self).create(cr, uid, values, context=context)
  File "/home/rdeheele/oerp/sandbox/parts/server/openerp/osv/orm.py", line 4477, in create
    result += self._columns[field].set(cr, self, id_new, field, vals[field], user, rel_context) or []
  File "/home/rdeheele/oerp/sandbox/parts/server/openerp/osv/fields.py", line 559, in set
    id_new = obj.create(cr, user, act[2], context=context)
  File "/home/rdeheele/oerp/sandbox/parts/server/openerp/osv/orm.py", line 4325, in create
    vals = self._add_missing_default_values(cr, user, vals, context)
  File "/home/rdeheele/oerp/sandbox/parts/server/openerp/osv/orm.py", line 2491, in _add_missing_default_values
    defaults = self.default_get(cr, uid, missing_defaults, context)
  File "/home/rdeheele/oerp/sandbox/parts/addons/procurement/procurement.py", line 554, in default_get
    warehouse_ids = warehouse_obj.search(cr, uid, [('company_id', '=', res['company_id'])], context=context)
KeyError: 'company_id'

Revision history for this message
Ravi Gohil (OpenERP) (rgo-openerp) wrote :

Hi Romain Deheele,

Thanks for pointing the mistake.

I just updated the branch to fix the mistake, would you please check again and share the feeback.

Revision history for this message
Martin Trigaux (OpenERP) (mat-openerp) wrote :

Merged in 7.0, thanks for the fix

revno: 10007 [merge]
revision-id: <email address hidden>

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'procurement/procurement.py'
2--- procurement/procurement.py 2013-10-21 09:57:35 +0000
3+++ procurement/procurement.py 2013-11-01 07:31:32 +0000
4@@ -552,7 +552,6 @@
5 'qty_multiple': lambda *a: 1,
6 'name': lambda x,y,z,c: x.pool.get('ir.sequence').get(y,z,'stock.orderpoint') or '',
7 'product_uom': lambda sel, cr, uid, context: context.get('product_uom', False),
8- 'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.warehouse.orderpoint', context=c)
9 }
10 _sql_constraints = [
11 ('qty_multiple_check', 'CHECK( qty_multiple > 0 )', 'Qty Multiple must be greater than zero.'),
12@@ -562,14 +561,15 @@
13 ]
14
15 def default_get(self, cr, uid, fields, context=None):
16+ warehouse_obj = self.pool.get('stock.warehouse')
17 res = super(stock_warehouse_orderpoint, self).default_get(cr, uid, fields, context)
18+ res['company_id'] = self.pool.get('res.company')._company_default_get(cr, uid, 'stock.warehouse.orderpoint', context=context)
19 # default 'warehouse_id' and 'location_id'
20 if 'warehouse_id' not in res:
21- warehouse = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'warehouse0', context)
22- res['warehouse_id'] = warehouse.id
23+ warehouse_ids = warehouse_obj.search(cr, uid, [('company_id', '=', res['company_id'])], context=context)
24+ res['warehouse_id'] = warehouse_ids and warehouse_ids[0] or False
25 if 'location_id' not in res:
26- warehouse = self.pool.get('stock.warehouse').browse(cr, uid, res['warehouse_id'], context)
27- res['location_id'] = warehouse.lot_stock_id.id
28+ res['location_id'] = False if not res.get('warehouse_id') else warehouse_obj.browse(cr, uid, res['warehouse_id'], context).lot_stock_id.id
29 return res
30
31 def onchange_warehouse_id(self, cr, uid, ids, warehouse_id, context=None):