This question has been flagged

hello, 

i have many2one field this contain one2many field i need to create onchange function on many2one field that when i select many2one field the onchange function fetch data from one2many field and set them in other one2many field

please help..

Avatar
Discard
Best Answer

Hi Guyz,

simply we can call  @api.constraints() method.

@api.constraints(first_one2many_field)

def copy_one2many(self):

   # loop the items in first_one2many_field and use "create" or" write" function to copy data to second_one2many_field#


Avatar
Discard
Best Answer

Hello Moh,

You can do this by using @api.onchange('many2one_field')

You can refer onchange methods in the default odoo addons.

Hope this helps.

Thank you

Avatar
Discard
Best Answer

Hi moh,

It's possible, you can do this using onchange method that i explain you bellow:

Step-1: create a many2one field like this:

many2one_field = fields.Many2one('One2manyFieldModelName', string="Many2one Field")

step-2: declare one2many field for storing onchange records

one2many_record_field = fields.One2many('Many2oneFieldModelName', 'field_name')

step-3 create onchange method using:

@api.onchange('many2one_field')

    def _onchange_many2one_field(self):

            self.one2many_record_field = self.env['One2manyFieldModelName'].search([('One2manyFieldName', '=', self.many2one_field)])


just do the above step and done.

Here i have created one Many2one field that contain one2many field data, after that i created one one2many field that store onchange records as you want, then after i just call onchange method and store records using search function, you can use any functions like mapped, search, browse etc.

i hope it's understandable for you, if not just comment.

accept the answer if usefull..

Thank you..


Avatar
Discard

Hi Haresh,

I'm be able to show un view records searched, bit when save view, records are missing.

Any suggestion wellcome