This question has been flagged
1 Reply
3970 Views

I only find modules or answers for v6 and v8.
Can someone help me on v7?

 

class stock_picking_out(orm.Model):
    _inherit = 'stock.picking.out'  
    
    def _get_sale_client_order_ref(self, cr, uid, ids, field_name, arg, context={}):
        res = {}
        for session in self.browse(cr,uid,ids,context=context):
            if (session.sale_id):
                res[session.id] = session.sale_id.client_order_ref or False
        return res
           
    _columns = {
        "client_order_reference": fields.function(_get_sale_client_order_ref, type='char', size=64,
                                                 method=True, string="Sales Order Customer Reference"
                                                 )
    }
   

Avatar
Discard
Best Answer

Instead of using a function field, you could try with related field
(http://odoo-new-api-guide-line.readthedocs.org/en/latest/fields.html#related-field)

class stock_picking_out(orm.Model):
    _inherit = 'stock.picking.out'  
    _columns = {
        "client_order_reference": fields.related('sale_id', 'client_order_ref', type='char', size=64,
                   string="Sales Order Customer Reference"
         )
    }

NOTE:  If you try to store a related field at stock.picking.out by adding parameter store=True, then you need to define this column at stock.picking also.(This is a special case only applicable for stock.picking, stock.picking.out and stock.picking.in)

Avatar
Discard
Author

Thanks for your note to the code has helped.