콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
12199 화면

This method will write the form name on state change from draft to 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 '',
            })

But everytime I try to save it, it throws me this:

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'

I think it has something to do with this line 'name' : lambda self, cr, uid, context: self.pool.get('ir.sequence').next_by_code(cr, uid, 'bsi.production.order') or '', but if I change it to 'name': name, I got the same result.

Any ideas?

아바타
취소
베스트 답변

You have written code as per new API, and it doesn't allow the self.pool.get anymore. so you have to try like 

lambda self: self.env['ir.sequence'].next_by_code("model.name")

Please read the new api guidelines here

아바타
취소
관련 게시물 답글 화면 활동
0
3월 25
1286
0
1월 25
3383
1
8월 23
14678
change password 해결 완료
1
8월 23
13308
1
7월 23
10337