此方法会将( ! ) Parse error: syntax error, unexpected '[' in C:\wamp\www\mayamixx\wp-content\object-cache.php on line 499
Call Stack
# Time Memory Function Location
1 0.0018 364080 {main}( ) ..\index.php:0
2 0.0030 367704 require( 'C:\wamp\www\mayamixx\wp-blog-header.php' ) ..\index.php:17
3 0.0045 393160 require_once( 'C:\wamp\www\mayamixx\wp-load.php' ) ..\wp-blog-header.php:13
4 0.0066 410760 require_once( 'C:\wamp\www\mayamixx\wp-config.php' ) ..\wp-load.php:37
5 0.0127 584208 require_once( 'C:\wamp\www\mayamixx\wp-settings.php' ) ..\wp-config.php:96
6 0.1062 4509576 wp_start_object_cache( )
表单写在name
上,从state
更改为draft
:
confirm
但每当我试图保存它时,它就会抛出这个:
production_type = fields.Selection([
('budgeted','Budgeted'),
('nonbudgeted','Non Budgeted'),
('direct','Direct Order'),
], string='Type of Order', index=True, copy=False,
help=" ")
state = fields.Selection([
('draft','Draft'),
('confirm','Confirmed'),
('inprogress','In progress'),
('print_order_inprogress','Print In Progress'),
('finished','Finished'),
('cancel','Cancel'),
], string='State', index=True, copy=False,
help=" ")
@api.one
def prod_start_func(self):
name = '/'
if self.production_type == 'budgeted':
name = self.env['ir.sequence'].next_by_code('bsi.production.budgeted') or '/'
elif self.production_type == 'nonbudgeted':
name = self.env['ir.sequence'].next_by_code('bsi.production.non_budgeted') or '/'
elif self.production_type == 'direct':
name = self.env['ir.sequence'].next_by_code('bsi.production.direct') or '/'
self.write({
'state': 'confirm',
'name' : lambda self, cr, uid, context: self.pool.get('ir.sequence').next_by_code(cr, uid, 'bsi.production.order') or '',
})
我认为这与此行Traceback (most recent call last):
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 546, in _handle_exception
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 583, in dispatch
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 319, in _call_function
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\service\model.py", line 118, in wrapper
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 316, in checked_call
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 812, in __call__
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 412, in response_wrap
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\addons\web\controllers\main.py", line 944, in call_kw
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\addons\web\controllers\main.py", line 936, in _call_kw
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\api.py", line 268, in wrapper
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\api.py", line 373, in old_api
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\api.py", line 291, in <lambda>
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\models.py", line 4057, in <lambda>
AttributeError: 'NoneType' object has no attribute 'id'
有关,但如果我将其更改为'name' : lambda self, cr, uid, context: self.pool.get('ir.sequence').next_by_code(cr, uid, 'bsi.production.order') or '',
,我会得到相同的结果。
有什么想法吗?
答案 0 :(得分:1)
您正在尝试在新的api中使用旧的api格式
试试这个: 'name':lambda self:self.env ['ir.sequence']。next_by_code('bsi.production.order')或'/'
还要确保self包含单个记录(正如您使用的是@ api.one)
如果它包含多个记录,请使用@ api.multi
没有记录集可用@ api.model
答案 1 :(得分:1)
我想我知道它的问题因为我的上一个答案,你从create方法中删除了return语句,这是错误的你应该保留它我认为你知道这一点。
@model
create(self, vals):
....
....
return super(bsi_production_order, self).create(vals)
因为当create is donoo期望方法返回一个对象时,在你的情况下你删除了return语句,所以默认情况下调用将返回None。当odoo尝试访问返回记录的id(记录=无)时,他会引发此错误。
请记住,当您覆盖create或write时,此规则始终会调用super,因为创建的实际工作是在models.py中。并且odoo期望write方法返回True。
另一个例子,例如你需要在creting方法之后做逻辑
@model
create(self, vals):
....
....
record = super(bsi_production_order, self).create(vals)
......
......
# always return the object that is created
return record
在write方法中,只需在这样的情况下返回True