So far i had read many questions but i am sure that i am total a mix up because i am unable understand how to use Search at odoo TransientModel.
I had written a code that get Active_ids from self
context=self.env.context.get('active_ids')
I am supposing these actives_ids as
product_tmpl_id but when i tried to use them
product_recs = produtc_obj.search([('product_tmpl_id', 'in', context)])
print(product_recs)
result = {}
for rec in product_recs:
print(rec.default_code )
result[rec.default_code ]
but its always return
result[rec.default_code ]
KeyError: '1'
Here is my full code
import logging
from odoo import models, fields, api
from odoo.exceptions import Warning
_logger = logging.getLogger(__name__)
class product_export_to_rakuten(models.TransientModel):
_name = 'rakuten_ftp.export_product'
#api.multi
def export_products(self):
# check for more than one orders.
# print(self.env)
context=self.env.context.get('active_ids')
produtc_obj = self.env['product.product']
product_recs = produtc_obj.search([('product_tmpl_id', 'in', context)])
print(product_recs)
result = {}
for rec in product_recs:
print(rec.default_code )
result[rec.default_code ]
Here is the Error
Traceback (most recent call last):
File "C:/Odoo_Source_Codes/odoo11\odoo\http.py", line 647, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "C:/Odoo_Source_Codes/odoo11\odoo\http.py", line 307, in _handle_exception
raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
File "C:/Odoo_Source_Codes/odoo11\odoo\tools\pycompat.py", line 87, in reraise
raise value
File "C:/Odoo_Source_Codes/odoo11\odoo\http.py", line 689, in dispatch
result = self._call_function(**self.params)
File "C:/Odoo_Source_Codes/odoo11\odoo\http.py", line 339, in _call_function
return checked_call(self.db, *args, **kwargs)
File "C:/Odoo_Source_Codes/odoo11\odoo\service\model.py", line 97, in wrapper
return f(dbname, *args, **kwargs)
File "C:/Odoo_Source_Codes/odoo11\odoo\http.py", line 332, in checked_call
result = self.endpoint(*a, **kw)
File "C:/Odoo_Source_Codes/odoo11\odoo\http.py", line 933, in __call__
return self.method(*args, **kw)
File "C:/Odoo_Source_Codes/odoo11\odoo\http.py", line 512, in response_wrap
response = f(*args, **kw)
File "C:\Odoo_Source_Codes\odoo11\addons\web\controllers\main.py", line 934, in call_button
action = self._call_kw(model, method, args, {})
File "C:\Odoo_Source_Codes\odoo11\addons\web\controllers\main.py", line 922, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "C:/Odoo_Source_Codes/odoo11\odoo\api.py", line 689, in call_kw
return call_kw_multi(method, model, args, kwargs)
File "C:/Odoo_Source_Codes/odoo11\odoo\api.py", line 680, in call_kw_multi
result = method(recs, *args, **kwargs)
File "C:\Odoo_Source_Codes\odoo11\custom_addons\rakuten_ftp\wizard\export_product.py", line 22, in export_products
result[rec.default_code ]
KeyError: '1'
Everything seems to be fine with the Transient Model, the problem is that you're trying to read a dictionary value whose key doesn't exist yet. I mean, the default_code of the first product you get in the loop is 1, and you're telling Python: I want to read the value of the key 1 of the dictionary result, but this one is empty, so you get the error (you need to fill it in first).
You can reply the error in a Python console, this is what is happening to you:
>>> result = {}
>>> result['1']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: '1'
You should do something like this to make it work:
>>> result = {}
>>> result['1'] = 'Your value' # result.update({'1': 'Your value', })
>>> result['1']
'Your value'
Related
I'm pretty new in Odoo, for the moment I dind't modified any code but this error is persistent when I try to create a new product.
Traceback (most recent call last):
File "/opt/odoo/odoo/odoo/tools/cache.py", line 85, in lookup
r = d[key]
File "/opt/odoo/odoo/odoo/tools/func.py", line 71, in wrapper
return func(self, *args, **kwargs)
File "/opt/odoo/odoo/odoo/tools/lru.py", line 34, in __getitem__
a = self.d[obj]
KeyError: ('product.template', <function ProductTemplate._get_default_category_id at 0x7f77854ab490>)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/odoo/odoo/odoo/tools/cache.py", line 85, in lookup
r = d[key]
File "/opt/odoo/odoo/odoo/tools/func.py", line 71, in wrapper
return func(self, *args, **kwargs)
File "/opt/odoo/odoo/odoo/tools/lru.py", line 34, in __getitem__
a = self.d[obj]
KeyError: ('ir.model.data', <function IrModelData._xmlid_lookup at 0x7f778a47b1c0>, 'product.product_category_all')
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/odoo/odoo/odoo/addons/base/models/ir_http.py", line 237, in _dispatch
result = request.dispatch()
File "/opt/odoo/odoo/odoo/http.py", line 687, in dispatch
result = self._call_function(**self.params)
File "/opt/odoo/odoo/odoo/http.py", line 359, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/opt/odoo/odoo/odoo/service/model.py", line 94, in wrapper
return f(dbname, *args, **kwargs)
File "/opt/odoo/odoo/odoo/http.py", line 348, in checked_call
result = self.endpoint(*a, **kw)
File "/opt/odoo/odoo/odoo/http.py", line 916, in __call__
return self.method(*args, **kw)
File "/opt/odoo/odoo/odoo/http.py", line 535, in response_wrap
response = f(*args, **kw)
File "/opt/odoo/odoo/addons/web/controllers/main.py", line 1347, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/opt/odoo/odoo/addons/web/controllers/main.py", line 1339, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/opt/odoo/odoo/odoo/api.py", line 464, in call_kw
result = _call_kw_multi(method, model, args, kwargs)
File "/opt/odoo/odoo/odoo/api.py", line 451, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "/opt/odoo/odoo/odoo/models.py", line 6356, in onchange
defaults = self.default_get(missing_names)
File "/opt/odoo/odoo/odoo/models.py", line 1410, in default_get
defaults[name] = field.default(self)
File "<decorator-gen-151>", line 2, in _get_default_category_id
File "/opt/odoo/odoo/odoo/tools/cache.py", line 90, in lookup
value = d[key] = self.method(*args, **kwargs)
File "/opt/odoo/odoo/addons/product/models/product_template.py", line 24, in _get_default_category_id
return self.env.ref('product.product_category_all')
File "/opt/odoo/odoo/odoo/api.py", line 578, in ref
res_model, res_id = self['ir.model.data']._xmlid_to_res_model_res_id(
File "/opt/odoo/odoo/odoo/addons/base/models/ir_model.py", line 1935, in _xmlid_to_res_model_res_id
return self._xmlid_lookup(xmlid)[1:3]
File "<decorator-gen-35>", line 2, in _xmlid_lookup
File "/opt/odoo/odoo/odoo/tools/cache.py", line 90, in lookup
value = d[key] = self.method(*args, **kwargs)
File "/opt/odoo/odoo/odoo/addons/base/models/ir_model.py", line 1928, in _xmlid_lookup
raise ValueError('External ID not found in the system: %s' % xmlid)
Exception
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/odoo/odoo/odoo/http.py", line 643, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/opt/odoo/odoo/odoo/http.py", line 301, in _handle_exception
raise exception.with_traceback(None) from new_cause
ValueError: External ID not found in the system: product.product_category_all
A little of backstory, I imported a lot of products, atributes and categories and did some testing deleting and importing again that is probably the origin of the issue.
The external ID product.product_category_all should be one of the default product categories introduced/installed by the app/module "product".
Obviously Odoo is using this one as a default value and you get an error, because it was deleted.
The easiest fix is to just update the app/module "product". Odoo will recreate the category and the error should be gone.
There are three compute functions in my code.
But I got the error.
Odoo Server Error
Traceback (most recent call last):
File "/vagrant/odoo/odoo/addons/base/models/ir_http.py", line 237, in _dispatch
result = request.dispatch()
File "/vagrant/odoo/odoo/http.py", line 682, in dispatch
result = self._call_function(**self.params)
File "/vagrant/odoo/odoo/http.py", line 358, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/vagrant/odoo/odoo/service/model.py", line 94, in wrapper
return f(dbname, *args, **kwargs)
File "/vagrant/odoo/odoo/http.py", line 346, in checked_call
result = self.endpoint(*a, **kw)
File "/vagrant/odoo/odoo/http.py", line 911, in __call__
return self.method(*args, **kw)
File "/vagrant/odoo/odoo/http.py", line 530, in response_wrap
response = f(*args, **kw)
File "/vagrant/odoo/addons/web/controllers/main.py", line 1359, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/vagrant/odoo/addons/web/controllers/main.py", line 1351, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/vagrant/odoo/odoo/api.py", line 396, in call_kw
result = _call_kw_multi(method, model, args, kwargs)
File "/vagrant/odoo/odoo/api.py", line 383, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "/vagrant/odoo/odoo/models.py", line 6165, in onchange
value = record[name]
File "/vagrant/odoo/odoo/models.py", line 5640, in __getitem__
return self._fields[key].__get__(self, type(self))
File "/vagrant/odoo/odoo/fields.py", line 979, in __get__
raise ValueError("Compute method failed to assign %s.%s" % (record, self.name))
Exception
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/vagrant/odoo/odoo/http.py", line 638, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/vagrant/odoo/odoo/http.py", line 314, in _handle_exception
raise exception.with_traceback(None) from new_cause
ValueError: Compute method failed to assign meeting.request(<NewId 0x7f4760a316d8>,).description
I have assigned empty value in my function.
Like self.request_srcmst_names = ''、self.date = ''、self.editable = False
But it still can't work. I don't know which function is wrong.
class MeetingRequest(models.Model):
_name = 'meeting.request'
request_srcmst_names = fields.Char(compute=_compute_request_srcmst_names)
date = fields.Date(compute=compute_date, search=search_date)
#api.depends('request_srcmst_ids')
def _compute_request_srcmst_names(self):
self.request_srcmst_names = ''
for record in self:
name = []
for request_srcmst in record.request_srcmst_ids:
name.append(request_srcmst.meeting_srcmst_id.name)
record.request_srcmst_names = ', '.join(name)
#api.depends('start_date')
def compute_date(self):
self.date = ''
for record in self:
if record.start_date:
real_date = pytz.utc.localize(datetime.datetime.strptime(record.start_date, '%Y-%m-%d %H:%M:%S')).astimezone(pytz.timezone(config['timezone'])).date()
record.date = real_date
class MeetingRequestSrcmst(models.Model):
_name = 'meeting.request.srcmst'
editable = fields.Boolean(compute=_compute_editable)
def _compute_editable(self):
self.editable = False
for record in self:
if record.hre_empbas_id.res_users_id.id == self.env.uid or record.create_uid.id == self.env.uid:
record.editable = True
How can I fix the function? Please give me some suggestions. Thanks!
I think it's syntax error. You forget to put a quote around function name. Computed function name should be inside a quote – compute='compute_date'. So is search function.
In your case,
date = fields.Date(compute='compute_date', search='search_date')
request_srcmst_names = fields.Char(compute='_compute_request_srcmst_names')
Inside your functions for computed fields, you can remove :
self.editable = False
self.date = ''
self.request_srcmst_names = ''
As I can see, you are trying to assign value to a field that does not exist in the database.
Your code:
request_srcmst_names = fields.Char(compute=_compute_request_srcmst_names)
Replace it with below then it will work:
request_srcmst_names = fields.Char(compute='_compute_request_srcmst_names', store=True)
compute field by default has store=False. To make it store you need pass parameter store=True.
Hope the provided solution works for you!
I get this error when I try to upgrade my custom module in odoo 13.
Odoo Server Error
Traceback (most recent call last):
File "/odoo/odoo-server/odoo/http.py", line 619, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/odoo/odoo-server/odoo/http.py", line 309, in _handle_exception
raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
File "/odoo/odoo-server/odoo/tools/pycompat.py", line 14, in reraise
raise value
File "/odoo/odoo-server/odoo/http.py", line 664, in dispatch
result = self._call_function(**self.params)
File "/odoo/odoo-server/odoo/http.py", line 345, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/odoo/odoo-server/odoo/service/model.py", line 93, in wrapper
return f(dbname, *args, **kwargs)
File "/odoo/odoo-server/odoo/http.py", line 338, in checked_call
result = self.endpoint(*a, **kw)
File "/odoo/odoo-server/odoo/http.py", line 910, in __call__
return self.method(*args, **kw)
File "/odoo/odoo-server/odoo/http.py", line 510, in response_wrap
response = f(*args, **kw)
File "/odoo/odoo-server/addons/web/controllers/main.py", line 1324, in call_button
action = self._call_kw(model, method, args, kwargs)
File "/odoo/odoo-server/addons/web/controllers/main.py", line 1312, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/odoo/odoo-server/odoo/api.py", line 387, in call_kw
result = _call_kw_multi(method, model, args, kwargs)
File "/odoo/odoo-server/odoo/api.py", line 374, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "<decorator-gen-64>", line 2, in button_immediate_upgrade
File "/odoo/odoo-server/odoo/addons/base/models/ir_module.py", line 72, in check_and_log
return method(self, *args, **kwargs)
File "/odoo/odoo-server/odoo/addons/base/models/ir_module.py", line 629, in button_immediate_upgrade
return self._button_immediate_function(type(self).button_upgrade)
File "/odoo/odoo-server/odoo/addons/base/models/ir_module.py", line 573, in _button_immediate_function
modules.registry.Registry.new(self._cr.dbname, update_module=True)
File "/odoo/odoo-server/odoo/modules/registry.py", line 86, in new
odoo.modules.load_modules(registry._db, force_demo, status, update_module)
File "/odoo/odoo-server/odoo/modules/loading.py", line 471, in load_modules
env['ir.model.data']._process_end(processed_modules)
File "/odoo/odoo-server/odoo/addons/base/models/ir_model.py", line 1971, in _process_end
record.unlink()
File "/odoo/odoo-server/odoo/addons/base/models/ir_model.py", line 1190, in unlink
table=self.env[selection.field_id.model]._table,
File "/opt/odoo/odoo13/odoo/api.py", line 463, in __getitem__
return self.registry[model_name]._browse(self, (), ())
File "/opt/odoo/odoo13/odoo/modules/registry.py", line 177, in __getitem__
return self.models[model_name]
KeyError: 'sales.terms'
This is the sales.terms model
class SalesTermsAndConditions(models.Model):
_name = 'sales.terms'
_description = 'Terms and Conditions'
_rec_name = 'typex'
new_type = fields.Selection([
('accessories', 'Accessories'),
('glass', 'Glass Work'),
('aluminium', 'Aluminium profiles'),
('projects', 'Projects')
], string='Testing')
d_active = fields.Boolean(string='Active')
notes = fields.Text()
I have a new model named 'sales.terms' I created and I created the corresponding ir.model.access.csv file for it, so I traced down the error and discovered that it isn't the whole model giving causing the error but just the selection field, if i remove the selection field the module upgrades fine.
I am confused as to what might be wrong.
I think there is something missing
class SalesTermsAndConditions(models.Model):
_name = 'sales.terms'
_description = 'Terms and Conditions'
_rec_name = 'typex'
new_type = fields.Selection([
('test', 'Test'),
('atest', 'A test'), // Comma is missing
('accessories', 'Accessories'),
('glass', 'Glass Work'),
('aluminium', 'Aluminium profiles'),
('projects', 'Projects')
], string='Testing')
d_active = fields.Boolean(string='Active')
notes = fields.Text()
Try to remove _rec_name.Replace with some field.
_rec_name = "new_type"
The selection seem to be ok. if you rename new_type does it then upgrade?
Can you look first errors wen you boot odoo or reload modules
The objective is to take the sale date and create a plan for automatic visits, 2 visits per year for three years, and i can do it in older version of odoo but now i get this error.
that worked in openerp 7, but now i want to do it in Odoo 11.0 Python 3, really i don't get it what i missed
class garantias(models.Model):
_name = 'itriplee.garantias'
equipo = fields.Many2one('itriplee.equipos', 'Equipo')
fecha_de_venta = fields.Date('Fecha de Venta', related='equipo.venta', readonly=True)
#api.model
def create(self, vals):
obj_visita = self.pool.get('itriplee.servicio')
obj = self.env['itriplee.garantias']
cliente = obj.cliente.id
fecha_compra = obj.fecha_de_venta
fm = ('%Y-%m-%d')
cantidad_meses = 6
ind = 0
now = datetime.now()
now_str = now.strftime(fm)
now_int = datetime.strptime(now_str, fm)
# fecha_compra_original = datetime.strptime(fecha_compra, fm)
fecha_compra_inicial = datetime.strptime(fecha_compra, fm)
while ind < cantidad_meses:
fecha_6_meses = fecha_compra_inicial + relativedelta(months=6)
if fecha_6_meses >= now_int:
obj_visita.create({'cliente':cliente,'visita':fecha_6_meses,'estado':'confirmar','visitas':obj.id},context=None)
ind = ind + 1
fecha_compra_inicial = fecha_6_meses
return True
and get this error:
Traceback (most recent call last):
File "/home/openerp/odoo-dev/odoo/odoo/http.py", line 651, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/openerp/odoo-dev/odoo/odoo/http.py", line 310, in _handle_exception
raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
File "/home/openerp/odoo-dev/odoo/odoo/tools/pycompat.py", line 87, in reraise
raise value
File "/home/openerp/odoo-dev/odoo/odoo/http.py", line 693, in dispatch
result = self._call_function(**self.params)
File "/home/openerp/odoo-dev/odoo/odoo/http.py", line 342, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/openerp/odoo-dev/odoo/odoo/service/model.py", line 97, in wrapper
return f(dbname, *args, **kwargs)
File "/home/openerp/odoo-dev/odoo/odoo/http.py", line 335, in checked_call
result = self.endpoint(*a, **kw)
File "/home/openerp/odoo-dev/odoo/odoo/http.py", line 937, in __call__
return self.method(*args, **kw)
File "/home/openerp/odoo-dev/odoo/odoo/http.py", line 515, in response_wrap
response = f(*args, **kw)
File "/home/openerp/odoo-dev/odoo/addons/web/controllers/main.py", line 934, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/home/openerp/odoo-dev/odoo/addons/web/controllers/main.py", line 926, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/home/openerp/odoo-dev/odoo/odoo/api.py", line 687, in call_kw
return call_kw_model(method, model, args, kwargs)
File "/home/openerp/odoo-dev/odoo/odoo/api.py", line 672, in call_kw_model
result = method(recs, *args, **kwargs)
File "/home/openerp/odoo-dev/odoo/addons/itriplee/models/garantias.py", line 53, in create
fecha_compra_inicial = datetime.strptime(fecha_compra, fm).date()
TypeError: strptime() argument 1 must be str, not bool
This error occurs when that field is not date string or it contains null value, so it returns False value when it is called.So first make sure that field contains date str when function is called.strptime method requires date string value.
You can use if condition to check whether data is present in field continue strptime method or if you're using pycharm you can add breakpoint to check values
I'm migrating some modules from v7 to v10 of Odoo community version.
Right now, I've modified this method, it looks like this:
class ResPartner(models.Model):
_inherit = 'res.partner'
#api.multi
#api.depends('company_id')
def _get_country_code(self):
"""
Return the country code of the user company. If not exists, return XX.
"""
context = dict(self._context or {})
user_company = self.env['res.users'].browse(company_id)
return user_company.partner_id and user_company.partner_id.country_id \
and user_company.partner_id.country_id.code or 'XX'
But every time I try to go to a res.partner view, it throws me this error:
Odoo Server Error
Traceback (most recent call last):
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 638, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 675, in dispatch
result = self._call_function(**self.params)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 331, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/service/model.py", line 119, in wrapper
return f(dbname, *args, **kwargs)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 324, in checked_call
result = self.endpoint(*a, **kw)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 933, in __call__
return self.method(*args, **kw)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 504, in response_wrap
response = f(*args, **kw)
File "/home/kristian/odoov10/odoo-10.0rc1c-20161005/odoo/addons/web/controllers/main.py", line 862, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/home/kristian/odoov10/odoo-10.0rc1c-20161005/odoo/addons/web/controllers/main.py", line 854, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/api.py", line 681, in call_kw
return call_kw_multi(method, model, args, kwargs)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/api.py", line 672, in call_kw_multi
result = method(recs, *args, **kwargs)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/models.py", line 2995, in read
values[name] = field.convert_to_read(record[name], record, use_name_get)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/models.py", line 5171, in __getitem__
return self._fields[key].__get__(self, type(self))
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/fields.py", line 860, in __get__
self.determine_value(record)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/fields.py", line 969, in determine_value
self.compute_value(recs)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/fields.py", line 924, in compute_value
self._compute_value(records)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/fields.py", line 918, in _compute_value
self.compute(records)
File "/home/kristian/odoov10/gilda/l10n_ve_fiscal_requirements/model/partner.py", line 72, in _get_uid_country
res = {}.fromkeys(self._get_country_code())
File "/home/kristian/odoov10/gilda/l10n_ve_fiscal_requirements/model/partner.py", line 51, in _get_country_code
user_company = self.env['res.users'].browse(company_id)
NameError: global name 'company_id' is not defined
I'm new into v10 API
Any ideas?
It's give you following error:
ValueError: Expected singleton: res.partner(1, 33, 8, 18, 22, 23)'
I think, you have added field in list/tree view. As per your current code, you didn't iterate record-sets.
If you want to keep your original code with improvements self.company_id then we should remove field from list/tree view. Other then you can move forward with my answer. It will work fine.
Try with following code:
#api.depends('company_id')
def _get_country_code(self):
"""
Return the country code of the user company. If not exists, return XX.
"""
context = dict(self._context or {})
for partner in self:
user_company = self.env['res.company'].browse(self.company_id)
#NOTE: replace code name with your real field name where you want to see value
partner.code = user_company.partner_id and user_company.partner_id.country_id \
and user_company.partner_id.country_id.code or 'XX'
You need to access company_id as a member
user_company = self.env['res.users'].browse(self.company_id)
#NeoVe,
but now it says 'raise ValueError("Expected singleton: %s" % self) ValueError: Expected singleton: res.partner(1, 33, 8, 18, 22, 23)' :/ Do You know why please?
you can try adding #api.one or #api.model decorator instead of #api.multi for the function declaration.