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

I need to update the Margin field which is a one2many field of SaleOrderLine to field margin in another model StockMove. How can we achieve it in Odoo 15

class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
Margin = fields.Float(string="Margin")

@api.model
def action_confirm(self):
record = self.env['stock.move'].update({'Margin': self.Margin})
print(record)
return super(SaleOrderLine, self).action_confirm(self)


class StockMove(models.Model):
_inherit = 'stock.move'
Margin = fields.Float(string="Margin")

This is the python code which i have written

아바타
취소
베스트 답변

Sale Order line have one2many relation with stock.move. So, if you want to update margin field of all moves related with line the try below code.

class SaleOrder(models.Model):
_inherit = 'sale.order'

def action_confirm(self):
for line in self.order_line:
for move in line.move_ids:
move.write({'Margin':line.Margin})
return super(SaleOrder, self).action_confirm(self)
아바타
취소
관련 게시물 답글 화면 활동
0
11월 23
1172
1
11월 22
3548
0
6월 22
2439
2
3월 24
4381
1
3월 23
2413