KeyError: 8 - Odoo v8

KeyError: 8 - Odoo v8

关于这个方法:

@api.multi
@api.onchange('order_picking')
@api.constrains('order_picking', 'order_picking.isbn')
def check_quantity(self):
    location = self.printer_book_block.property_stock_supplier.id
    for rec in self:
        if rec.order_picking:
            for line in rec.order_picking:
                if line.qty > line.isbn.with_context({ 'location': location, }).qty_available >= 0:#line.isbn.qty_available in location:
                    rec.write({'state': 'awaitingraw'})
                else:
                    rec.write({'state': 'work_in_progress',})

它给我带来了这个:

2017-12-14 01:50:15,732 5080 WARNING hasta_cuandooo_def openerp.models: method bsi.print.order.check_quantity: @constrains parameter 'order_picking.isbn' is not a field name
2017-12-14 01:50:16,075 5080 ERROR hasta_cuandooo_def openerp.http: 
Exception during JSON request handling.
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 948, in call_button
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 399, in old_api
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\addons\bsi\models\models.py", line 1472, in check_quantity
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\api.py", line 266, in wrapper
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\models.py", line 3789, in write
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\api.py", line 266, in wrapper
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\api.py", line 592, in new_api
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\models.py", line 4048, in _write
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\api.py", line 266, in wrapper
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\models.py", line 5773, in recompute
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\models.py", line 5773, in <dictcomp>
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\models.py", line 5654, in __getitem__
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\fields.py", line 841, in __get__
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\models.py", line 6056, in __getitem__
KeyError: 8

违规行是:

rec.write({'state': 'awaitingraw'})

此方法检查产品线(isbn)是否有足够的数量,如果没有,则继续awaitingraw,如果足够,则转到work_in_progress。但是很奇怪,这个错误是在我添加了这个方法之后(check_quantity之前):

@api.multi
@api.depends('order_picking', 'order_picking.isbn', 'contract_worksheet', 'state')
def accounting_scenarios(self):
    for record in self:
        if not len(record.transporter):
            raise Warning('Please Enter Transporter !')
        elif not len(record.transporter.transp_transit):
            raise Warning('Please assign transit account to the transporter !')
        if record.state in ('awaitingraw'): 
            record.temp = record.contract_worksheet.total_alles - record.contract_worksheet.total_totals
            acc_move = self.env['account.move'] 
            move_lines = [
                (0, 0, {
                    'name': 'name', 
                    'debit': record.temp or 0.0, 
                    'credit': 0, 
                    'account_id': record.transporter.transp_transit.id, 
                    'date': fields.Date.today(), #date,
                    'partner_id': record.transporter.id, # partner if there is one
                    #'currency_id': currency_id or (account.currency_id.id or False),
                }),
                (0, 0, {
                    'name': 'name',
                    'debit': 0, 
                    'credit': record.contract_worksheet.total_alles or 0.0,
                    'account_id': record.transporter.transp_transit.id,
                    #'analytic_account_id': context.get('analytic_id', False),
                    'date': fields.Date.today(), #date,
                    'partner_id': record.transporter.id,
                    #'currency_id': currency_id or (account.currency_id.id or False),
                })
            ]

            journal_id = False
            if record.transporter.transp_transit:
                journals = self.env['account.journal'].search([
                    ('default_debit_account_id', '=', record.transporter.transp_transit.id)
                ])
                if journals:
                    journal_id = journals[0].id
                    acc_move.create({
                    #'period_id': period_id, #Fiscal period
                        'journal_id': journal_id, 
                        'date': fields.Date.today(),
                        'state': 'draft',
                        'line_id': move_lines, 
                    })
            #return move.id
        elif record.state in ('work_in_progress'):
            record.temp2 = record.contract_worksheet.total_totals
        elif record.state in ('delivered'):
            record.transporter.transp_transit.debit = record.contract_worksheet.total_alles

现在似乎可以正常工作了,有什么想法吗?

编辑

此外,当我尝试编辑记录并编辑字段 printer_book_block 时,保存时抛出:

         ValidateError

Error while validating constraint

              8

这是字段:

printer_book_block = fields.Many2one('res.partner', string="Printer Book Block")

编辑 2

似乎问题出在 printer_book_block 之间,它是 Many2oneres.partner,和我正在处理的 class id,序列号id 它在每次创建新记录时存储,我看到这个 8 作为文档的 id,无论我尝试编辑什么,都一样。

报错了,明明就是数字变了,要看我编辑的是哪一个,很费解...

首先,您需要将此行移动到 for 循环内,并从 rec 而不是 self 获取位置。

     for rec in self:
            location = rec.printer_book_block.property_stock_supplier.id

现在我在这里看不到错误,所以你们评论位置并计算所有位置的可用数量,但这个错误仍然存​​在