Search code examples
python-2.7odooodoo-8openerp-8

Add shipping address field in stock picking in odoo


When we conform sale from sale order it generate stock picking in all transfer and pass some fields by automatically like oder id as source document, partner id and other things to stock picking now i want to transfer another field with them that is address of partner_shipping_id field. Someone please tell me how can i do it. I'll be very thankful ...


Solution

  • The following way you can solve your issue.

    1.Set custom field on sale.order and stock.pirking in py as well as view side.
    2.Inherit the stock.move in your custom module and use the _prepare_picking_assign() over ridding method.
    3.Using super and set your custom field value.
    4.View that changes After confirming of Sale Order document.

    For example :

    from openerp import models, fields, api, _
    
    class sale_order(models.Model):
        _inherit='sale.order'
        customer_field=fields.Char(string='Customer Field')
    
    class stock_picking(models.Model):
        _inherit='stock.picking'
        customer_field=fields.Char(string='Customer Field')    
    
    class stock_move(models.Model):
        _inherit='stock.move'
    
    def _prepare_picking_assign(self,cr, uid, move, context=None):
        res=super(stock_move,self)._prepare_picking_assign(cr, uid, move, context)
        if move.procurement_id and move.procurement_id.sale_line_id and move.procurement_id.sale_line_id.order_id:
            sale_obj = move.procurement_id.sale_line_id.order_id
            if sale_obj.dif_pick_address:
                res.update({
                    'customer_field':sale_obj.customer_field,
                })
        return res   
    

    Above code is working fine in Odoo 8.0 version

    Also, You should set in the view part so that you can check the sale order values come into stock picking after confirming your sale order.

    I hope my answer may helpful for you :)