This question has been flagged
2 Replies
8210 Views

Hi, I use OE version 7.0 and I have a case like this.

In stock move, on module stock, we have write method defined

def write(self, cr, uid, ids, vals, context=None):
    if isinstance(ids, (int, long)):
        ids = [ids]
    if uid != 1:
        frozen_fields = set(['product_qty', 'product_uom', 'product_uos_qty', 'product_uos', 'location_id', 'location_dest_id', 'product_id'])
        for move in self.browse(cr, uid, ids, context=context):
            if move.state == 'done':
                if frozen_fields.intersection(vals):
                    raise osv.except_osv(_('Operation Forbidden!'),
_('Quantities, Units of Measure, Products and Locations cannot be modified on stock moves that have already been processed (except by the Administrator).'))
    return super(stock_move, self).write(cr, uid, ids, vals, context=context)


I want to override it in my custom module become like this one:

def write(self, cr, uid, ids, vals, context=None):
    if isinstance(ids, (int, long)):
        ids = [ids]
    access = self.pool.get('ir.model.access').check(cr, uid, 'stock.move', 'write', context)
    if uid != 1 and not access:
        frozen_fields = set(['product_qty', 'product_uom', 'product_uos_qty', 'product_uos', 'location_id', 'location_dest_id', 'product_id'])
        for move in self.browse(cr, uid, ids, context=context):
            if move.state == 'done':
                if frozen_fields.intersection(vals):
                    raise osv.except_osv(_('Operation Forbidden!'),
_('Quantities, Units of Measure, Products and Locations cannot be modified on stock moves that have already been processed (except by the Administrator).')) 
return super(stock_move, self).write(cr, uid, ids, vals, context=context)

If I use that method in my custom module, my method will be called but it keep raising exception from the first method too.

I need suggestions how to do it properly in OpenERP/ODOO

Avatar
Discard
Best Answer

Hi Sinaga,

To eliminate need of calling super method, you can use like this:-

instead of this -> super(stock_move, self).write(cr, uid, ids, vals, context=context)

you can give-> osv.osv.write(self, cr, uid, ids, vals, context=context)

This will call directly write function of ORM...


Hope this helps....


Avatar
Discard
Best Answer

Hi Dedi Sinaga,

You will be writing a class in the custom module like below.

class stock_move_inherit(osv.osv):

        _inherit = 'stock.move'

       def write(self, cr, uid, ids, vals, context=None):

if isinstance(ids, (int, long)):

ids = [ids]

access = self.pool.get('ir.model.access').check(cr, uid, 'stock.move', 'write', context)

if uid != 1 and not access:

frozen_fields = set(['product_qty', 'product_uom', 'product_uos_qty', 'product_uos', 'location_id', 'location_dest_id', 'product_id'])

for move in self.browse(cr, uid, ids, context=context):

if move.state == 'done':

if frozen_fields.intersection(vals):

raise osv.except_osv(_('Operation Forbidden!'),

_('Quantities, Units of Measure, Products and Locations cannot be modified on stock moves that have already been processed (except by the Administrator).'))

return super(stock_move_inherit, self).write(cr, uid, ids, vals, context=context)



In the return statement, the value should be your inherited class name (stock_move_inherit) but not the main class name (stock_move).

Avatar
Discard