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

onchange method of field ? [Closed]

By
priyankahdp
on 3/23/13, 8:38 AM 1,707 views

The Question has been closed

by
priyankahdp
on 04/30/2013 10:20:07

I'm going to add a method when i select company then need to get estates list relevant for that company.mapping is like this company has estates.estates has divisions

but my function not worked properly.please help me to sort it out friends

def on_change_company(self, cr, uid, ids, company_id, context=None):
    if not company_id:
        return {}
    company = self.pool.get('bpl.company.n.registration').browse(cr, uid, company_id, context=context)
    print (company.estates)
    estates = company.estates
    return {
        'value': {
            'bpl_estate_id': estates,
        }
    }
_name = "bpl.worker"
_description = "Worker registration details"
_columns = {
    'bpl_company_id':fields.many2one('bpl.company.n.registration', 'Company', help='Company'),
    'bpl_estate_id':fields.many2one('bpl.estate.n.registration', 'Estate', help='Estate'),
    'bpl_division_id':fields.many2one('bpl.division.n.registration', 'Division', help='Division'),

here shows my separate classes for those mappings

class company_new_registration(osv.osv):
    _name = "bpl.company.n.registration"
    _description = "Company"
    _columns = {
                'name': fields.char('Company Name', size=128, required=True),
                'estates': fields.one2many('bpl.estate.n.registration', 'company_id', 'Estate')                                        
    }

company_new_registration()

class estate_new_registration(osv.osv):
    _name = "bpl.estate.n.registration"
    _description = "Estates"
    _columns = {
        'name': fields.char('Estate Name', size=128, required=True),
        'company_id': fields.many2one('bpl.company.n.registration', 'Company Name', select=True),
        'divisions': fields.one2many('bpl.division.n.registration', 'estate_id', 'Division')
    }

estate_new_registration()

class division_new_registration(osv.osv):
    _name = "bpl.division.n.registration"
    _description = "Divisions"
    _columns = {
        'name': fields.char('Division Name', size=128, required=True),
        'estate_id': fields.many2one('bpl.estate.n.registration', 'Estate Name', select=True),
    }

division_new_registration()

in my view xml file i call to function like below

<field name="bpl_company_id" on_change="on_change_company(bpl_company_id)" />
<field name="bpl_estate_id" />
<field name="bpl_division_id" />

earlier i added

estates = company.estates

then field name value equal to estates.then error occured "not id attribute" then i remove

.id

phase.then below error occur. seems issue with mapping.now another type error also occured

TypeError: browse_record(bpl.estate.n.registration, 1) is not JSON serializable
1
Mike Telahun
On 3/23/13, 11:06 AM

There are a couple of problems with your code:

  1. There is not estate_id in your view. Do you mean bpl_estate_id?
  2. bpl_estate_id is a many2one field, but estates (in bpl.company.n.registration) is a one2many field. So if you want to use it you have to choose one value from it. For example:

    return { 'value': { 'estate_id': estates[0].id } }

thanks Mike u saved my whole day........ :-) now its working. one more friend, please tell me if i need to sql query with cr parameter for this how to do this. ex : select estate where xxxxx

priyankahdp
on 3/23/13, 11:40 AM
0

Francesco OpenCode

--Francesco OpenCode--
3608
| 5 7 9
Grottaglie, Italy
--Francesco OpenCode--

Italian Odoo (OpenERP) Modules Developer LINKEDIN: http://www.linkedin.com/in/francescoapruzzese

Francesco OpenCode
On 3/23/13, 9:02 AM

Try this:

def on_change_company(self, cr, uid, ids, company_id, context=None):
    if not company_id:
        return {}
    company = self.pool.get('bpl.company.n.registration').browse(cr, uid, company_id, context=context)
    print (company.estates)
    estates = company.estates
    return {
        'value': {
            'bpl_estate_id': estates,
        }
    }

About This Community

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

Question tools

1 follower(s)

Stats

Asked: 3/23/13, 8:38 AM
Seen: 1707 times
Last updated: 3/16/15, 8:10 AM