Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odgovori
5249 Prikazi

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

Avatar
Opusti
Best Answer

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)
Avatar
Opusti
Related Posts Odgovori Prikazi Aktivnost
0
nov. 23
1188
1
nov. 22
3574
0
jun. 22
2491
2
mar. 24
4427
1
mar. 23
2431