Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
12 ตอบกลับ
7331 มุมมอง

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?

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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.

อวตาร
ละทิ้ง
ผู้เขียน

Thanks Anil. I will try.

ผู้เขียน

its not working

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

ผู้เขียน

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

ผู้เขียน

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

คำตอบที่ดีที่สุด
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

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

อวตาร
ละทิ้ง
ผู้เขียน

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.