I have created two fields, one in sale.order.line and one in stock.move. When the sale.order get's confirmed it creates stock.picking with product info in stock.move. I want to send my custom field value from sale.order.line to stock.move. How to do that?
To send value from sale.order to stock.picking I used the '''action_confirm''' function. I can get the '''picking_ids''' and crate a stock.move in there. But that will not be efficient.
Is there any existing function in odoo like '''_prepare_stock_moves()''' to create the move from sales order?
The function is still there in odoo v12 but in a different way.
In 'sale.order.line' model write this -
@api.multi
def _prepare_procurement_values(self, group_id=False):
res = super(YourModelName, self)._prepare_procurement_values(group_id)
# I am assuming field name in both sale.order.line and in stock.move are same and called 'YourField'
res.update({'YourField': self.YourField})
return res
While creating stock.picking or stock.move it impacts procurement/stock.rule. So, you will have to add the values in stock.rule too. For that inherit the stock.rule model. Like this -
class StockRuleInherit(models.Model):
_inherit = 'stock.rule'
def _get_stock_move_values(self, product_id, product_qty, product_uom, location_id, name, origin, values, group_id):
res = super(StockRuleInherit, self)._get_stock_move_values(product_id, product_qty, product_uom, location_id,
name, origin, values, group_id)
res['YourField'] = values.get('YourField', False)
return res
Now, when you will confirm the sale order, the remarks value from the order line will be also carried to stock.move with other values.