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

When Modified my fields my merge field not update?

By
philip
on 11/30/14, 6:07 AM 592 views

Hi all,

I need your help to fix this, when I update my fields street and street2 the abs_completeadd field is not update.

When I create the record example street = "no 45 avenue street" street2= "xxxxx" my merge field abs_completeadd = "No 45 Avenue Street Xxxxx" but when I modified my fields, my abs_completeadd field is not update. I got no error, then I tried to look on the database two fields updated but my merged abs_completeadd field is not.

Thanks

    _columns = {
        'abs_street': fields.char('Street', size=128, store=False),
        'abs_street2': fields.char('Street2', size=128, store=False),
        'abs_provinces_id': fields.many2one('abs.provinces', 'Province'),
        'abs_cities_id': fields.many2one('abs.cities', 'City'),
        'abs_completeadd': fields.char('Address', size=128),
    }

def create(self, cr, uid, vals, context=None):
        abs_completeadd = str(vals['abs_street'] or '') + ' ' +str(vals['abs_street2'] or '')
        abs_street = str(vals['abs_street'] or '')
        abs_street2 = str(vals['abs_street2'] or '')
        vals['abs_completeadd'] = abs_completeadd.title()
        vals['abs_street'] = abs_street.title()
        vals['abs_street2'] = abs_street2.title()
        return super(hr_employee, self).create(cr, uid, vals, context=context)

0

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
On 11/30/14, 10:53 PM

Because you only update the abs_completeadd in create method.  You need to also inherit the write method to do so.  Now, there are several things in write that is more complicated than create:

  • user may update only abs_street (in which case vals['abs_street2'] will return KeyError) or only abs_street2 (in which case vals['abs_street'] will return KeyError) or even did not update both fields (update other field that are not abs_street or abs_street2).  So, you might want to first read (or browse) the record first and then use the old value as default.  To avoid KeyError you want to use vals.get('abs_street2', '') instead of vals['abs_street2'] or ''.
  • write (can) work with multiple IDs.  So, since if abs_street2 and/or abs_street not updated you did not get the value, you want to put the necessary codes inside of the for loop that loop through all ids.

This is what you mean sir? I will try this later and update here. Thanks for your kind def create(self, cr, uid, vals, context=None):
abs_completeadd = str(vals.get['abs_street'] or '') + ' ' +str(vals.get['abs_street2'] or '')
abs_street = str(vals['abs_street'] or '')
abs_street2 = str(vals['abs_street2'] or '')
vals['abs_completeadd'] = abs_completeadd.title()
vals['abs_street'] = abs_street.title()
vals['abs_street2'] = abs_street2.title()
return super(hr_employee, self).create(cr, uid, vals, context=context)

philip
on 12/1/14, 1:05 AM

You're just repeating the create method inherit that you have specified earlier. You need to inherit the write method.

Ivan
on 12/1/14, 1:27 AM

Hi John, can you give an example method inherit you've said, I am newbie in Odoo7 Thanks

philip
on 12/1/14, 9:49 AM

What you did for method create is inheriting (overriding). You just need to do something similar to write method. You can find some examples in openerp/addons/base/res/res_partner.py itself on who to inherit write method.

Ivan
on 12/1/14, 10:29 PM

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

1 follower(s)

Stats

Asked: 11/30/14, 6:07 AM
Seen: 592 times
Last updated: 3/16/15, 8:10 AM