Odoo Help


how to use create and write function

samir Guesmi
on 5/27/13, 9:05 AM 7,947 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 .

On 5/27/13, 9:28 AM


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)


Andreas Maertens
On 5/27/13, 9:21 AM

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.

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

samir Guesmi
on 5/27/13, 9:24 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 5/27/13, 9:05 AM
Seen: 7947 times
Last updated: 3/16/15, 8:10 AM