Odoo Help


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.


Onchange event to return activity name by searching activity code?

on 4/17/14, 7:22 AM 1,136 views

Hi, I'm having some problem with my onchange method which is supposed to return the activity name once activity code is entered (it looks for the activity code and returns the activity name that matches the code )

im getting this error, AttributeError: 'NoneType' object has no attribute 'search'

Below is my code..please help

my xml form

 <record id="activitysummary_form" model="ir.ui.view">
          <field name="name">budget.activity_summary.form</field>
          <field name="model">budget.activity_summary</field>
         <field name="arch" type="xml">
               <form string="Activity Master Template" version="7.0">
                      <group col="4">
                               <field name="activity_summarycode" string="Activity Code" 
                                 <field name="activity_name"/>
                          <field name="region_id"/>

my class with the onchange method

class activity_summary(osv.osv):
   _name = "budget.activity_summary"
   _description = "Activity Summary"
   _rec_name = "activity_summarycode"
   _columns = {
      'activity_summarycode' : fields.many2one("budget.activity_year", "Activity Summary Code", on delete = "no action", required=True  ),   
      'activity_name' : fields.char("Activity Name" size = 128),
      'region_id' : fields.char("Region ID", size=64, required=True),
    _sql_constraints = [
     ('activity_summarycode_unique', 'UNIQUE(activity_summarycode)', 'Each Activity year code is unique.'),

   def onchange_activity_name(self, cr, uid, ids, activity_summarycode, context = None):
    activity = self.pool.get('budget.activity_yearcode').search(cr, uid,[('activity_yearcode', '=', activity_summarycode)], 

    if activity:
        activityname = self.pool.get('budget.activity_yearcode').browse(cr, uid, activity, context=context)
        return {'activity_name' : activityname.activity_name}
    return {'activity_name':{}}

the class im trying to search code and retrieve name

class activity_year(osv.osv):
  _name = "budget.activity_year"
  _description = "Activity year"
  _rec_name = "activity_yearcode"
  _columns = {
    'activity_yearcode' : fields.char("Activity Code", size=64, required=True),
    'activity_name' : fields.char("Activity Name", size=128),
    'act_status' : fields.selection([
                ('1', 'All'),
                ('2', 'Active'),
                ('3', 'Inactive'),
                ], 'Status'),
  _sql_constraints = [
    ('activity_yearcode_unique', 'UNIQUE(activity_yearcode)', 'Each activity code is unique.'),

René Schuster

--René Schuster--
| 5 5 8
Weinheim, Germany
--René Schuster--

Challenge Everything!

René Schuster
On 4/17/14, 7:39 AM

Small typo I guess:

activity = self.pool.get('budget.activity_yearcode').search(cr, uid,[('activity_yearcode', '=', activity_summarycode)], 

Your model is called 'budget.activity_year'.



thank you!...that was the problem.

on 4/18/14, 6:34 AM

Sudhir Arya (SA)

--Sudhir Arya (SA)--
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow




Sudhir Arya (SA)
On 4/17/14, 4:35 PM

Hi Suthan,

The error has appeared because you have given wrong object name while creating object in your code.

You have given self.pool.get('budget.activity_yearcode') but it must be self.pool.get('budget.activity_summary').

You should change the object name:

  1. activity = self.pool.get('budget.activity_summary').search(cr, uid,[('activity_yearcode', '=', activity_summarycode)],
  2. activityname = self.pool.get('budget.activity_summary').browse(cr, uid, activity, context=context)

hi, i fixed it, as you said i changed the object name, but the field values i was trying the get was from the budget.activity_year model. anyway thank you, i appreciate your help.

on 4/18/14, 6:44 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)


Asked: 4/17/14, 7:22 AM
Seen: 1136 times
Last updated: 3/16/15, 8:10 AM