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.

0

How to execute function immediately after adding new record?

By
Vitaliy
on 5/23/13, 5:15 AM 978 views

I have a model and I want to automatically fill one field of this model.

E.g. I have some test model and I want to automaticly genrate EAN13 for this after adding new product:

class product_test(osv.osv):
    _name = "product.test"
    _description = "Product test"
    _table = "product_test"
    _columns = {
        'name': fields.char('name', size=64, required=True, translate=True, select=True),
        'ean13': fields.char('EAN13', size=64, readonly=True),
    }
    _order = "name"
1

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/23/13, 6:10 AM

Hi,

must be overwrite method create

def create(self, cr, user, vals, context=None):           
        new_id = super(product_test, self).create(cr, user, vals, context)
        //your treatment
        return new_id

or use _defaults {}

  _columns = {  'ean13' : fields.char('ean13', size=64, ), }

  _defaults = {   'ean13': _get_ean13, }

  def _get_ref(self, cr, uid,context, *args):
        ean13 = // your treatment
        return ean13

Thanks.

Thank you! But when I install my addon with _defaults it writes the same EAN13 to all existing fileds.

Vitaliy
on 5/23/13, 6:38 AM

in _defaults you make a call to a function _get_ean13 which treatment you want it can return a new ean13 for each new product and not same ean13.

Borni DHIFI
on 5/23/13, 6:43 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/23/13, 5:15 AM
Seen: 978 times
Last updated: 3/16/15, 8:10 AM