OpenERP:通过继承销售订单在“州”字段上添加新选择

时间:2013-02-19 21:50:44

标签: openerp

我真的需要在我的Sale Order对象上添加一个额外的'state'值。从7.0版开始,'sale_stock'模块就已经完成了。当您尝试从自己的模块执行相同操作时,您的键,值将被忽略。有没有其他替代方法来实现这一目标?
正如我所发现的那样,这似乎是两年前的一个旧时期问题,如thread所述。建议的解决方法是做这样的事情:

_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'`

如果在启动板上报告此错误或是否是非预期用途?你能提出哪些其他可能的解决方案?提前谢谢。

3 个答案:

答案 0 :(得分:0)

试试这个

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()

答案 1 :(得分:0)

只需继承sale.order模型并添加您在现有模型中定义的状态字段,添加您需要添加的外部状态

例如:

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()

而不是键值将是您的附加选择字段,您可以根据您的要求将其设置在序列中的任何位置。

答案 2 :(得分:0)

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

的列表
depends : ['sale_stock',...]

您可以在此模块中看到一个示例,该示例在州字段中有另一个(键,值):http://bazaar.launchpad.net/~agaplan/agaplan-addons/7.0/files/head:/sale_double_validation/

希望有所帮助