Merge lp:~camptocamp/ocb-addons/7.0-fix-lp-1210195-RDE into lp:ocb-addons

Proposed by Romain Deheele - Camptocamp
Status: Rejected
Rejected by: Stefan Rijnhart (Opener)
Proposed branch: lp:~camptocamp/ocb-addons/7.0-fix-lp-1210195-RDE
Merge into: lp:ocb-addons
Diff against target: 45 lines (+12/-5)
2 files modified
procurement/procurement.py (+3/-5)
stock/stock.py (+9/-0)
To merge this branch: bzr merge lp:~camptocamp/ocb-addons/7.0-fix-lp-1210195-RDE
Reviewer Review Type Date Requested Status
Alexandre Fayolle - camptocamp code review, test Needs Fixing
Review via email: mp+181227@code.launchpad.net

Description of the change

Hello,

This branch fixes bug #1210195:access denied when a subsidiary company's user tries to create a reordering rule(multicompany context)

https://bugs.launchpad.net/openobject-addons/+bug/1210195

Romain

To post a comment you must log in.
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

This fix breaks the database creation from scratch.

2013-09-26 07:53:54,261 8361 INFO openerp_prod_doremi openerp.modules.loading: module procurement: loading stock_orderpoint.xml
2013-09-26 07:53:54,321 8361 ERROR openerp_prod_doremi openerp.tools.convert: Parse error in /home/afayolle/work/customers/doremi/openerp_buildout_prod/parts/addons/procurement/stock_orderpoint.xml:7:
<record id="stock_warehouse_orderpoint_0" model="stock.warehouse.orderpoint">
            <field name="product_max_qty">25.0</field>
            <field name="product_min_qty">5.0</field>
            <field model="product.uom" name="product_uom" ref="product.product_uom_dozen"/>
            <field model="stock.warehouse" name="warehouse_id" search="[]"/>
            <field model="product.product" name="product_id" ref="product.product_product_36"/>
            <field name="location_id" ref="stock.stock_location_stock"/>
        </record>
Traceback (most recent call last):
  File "/home/afayolle/work/customers/doremi/openerp_buildout_prod/parts/server/openerp/tools/convert.py", line 847, in parse
    self._tags[rec.tag](self.cr, rec, n)
  File "/home/afayolle/work/customers/doremi/openerp_buildout_prod/parts/server/openerp/tools/convert.py", line 814, in _tag_record
    id = self.pool.get('ir.model.data')._update(cr, self.uid, rec_model, self.module, res, rec_id or False, not self.isnoupdate(data_node), noupdate=self.isnoupdate(data_node), mode=self.mode, context=rec_context )
  File "/home/afayolle/work/customers/doremi/openerp_buildout_prod/parts/server/openerp/addons/base/ir/ir_model.py", line 963, in _update
    res_id = model_obj.create(cr, uid, values, context=context)
  File "/home/afayolle/work/customers/doremi/openerp_buildout_prod/parts/server/openerp/osv/orm.py", line 4318, in create
    vals = self._add_missing_default_values(cr, user, vals, context)
  File "/home/afayolle/work/customers/doremi/openerp_buildout_prod/parts/server/openerp/osv/orm.py", line 2487, in _add_missing_default_values
    defaults = self.default_get(cr, uid, missing_defaults, context)
  File "/home/afayolle/work/customers/doremi/openerp_buildout_prod/parts/addons/procurement/procurement.py", line 554, in default_get
    warehouse = self.pool.get('stock.warehouse').browse(cr, uid, res['warehouse_id'], context)
KeyError: 'warehouse_id'

review: Needs Fixing (code review, test)
Revision history for this message
Holger Brunn (Therp) (hbrunn) wrote :

setting to work in progress due to inactivity

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Competing fix was merged in upstream 7.0: https://code.launchpad.net/~openerp-dev/openobject-addons/7.0-opw-596679-rgo/+merge/186294. Setting to rejected.

Unmerged revisions

9414. By Romain Deheele - Camptocamp

[FIX] fix bug #1210195:fix access denied when a subsidiary company's user tries to create a reordering rule(multicompany context)

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 2012-10-23 16:05:04 +0000
3+++ procurement/procurement.py 2013-08-21 08:52:01 +0000
4@@ -537,7 +537,8 @@
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+ 'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.warehouse.orderpoint', context=c),
10+ 'warehouse_id': lambda self, cr, uid, c: self.pool.get('stock.warehouse')._default_warehouse_id(cr, uid, context=c)
11 }
12 _sql_constraints = [
13 ('qty_multiple_check', 'CHECK( qty_multiple > 0 )', 'Qty Multiple must be greater than zero.'),
14@@ -548,10 +549,7 @@
15
16 def default_get(self, cr, uid, fields, context=None):
17 res = super(stock_warehouse_orderpoint, self).default_get(cr, uid, fields, context)
18- # default 'warehouse_id' and 'location_id'
19- if 'warehouse_id' not in res:
20- warehouse = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'warehouse0', context)
21- res['warehouse_id'] = warehouse.id
22+ # default location_id'
23 if 'location_id' not in res:
24 warehouse = self.pool.get('stock.warehouse').browse(cr, uid, res['warehouse_id'], context)
25 res['location_id'] = warehouse.lot_stock_id.id
26
27=== modified file 'stock/stock.py'
28--- stock/stock.py 2013-08-15 07:54:23 +0000
29+++ stock/stock.py 2013-08-21 08:52:01 +0000
30@@ -2944,6 +2944,15 @@
31 'lot_output_id': fields.many2one('stock.location', 'Location Output', required=True, domain=[('usage','<>','view')]),
32 }
33
34+ def _default_warehouse_id(self, cr, uid, context=None):
35+ company_id = self.pool.get('res.users').read(cr, uid, uid, ['company_id'])['company_id']
36+ if company_id:
37+ default_warehouse_id = self.search(cr, uid, [('company_id','=',company_id[0])])
38+ if default_warehouse_id:
39+ return default_warehouse_id[0]
40+ else:
41+ raise osv.except_osv(_("Warning"), _("Please define the warehouse and locations for %s company first."%(company_id[1])))
42+
43 def _default_lot_input_stock_id(self, cr, uid, context=None):
44 lot_input_stock = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_stock')
45 return lot_input_stock.id