2013-02-19 92 views
0

我確實需要在我的銷售訂單對象上添加額外的「狀態」值。從版本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在啓動板中報或這是一個意外的用途?你能提出什麼其他可能的解決方案?提前致謝。

回答

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

簡單地繼承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按您的要求。

0

有同樣的問題,我看了一下線程,你注意到了。 我想這個問題來自於我們的模塊和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/

希望它有幫助

相關問題