Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
5203 Weergaven

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
Annuleer
Beste antwoord

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
Annuleer
Auteur

thank you!...that was the problem.

Beste antwoord

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
Annuleer
Auteur

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.

Gerelateerde posts Antwoorden Weergaven Activiteit
1
feb. 22
2698
1
mei 24
2529
0
aug. 15
3575
1
mrt. 15
4961
1
mrt. 15
9704