OpenERP:通过继承销售订单在'状态'字段上添加新选择

问题描述:

我确实需要在我的销售订单对象上添加额外的“状态”值。从版本7.0开始,'sale_stock'模块就已经完成了。当你尝试从你自己的模块做同样的事情时,你的键,值只会被忽略。有没有其他的选择来实现这一目标?
正如我发现的,这似乎是两年前的旧时间问题,如thread中所述。建议解决有做这样的事情:OpenERP:通过继承销售订单在'状态'字段上添加新选择

_inherit = 'sale.order' 
def __init__(self, pool, cr): 
    super(sale_order, self)._columns['state'].selection.append(('keyx', 'valuex')) 

我发现这种方法的逻辑,但它导致了以下错误:

`File "/home/nicolas/Eclipse/OpenERP/7.0/src/openerp/osv/orm.py", line 2958, in _auto_init 
    self._field_create(cr, context=context) 
File "/home/nicolas/Eclipse/OpenERP/7.0/src/openerp/osv/orm.py", line 764, in _field_create 
    ir_model_fields_obj = self.pool.get('ir.model.fields') 
AttributeError: 'sale.order' object has no attribute 'pool'` 

如果这个bug在启动板中报或这是一个意外的用途?你能提出什么其他可能的解决方案?提前致谢。

试试这个

from openerp.osv import osv, fields 
class sale_order(osv.osv): 
    _inherit = 'sale.order' 
    selection_list = [];#add your selection list here. 
    _columns = { 
     'state': fields.selection(selection_list,'State');#add necessary arguments 
    } 
sale_order() 

简单地继承sale.order模型,并添加你的状态字段它是定义现有模型,添加您需要添加additionaly

的外部状态例如:

class sale_order(osv.osv) 

    _inherit ='sale.order' 

    _columns = { 
     'state': fields.selection([ 
     ('draft', 'Quotation'), 
     ('waiting_date', 'Waiting Schedule'), 
     ('manual', 'To Invoice'), 
     ('progress', 'In Progress'), 
     ('shipping_except', 'Shipping Exception'), 
     ('invoice_except', 'Invoice Exception'), 
     ('done', 'Done'), 
     ('cancel', 'Cancelled'), 
     **('key','value')**, 

上面这将是你新添加的选择值序列这么想的事情。

 ], 'Order State', readonly=True, help="Gives the state of the quotation or sales order. \nThe exception state is automatically set when a cancel operation occurs in the invoice validation (Invoice Exception) or in the picking list process (Shipping Exception). \nThe 'Waiting Schedule' state is set when the invoice is confirmed but waiting for the scheduler to run on the order date.", select=True), 

    } 

sale_order() 

比abouve关键值将是额外的选择字段,你可以将它设置任何地方在SQUENCE按您的要求。

有同样的问题,我看了一下线程,你注意到了。 我想这个问题来自于我们的模块和sale_stock是“冲突”的事实,因为它们修改了sale.order对象中的相同字段('state')并且不依赖于其他对象。 一种解决方案是修改自己的模块,并添加“sale_stock”中的‘依赖’OpenERP的列表的.py:

depends : ['sale_stock',...] 

您可以将此模块,曾在看到另一例(键,值) in state field:http://bazaar.launchpad.net/~agaplan/agaplan-addons/7.0/files/head:/sale_double_validation/

希望它有帮助