我已经在我的sale_order表单中添加了一个自定义字段,现在我希望它显示在确认销售订单后生成的相应交货订单上。在v8中可能有一种更简单的方法来执行此操作,但是我必须在v7中执行此操作,因此请仅以适用于OpenERP v7的答案进行回答。
在尝试了许多其他方法来实现这一目标之后,我在oodo.com上发现了一个建议,称有人应该尝试覆盖'_prepare_order_picking'函数,因为它实际上是根据销售订单中的值创建交货订单的,方法是返回将在交货单上显示的值的字典。我已经获得了该链接提供的代码,但对我而言不起作用。这是link。非常感谢您的帮助,我已尽力澄清所有问题,但如果需要澄清,请告诉我,我将编辑我的问题。
我已经修改了代码,以使其更易于阅读,并且将我需要从销售订单中获取的自定义字段的数量限制为一个字段,在实际工作时,我需要多个字段,但是一旦实现,就应该易于扩展正确实施。
我修改的代码如下:
__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>
最佳答案
您需要在sale_stock
文件中添加__openerp__.py
(取决于销售和库存)模块的依赖项。喜欢
"depends" : ['sale_stock'],
在
nicks_delivery_fields.xml
中,您输入了错误的型号名称来修改交货单视图。它应该是stock.picking
<?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">stock.picking</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>