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

I have two fields, both are many2one

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

 <field name="dest_location" on_change="onchange_project_id(dest_location)"/>
 <field name="new_project" on_change="onchange_location_id(new_project)" />

My doubt :

Error in

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
       return {'value': {'new_project': project.name}}

How to return one2many field in a onchange function?

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'),
      
    }

How can i import all projects in the location table when onchange works?

Avatar
Annuleer
Beste antwoord

Hello rosey,

You need to make list of tuples for your one2many field and return it in your result dictionary with one2many field

Here you go!

return {'value': {''location_ids'': [(0, 0,  { fields }), (0, 0,  { fields })]}

Hope this will help you.

Regards,

Anil.

Avatar
Annuleer
Auteur

Thanks Anil. I will try.

Auteur

its not working

Use this format (0, 0, { fields }) list tuples. each dictionary will contain your line data.

Auteur

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

Auteur

is this correct??

Nop. let say you have three fields inside project.location model like name,date now your return value for number location_ids will be like this. return {'value': {'location_ids': [(0,0,{'name':"project_first", 'date':"project_date"}), (0,0, {'name':'project_second', 'date':"date_second"})] }} so on..

Nop. let say you have two fields inside project.location model like name,project_id now your return value for number location_ids will be like this. return {'value': {'location_ids': [(0,0,{'name':"project_first", 'project_id':id of your project.}), (0,0, {'name':'project_second', 'project_id':id of your project })] }} so on..

Beste antwoord
terms_obj = self.env['x.x'].search([('terceiro_id', '=', self.terceiro_id_doc_conta_corente.id),('pago1', '=', False)])
list_of_dict = []para linha em terms_obj:
data = self ._comput_line (linha)
data.update ({ ' name1 ' : line.name1 , 'pago1' : line.pago1 , ' date1 ' : line.date , 'acobrado1' : line.acobrado1 ,
'totalr1' : line.totalr , 'saldo1' : line.saldo})
list_of_dict.append ((0 , 0 , data)) return { 'valor' : { "doc_cont_corent" : list_of_dict}}

this will help you

Avatar
Annuleer
Beste antwoord

return {'value': {'new_project': project.name}}

project is plural, but new_project is singular, so which project should return? If you want to return the first project, then

return {'value': {'new_project': project[0].id}}

Hmm, I think I should edit also the other answer from related question -___-

Avatar
Annuleer
Auteur

i want to return all projects, which have location the same. If location 1 have 3 projects, i want to select all of the three only in the list.

You can't do it, because new_project is many2one.