2013-04-26 63 views
1

這是我的錯誤,當我要創建records.please時,建議我缺少的地方在哪裏?在我的代碼OpenERP一次創建和寫入方法

File "/home/bellvantage/Documents/openerp-7.0/openerp-7/openerp/addons/bpl/bpl.py", line 394, in create 
    self.write(cr, uid, [id], {'name': name}, context) 
    File "/usr/lib/python2.7/dist-packages/psycopg2/extensions.py", line 129, in getquoted 
    pobjs = [adapt(o) for o in self._seq] 
ProgrammingError: can't adapt type 'builtin_function_or_method' 
2013-04-26 06:14:07,719 5739 INFO demo werkzeug: 127.0.0.1 - - [26/Apr/2013 06:14:07] "POST /web/dataset/call_kw HTTP/1.1" 200 - 

相關的信息是這樣的

def create(self, cr, uid, values, context=None): 
    name = 'CheckRoll No : ' + str(values['checkroll_no']) + ' & Gang No : ' + str(values['gang_no']) 
    self.write(cr, uid, [id], {'name': name}, context) 
    return True   

錯誤出現,並表明我寫的方法是incorrect.seems一些參數由我失蹤。 需要你的建議來實現模塊 感謝..

EDITED

現在錯誤,如下面

File "/home/bellvantage/Documents/openerp-7.0/openerp-7/openerp/addons/bpl/bpl.py", line 395, in create 
    res = super('bpl.work.offer',self).create(cr,uid,values,context=context) 
TypeError: must be type, not str 
2013-04-26 07:58:43,452 6947 INFO demo werkzeug: 127.0.0.1 - - [26/Apr/2013 07:58:43] "POST /web/dataset/call_kw HTTP/1.1" 200 - 

在這裏展示我的模型類領域

'name': fields.char('Name', size=50), 
'checkroll_no': fields.integer('Checkroll No'), 
'gang_no': fields.integer('Gang'), 

這裏顯示值爲當我調試(在super.create()的時間),

dict: {'selected_tea_workers_line_ids': [[5, False, False], [0, False, {'worker_emp_no': '1000', 'worker_id': 
1, 'tea_line_worker_id': False, 'is_selected': False}]], 'user_id': False, 'is_confirmed': False, 
'date_of_offer': '2013-04-26', 'bpl_division_id': 1, 'work_type': 'tea', 'checkroll_no': 10, 'name': 
'CheckRoll No : 10 & Gang No : 100', 'selected_rubber_workers_line_ids': [[5, False, False], [0, False, 
{'worker_emp_no': '1001', 'worker_id': 2, 'rubber_line_worker_id': False, 'is_selected': False}]], 
'work_update_id': False, 'field_no': 15, 'selected_sundry_workers_line_ids': [], 'payment_type': 
'normal_work', 'gang_no': 100, 'total_workers': 0, 'no_of_workers': 0, 'norm': 15, 
'selected_other_workers_line_ids': [], 'bpl_estate_id': 1, 'select_by': 'by_name'} 

現在它的工作。感謝阿諾馬

最後編輯

def create(self, cr, uid, values, context=None): 
    name = 'CheckRoll No = ' + str(values['checkroll_no']) + ' & Gang No = ' + str(values['gang_no']) 
    values.update({'name': name}) 
    return super(bpl_work_offer,self).create(cr,uid,values,context=context) 

回答

3

Actua如果你做錯了。你正試圖寫入一個沒有被創建的記錄。在這種情況下,我不認爲你需要使用寫入。

class bpl_abc(osv.osv) 
    _inherit = 'bpl.work.offer' 
    def create(self, cr, uid, values, context=None): 
     name = 'CheckRoll No : ' + str(values['checkroll_no']) + ' & Gang No : ' + str(values['gang_no']) 
     values.update({'name': name}) 
     res = super('bpl_abc',self).create(cr,uid,values,context=context) 
     return res 
bpl_abc() 

請記住,openerp中的創建函數總是返回新創建的記錄的ID。

+0

感謝AnomA.thats爲什麼我想要代碼和課程:-) – 2013-04-26 06:57:57

+1

什麼錯誤?請在值中檢查checkroll_no和gang_no中的值。 – OmaL 2013-04-26 07:16:19

+0

Sorted AnomA thanks.i錯過模型類並將其作爲字符串給予:-) – 2013-04-26 08:58:20

-2

可能是因爲 '寫' 的方法是內置的方法

EX:

with open("a.txt","r+") as f: 
    f.write("sometext") 

不要使用self.write因爲寫入是'文件'對象的內置方法

+0

似乎問題與[id] .need獲取自我對象的ID – 2013-04-26 06:37:07

+1

你已經定義了「寫」方法,並使用它在這裏,我想要你是重命名你的「寫」方法 – 2013-04-26 06:37:16

+0

謝謝Rajesh。 yep.need覆蓋寫入和更新值,當我的創建函數called.thats我的requirements.how要做到這一點。 – 2013-04-26 06:40:58