This question has been flagged
2 Replies
22094 Views

hi all ,

i have add a new class , and it's related with product.product :

'myfield' : fields.one2many('new.field', 'number', 'My field'),

, now , i would to override quantité ( qty_available ) with value of field : ("number")

when i create or update a product.

thanks a lot .

Avatar
Discard
Best Answer

Hi,

if your class related with a one product.product use many2one.

class my_class(osv.osv) :
{
    _name = "my_class"
    _description = "My Class"
    _columns = {
        'number': fields.integer('Qte'),        
        'product_id': fields.many2one('product.product', 'Product'),
    }
}

in methods create and copy ,

def create(self, cr, uid, values, context=None):    
            #get product            
            product_pool = self.pool.get('product.product')                 
            product_id = values['product_id']
            #write a new value to product
            product_pool.write(cr, uid, [product_id],
                               {'qty_available': values['number'],}
                               )      
            return super(my_class, self).create(cr, uid, values, context)

Thanks.

Avatar
Discard
Best Answer

Looks like you want to set a default value for your product qty_available right?

You can set that with '_defaults' to make sure you'll get your default on creation. In other case (when write) you'll need to make 'qty_available' a functional field making that function setting your required functionality.

You can override 'qty_available' by resetting it '_columns' in your new module.

Avatar
Discard
Author

yes , i want to do like that , but not a default value , but costumer value .