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

I created an onchange function that link some object lines to the current one

     mo_lines_g1 = fields.One2many(comodel_name='object.order', inverse_name='mo_id1', copy=False )
    @api.onchange('date')    def change_date(self):          if self.date:
            g1=self.env['object.order'].search(['&'('date_order','>=',self.date),('date_order','<=',self.date)])            self.mo_lines_g1 = [(6,0, g1.ids )]


here everything is ok, but when I save the view, Odoo try to delete the linked lines from the object.order

so I tried to see what the write function send I found it send the old records :
vals[ 'mo_lines_g1'] = [[2, 61, False], [2, 62, False], [2, 63, False]]

normaly it must be :
vals['mo_lines_g1']=[] # or [(6,0,[])]

any ideas ?

아바타
취소
베스트 답변

Hello Qamar,


Try below code::

@api.onchange('date')

def change_date(self):

     if self.date:

         g1=self.env['object.order'].search(['&'('date_order','>=',self.date),('date_order','<=',self.date)])

         if g1:

             for id in g1:

             self.mo_lines_g1 = [(4, g1.id )]

아바타
취소
작성자

mo_lines_g1 are added and prisent on the view but when I click Save button they disappears !

관련 게시물 답글 화면 활동
2
2월 20
17628
2
3월 15
7494
3
7월 17
11965
1
4월 17
19586
2
12월 15
3903