This question has been flagged
1 Reply
4678 Views

class location_location(osv.osv):

      _name = 'location.location'
      _description = 'Site Information'
      _columns = {
                  'name': fields.char('Location'),
                  'location_ids': fields.one2many('project.location', 'project_id', 'Work done'),
        
    }
location_location()

class project_location(osv.osv):
      _name = "project.location"
      _description = "Project Location"
      _columns = {
        
        'project_id': fields.many2one('project.project', 'Project'),
      
    }

Then i will enter the projects in the specified location.  When location change, its corresponding projects should be displayed in the project field(many2one field)

onchange function is

 'dest_location' : fields.many2one('location.location',"New Location"),
 'new_project' : fields.many2one('project.project','New Project'),

 def onchange_project_id(self, cr, uid, id, dest_location, context=None):
          if dest_location:
             project = self.pool.get('location.location').browse(cr, uid, dest_location, context=context).location_ids
             print "locationnnnnnnnnnnnnnnnn",project
             return {'value': {'new_project': project.name}} 

 

How can solve this?

Avatar
Discard

Your 'project_id' field on the project location should point to your site information OR your location_ids on the site information should use a different field to point to in the project location. Easiest would be to create a many2one on your project.location, call it 'site_location_id' and point it to 'location.location' object.

Your */return type/* is not matching with the column/* */"new_project" data_type, do have a look at it 1. In you object: you have defined it as Many2one,/ (*which take integer as an input*)/ 2. In onchange: variable project is of type list, (*/list of browse_records/*) 3. similarily you are trying to fetch name from project /*(list variable)*/ which is not sinking with the semmantics....

I swear I just read the above comments as answers. o_O

@ Ben Bernard: That is correct. Furthermore, the replies on those answers have been removed as well. Odd situation.....

Hmmmm... I did answered it in Answer post... but guess my answer was not appropriate, hence somebody has converted it to a Comment .. funny :) :)

Best Answer

Try this:

 

def onchange_location_id(self, cr, uid, id, new_project, context=None):
          if new_project:
             project = self.pool.get('project.project').browse(cr, uid, new_project, context=context)
             return {'value': {'dest_location': project.location.id}} 
          return {'value': {}}

Avatar
Discard