Odoo Help

Welcome!

This community 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.

1

how to use create and write function

By
samir
on 5/27/13, 9:05 AM 5,216 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--
5102
| 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--
912
| 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
on 5/27/13, 9:24 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

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