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

Python code error in onchange one2many field. How can i solve this?

By
rosey
on 10/8/14, 6:28 AM 1,230 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?

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.

Ludo - Neobis
on 10/8/14, 7:17 AM

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....

deep
on 10/8/14, 7:15 AM

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

Ben Bernard
on 10/9/14, 12:22 AM

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

Ludo - Neobis
on 10/9/14, 8:56 AM

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

deep
on 10/9/14, 8:59 AM
4

Remya

--Remya--
5813
| 7 8 8
Thiruvananthapuram, India
--Remya--

Working as an Senior ODOO developer. http://in.linkedin.com/pub/remya-r/69/a23/298

Remya
On 10/9/14, 1:38 AM

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': {}}

Thnaks for Ur work

aci aisha
on 3/11/15, 1:21 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

5 follower(s)

Stats

Asked: 10/8/14, 6:28 AM
Seen: 1230 times
Last updated: 3/16/15, 8:10 AM