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 define a default country value for the partner form in my custom module?

By
Francisco Luz
on 4/13/14, 1:35 AM 1,422 views

FYI I am aware that one could define default values for any field through the developer mode User Interface.

I would like though to define my default values on my custom module. For the partner object specifically, I presume the way to go is something like:

from openerp.osv import orm, fields

class MyModule(orm.Model):
    _inherit = 'res.partner'
   _defaults = {
       # Not quite sure how to set the default value for country here.
   }
1

Med Said BARA

--Med Said BARA--
2664
| 5 5 7
Algeria
--Med Said BARA--
Med Said BARA
On 4/13/14, 7:14 AM

Try using this code - where XX = your country code:

def _default_country(self, cr, uid, context=None):

    cid = self.pool.get('res.country').search(cr, uid, [('code', '=', 'XX')], context=context)
    if cid: return cid[0]

_defaults = {
    'country_id': _default_country,
}
1

Prakash

--Prakash--
3173
| 5 4 7
Bikaner, India
--Prakash--

OpenERP Devloper at SunARC Technology

Prakash
On 4/13/14, 7:17 AM

Your solution works also but I had to slightly change the code " _defaults = { 'country': " with " _defaults = { 'country_id': "

Francisco Luz
on 4/13/14, 6:58 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

0 follower(s)

Stats

Asked: 4/13/14, 1:35 AM
Seen: 1422 times
Last updated: 3/16/15, 8:10 AM