This question has been flagged
2 Replies
3864 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" 
                                on_change="onchange_activity_name(activity_summarycode)"/>
                                 <field name="activity_name"/>
                          <field name="region_id"/>
                    </group>
               </form>
        </field>
    </record>

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)], 
      context=context)   

    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.'),
]
Avatar
Discard
Best Answer

Small typo I guess:

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

Your model is called 'budget.activity_year'.

self.pool.get('budget.activity_year')

Regards.

Avatar
Discard
Author

thank you!...that was the problem.

Best Answer

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)
Avatar
Discard
Author

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.