consider these models:
class bsi_production_order(models.Model):
_name = 'bsi.production.order'
name = fields.Char('Reference', required=True, index=True, copy=False, readonly='True', default='New')
date = fields.Date(string="Production Date")
production_type = fields.Selection([
('budgeted','Budgeted'),
('nonbudgeted','Non Budgeted'),
('direct','Direct Order'),
], string='Type of Order', index=True,
track_visibility='onchange', copy=False,
help=" ")
notes = fields.Text(string="Notes")
order_lines = fields.One2many('bsi.production.order.lines', 'production_order', states={'finished': [('readonly', True)], 'cancel': [('readonly', True)]}, string="Order lines", copy=True)
class bsi_production_order_lines(models.Model):
_name = 'bsi.production.order.lines'
production_order = fields.Many2one('bsi.production.order', string="Production Orders")
isbn = fields.Many2one('product.product', string="ISBN", domain="[('is_isbn', '=', True)]")
qty = fields.Integer(string="Quantity")
consumed_qty = fields.Float(string="Consumed quantity")
remaining_qty = fields.Float(string="Remaining quantity", compute="_remaining_func")
@api.onchange('qty', 'consumed_qty')
def _remaining_func(self):
if self.consumed_qty or self.qty:
self.remaining_qty = self.consumed_qty - self.qty
On bsi.production.order
object I have a One2many
to bsi.production.order.lines
, on this model I have isbn
field, and qty
, which actually is a Many2one
to product.product
object.
I have a button which should check on these lines for the availability per location of this product (isbn).
I saw this method here on SO:
@api.onchange('isbn','source_location')
def product_qty_location_check(self):
if self.isbn and self.source_location:
product = self.isbn
available_qty = product.with_context({'location' : self.source_location.id}).qty_available
print available_qty
But when I try to update my module, after restarting the Odoo process, it says that this line available_qty = product.with_context({'location' : self.source_location.id}).qty_available
has invalid syntax, precisely on .qty_available
.
Anyways, I should print this to view, I don't know if it's the right solution, besides the syntax error.
Any ideas?
The complete traceback:
Traceback (most recent call last):
File "werkzeug\serving.py", line 177, in run_wsgi
File "werkzeug\serving.py", line 165, in execute
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\service\server.py", line 294, in app
return self.app(e, s)
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\service\wsgi_server.py", line 216, in application
return application_unproxied(environ, start_response)
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\service\wsgi_server.py", line 202, in application_unproxied
result = handler(environ, start_response)
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\http.py", line 1299, in __call__
return self.dispatch(environ, start_response)
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\http.py", line 1273, in __call__
return self.app(environ, start_wrapped)
File "werkzeug\wsgi.py", line 579, in __call__
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\http.py", line 1444, in dispatch
ir_http = request.registry['ir.http']
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\http.py", line 355, in registry
return openerp.modules.registry.RegistryManager.get(self.db) if self.db else None
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\modules\registry.py", line 339, in get
update_module)
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\modules\registry.py", line 370, in new
openerp.modules.load_modules(registry._db, force_demo, status, update_module)
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\modules\loading.py", line 351, in load_modules
force, status, report, loaded_modules, update_module)
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\modules\loading.py", line 255, in load_marked_modules
loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks)
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\modules\loading.py", line 143, in load_module_graph
load_openerp_module(package.name)
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\modules\module.py", line 315, in load_openerp_module
__import__('openerp.addons.' + module_name)
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\modules\module.py", line 80, in load_module
mod = imp.load_module('openerp.addons.' + module_part, f, path, descr)
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\addons\mrp_worksheet_contract\__init__.py", line 4, in <module>
from . import models
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\addons\mrp_worksheet_contract\models\__init__.py", line 3, in <module>
from . import models
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\addons\mrp_worksheet_contract\models\models.py", line 165
available_qty = product.with_context({'location' : self.source_location.id}).qty_available
^
SyntaxError: invalid syntax
EDIT
Original question, I think also this would have problems with the field source_location
since I don't have any location specified on my model, could that be fixable?