1
votes

I'm attempting to display the customer reference as a read only field in the Delivery orders form view.

I added a related field to the stock.picking.out model:

class stock_picking_out(osv.Model):
    _inherit = "stock.picking.out"
    _columns = {
        'cust_order_ref': fields.related('sale_id', 'client_order_ref', type='char', string='Customer Reference'),
    }

I inherited the delivery order view with the following block:

<record id="view_stock_picking_out_extended_form" model="ir.ui.view">
        <field name="name">stock.picking.out.extended.form</field>
        <field name="model">stock.picking.out</field>
        <field name="inherit_id" ref="stock.view_picking_out_form"/>
        <field name="arch" type="xml">
            <xpath  expr="//field[@name='origin']" position="after">
                <field name="client_order_ref" />
            </xpath>
        </field>
    </record>

When I install my custom module, I do see the model getting updated with the new field, and I also see the new field appear in the delivery order view. However, the values of this field are always empty, even if there is a customer order reference in the related sale order (sale_id). Can anyone explain to me what I am doing wrong here?

Thanks in advance.

1

1 Answers

0
votes

Try with blow code, Before add any new field in this object stock.picking.in or stock.picking.out, we need to add it into parent class stock.picking.

class stock_picking(osv.Model):
    _inherit = 'stock.picking'
    _columns = {
        'cust_order_ref': fields.related('sale_id', 'client_order_ref', type='char', string='Customer Reference'),
    }

class stock_picking_out(osv.Model):
    _inherit = "stock.picking.out"
    _columns = {
        'cust_order_ref': fields.related('sale_id', 'client_order_ref', type='char', string='Customer Reference'),
    }

Please change your .xml file to.

<record id="view_stock_picking_out_extended_form" model="ir.ui.view">
    <field name="name">stock.picking.out.extended.form</field>
    <field name="model">stock.picking.out</field>
    <field name="inherit_id" ref="stock.view_picking_out_form"/>
    <field name="arch" type="xml">
        <xpath  expr="//field[@name='origin']" position="after">
            <field name="cust_order_ref" />
        </xpath>
    </field>
</record>

Hope this will solve you problem.