Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
5265 มุมมอง

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)
อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
พ.ย. 23
1197
Create order_line from code แก้ไขแล้ว
1
พ.ย. 22
3604
0
มิ.ย. 22
2499
2
มี.ค. 24
4496
1
มี.ค. 23
2446