콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다

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

아바타
취소
베스트 답변

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#


아바타
취소
베스트 답변

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

아바타
취소
베스트 답변

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


아바타
취소

Hi Haresh,

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

Any suggestion wellcome

관련 게시물 답글 화면 활동
2
7월 22
12014
1
12월 19
10040
1
3월 15
4923
4
1월 24
14150
2
11월 19
6844