Reputation: 3907
On this method:
@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',})
It throws me this:
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
The offending line is:
rec.write({'state': 'awaitingraw'})
This method checks for lines of products (isbn) to see if there's enough quantity, if not, it goes on awaitingraw
, if there is enough, then it goes to work_in_progress
. but it's very weird, the error comes after I added this method (before 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
Which seems to be working now, so, Any ideas?
EDIT
Also, when I try to edit the record, and edit the field printer_book_block
, on save it throws:
ValidateError
Error while validating constraint
8
This is the field:
printer_book_block = fields.Many2one('res.partner', string="Printer Book Block")
EDIT 2
Seems like the problem is something between the printer_book_block
which is a Many2one
to res.partner
, and the class id on which I'm working, the serial id it stores every time a new record is created, I saw this 8
as the id of the document, and same goes for whichever I try to edit,.
The error happens, and it just changes the number obviously, depending on which one I'm editing, very puzzling...
Upvotes: 1
Views: 967
Reputation: 14751
First of all you need to move this line inside the for loop and get the location from the rec
not self
.
for rec in self:
location = rec.printer_book_block.property_stock_supplier.id
Now i don't see the error here so of you comment the location and count available qantity in all location doe's this error still raise
Upvotes: 1