コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
5267 ビュー

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
1198
1
11月 22
3609
0
6月 22
2499
2
3月 24
4501
1
3月 23
2447