1

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?

Red Tea
  • 13
  • 1
  • 3
  • Possible duplicate of [How the Delivery orders are created from Sale Order in ODOO 10?](https://stackoverflow.com/questions/47215960/how-the-delivery-orders-are-created-from-sale-order-in-odoo-10) – Navi Apr 05 '19 at 09:39
  • it's not duplicate, because in v10 we had a function named - _prepare_order_line_procurement() to add custom values to stock.move . Now this is not the case in v12 anymore – Red Tea Apr 05 '19 at 10:16

1 Answers1

3

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.

Tanzil Khan
  • 942
  • 1
  • 9
  • 20
  • Hi @Tanzil Khan, is this the same format to implement moving a field from sale order to stock picking when a sale is confirmed? – Eric Aug 06 '21 at 14:14
  • Hi @Eric, did you find à solution to what you needed ? – Gabin Mar 22 '22 at 15:30
  • Yes @Gabin , the format was the same as this. Having any issues or a clarification? – Eric Mar 23 '22 at 20:06