I have added a custom field to my sale_order form, and now I want it to show up on the corresponding delivery order which is generated after the sale order is confirmed. There is probably an easier way to do this in v8 but I must do this in v7, so please only respond with answers that will work in OpenERP v7.
After having tried many other approaches to accomplish this, I found a suggestion on odoo.com from someone saying that you should try overriding the '_prepare_order_picking' function as it is what actually creates the delivery order from the values in the sale order, by returning a dictionary of values that are to be displayed on the delivery order. I have taken the code provided from that link, but it is not working for me. Here is the link. Any help is greatly appreciated, I have tried to make everything clear but let me know if I need to clarify anything and I will edit my question.
I have modified my code to be easier to read, and have limited the number of custom fields I need to take from the sale order to just one field, I need multiple when this is actually working, but it should be easy to scale once it is correctly implemented.
My modified code is as follows:
__openerp__.py:
{
"name" : "Nick's Sale order/delivery order form fields",
"version" : "1.0",
"author" : "Nick",
"category" : "Custom",
"depends" : ['sale', 'stock'],
"description" : """ Sale and delivery order customizations by Nick """,
'data' : ['nicks_sale_fields.xml', 'nicks_delivery_fields.xml'],
'installable' : True,
}
nicks_sale_fields.py:
from openerp.osv import fields,osv
class nicks_sale_fields(osv.Model):
_inherit='sale.order'
def _prepare_order_picking(self, cr, uid, order, context=None):
vals=super(sale_order, self)._prepare_order_picking(cr, uid, order, context=context)
vals.update({'my_custom_field': 'my_custom_field_value'})
return vals
_columns={
'my_custom_field': fields.char('field description', required=True, store=True, size=3, help='field help text',),
}
_defaults={
'my_custom_field': 'yes'
}
nicks_sale_fields.xml:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="nicks_sale_order_fields">
<field name="name">sale.order.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="/form/sheet/notebook/page[1]/group" position="after">
<group string="Sales order: custom fields">
<field name="my_custom_field" string="Sale form descriptor" class="oe_inline"/>
</group>
</xpath>
</field>
</record>
</data>
</openerp>
nicks_delivery_fields.xml:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="nicks_deliv_order_fields">
<field name="name">stock.picking.out.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="stock.view_picking_out_form"/>
<field name="arch" type="xml">
<xpath expr="/form/sheet/group/group[2]/field[@name='origin']" position="after">
<group string="Delivery order: custom fields">
<field name="my_custom_field" string="Delivery form descriptor" class="oe_inline"/>
</group>
</xpath>
</field>
</record>
</data>
</openerp>
store=True
since it's not a function field. – Daniel Reis