Odoo Help

1

how to use create and write function

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

3

Borni DHIFI

--Borni DHIFI--
5172
| 6 8 9
Tunis, Tunisia
--Borni DHIFI--

Techno Functional Consultant Odoo(OpenERP) 

http://www.linkedin.com/in/borni

Skype : dhifi.borni

Borni DHIFI
On 5/27/13, 9:28 AM

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.

1

Andreas Maertens

--Andreas Maertens--
937
| 5 5 7
Finsterwalde, Germany
--Andreas Maertens--

I develop odoo8.0 modules

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.

Register

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)

Stats

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