Odoo 8 -Browse a model in Object Class - class

I have Object class and i need to browse the model document.directory in this class. I tried this.
class node_database(object):
obj=openerp.registry(cr.dbname).get('document.directory')
print'obj',obj # it ptints document.directory
datas=obj.browse(cr,uid,ids)
print'datas',datas # Here nothing print
and also tried this:
osv_pool = pooler.get_pool(dbname)
dir_obj=osv_pool.get('document.directory')
Search function works fine but browse not?
Getting this error:
2016-06-24 06:41:52,690 9427 ERROR dms1 openerp.addons.document_ftp.ftpserver: Traceback (most recent call last):
File "/home/kabeer/odoo-8.0-20151229/openerp/addons/document_ftp/ftpserver/ftpserver.py", line 1806, in try_as_current_user
re=self.run_as_current_user(function, *args, **kwargs)
File "/home/kabeer/odoo-8.0-20151229/openerp/addons/document_ftp/ftpserver/ftpserver.py", line 1779, in run_as_current_user
return function(*args, **kwargs)
File "/home/kabeer/odoo-8.0-20151229/openerp/addons/document_ftp/ftpserver/abstracted_fs.py", line 509, in get_list_dir
listing = self.listdir(datacr)
File "/home/kabeer/odoo-8.0-20151229/openerp/addons/document_ftp/ftpserver/abstracted_fs.py", line 377, in listdir
res = node.children(cr)
File "/home/kabeer/odoo-8.0-20151229/openerp/addons/document/document.py", line 981, in children
res = self._child_get(cr, domain=domain) + self._file_get(cr)
File "/home/kabeer/odoo-8.0-20151229/openerp/addons/document/document.py", line 1022, in _child_get
print'cntobj_search_read',cntobj.search_read(cr, uid,[('id','=',1)],['name'],context=ctx)
File "/home/kabeer/odoo-8.0-20151229/openerp/api.py", line 256, in wrapper
return old_api(self, *args, **kwargs)
File "/home/kabeer/odoo-8.0-20151229/openerp/models.py", line 5186, in search_read
result = self.read(cr, uid, record_ids, fields, context=read_ctx)
File "/home/kabeer/odoo-8.0-20151229/openerp/api.py", line 256, in wrapper
return old_api(self, *args, **kwargs)
File "/home/kabeer/odoo-8.0-20151229/openerp/models.py", line 3144, in read
records = self.browse(cr, user, ids, context)
File "/home/kabeer/odoo-8.0-20151229/openerp/api.py", line 256, in wrapper
return old_api(self, *args, **kwargs)
File "/home/kabeer/odoo-8.0-20151229/openerp/models.py", line 5266, in browse
return self._browse(Environment(cr, uid, context or {}), ids)
File "/home/kabeer/odoo-8.0-20151229/openerp/api.py", line 740, in __new__
env, envs = None, cls.envs
File "/home/kabeer/odoo-8.0-20151229/openerp/tools/func.py", line 109, in __get__
return self.fget.__get__(None, owner)()
File "/home/kabeer/odoo-8.0-20151229/openerp/api.py", line 713, in envs
return cls._local.environments
File "/usr/lib/python2.7/dist-packages/werkzeug/local.py", line 71, in __getattr__
raise AttributeError(name)
AttributeError: environments
Any solution pls?

for item in obj.search(cr, uid, []):
obj = self.browse(cr, uid, item)
print obj.name

Resolved this issue by create a new cursor.
new_cr = openerp.sql_db.db_connect(self.context.cr.dbname).cursor()
uid, context = self.context.uid, self.context.context
with api.Environment.manage():
self.env = api.Environment(new_cr, uid, context)
try:
datas=obj.browse(cr,uid,ids)
print'datas',datas # Here print
finally:
self.env.cr.close()

Related

Error when using find/find_one pymongo methods when on an apache2 server (mongodb atlas)

when using find/find_one pymongo methods when on an apache2 server i get the following error :
No <class 'cryptography.x509.extensions.TLSFeature'> extension was found
when using pymongo on an apache2 server to connect and insert or delete in my mongodb collections it works just fine, but when i try to pull something out of the database (using find or find_one methods) i get an error, please note that this error only occurs while running the apache2 server, because when i connected and used find methods in a locally run python script it gave me the information without any errors.
if it is of any relevance, the web framework i am using is flask.
Edit : As for what is producing the error i dont know for sure, so here are the logs.
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 2525, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1822, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1820, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1796, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
File "/var/www/html/srv21/SRVApp.py", line 17, in downloadpage
ThreadID = ThreadID.next()
File "/usr/local/lib/python3.10/dist-packages/pymongo/cursor.py", line 1248, in next
if len(self.__data) or self._refresh():
File "/usr/local/lib/python3.10/dist-packages/pymongo/cursor.py", line 1165, in _refresh
self.__send_message(q)
File "/usr/local/lib/python3.10/dist-packages/pymongo/cursor.py", line 1052, in __send_message
response = client._run_operation(
File "/usr/local/lib/python3.10/dist-packages/pymongo/_csot.py", line 105, in csot_wrapper
return func(self, *args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/pymongo/mongo_client.py", line 1330, in _run_operation
return self._retryable_read(
File "/usr/local/lib/python3.10/dist-packages/pymongo/_csot.py", line 105, in csot_wrapper
return func(self, *args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/pymongo/mongo_client.py", line 1442, in _retryable_read
with self._socket_from_server(read_pref, server, session) as (sock_info, read_pref):
File "/usr/lib/python3.10/contextlib.py", line 135, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.10/dist-packages/pymongo/mongo_client.py", line 1282, in _socket_from_server
with self._get_socket(server, session) as sock_info:
File "/usr/lib/python3.10/contextlib.py", line 135, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.10/dist-packages/pymongo/mongo_client.py", line 1217, in _get_socket
with server.get_socket(handler=err_handler) as sock_info:
File "/usr/lib/python3.10/contextlib.py", line 135, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.10/dist-packages/pymongo/pool.py", line 1407, in get_socket
sock_info = self._get_socket(handler=handler)
File "/usr/local/lib/python3.10/dist-packages/pymongo/pool.py", line 1520, in _get_socket
sock_info = self.connect(handler=handler)
File "/usr/local/lib/python3.10/dist-packages/pymongo/pool.py", line 1358, in connect
sock = _configured_socket(self.address, self.opts)
File "/usr/local/lib/python3.10/dist-packages/pymongo/pool.py", line 1061, in _configured_socket
sock = ssl_context.wrap_socket(sock, server_hostname=host)
File "/usr/local/lib/python3.10/dist-packages/pymongo/pyopenssl_context.py", line 369, in wrap_socket
ssl_conn.do_handshake()
File "/usr/local/lib/python3.10/dist-packages/pymongo/pyopenssl_context.py", line 125, in do_handshake
return self._call(super(_sslConn, self).do_handshake, *args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/pymongo/pyopenssl_context.py", line 108, in _call
return call(*args, **kwargs)
File "/usr/lib/python3/dist-packages/OpenSSL/SSL.py", line 1894, in do_handshake
self._raise_ssl_error(self._ssl, result)
File "/usr/lib/python3/dist-packages/OpenSSL/SSL.py", line 1603, in _raise_ssl_error
self._context._ocsp_helper.raise_if_problem()
File "/usr/lib/python3/dist-packages/OpenSSL/SSL.py", line 319, in raise_if_problem
raise self._problems.pop(0)
File "/usr/lib/python3/dist-packages/OpenSSL/SSL.py", line 539, in wrapper
valid = callback(conn, ocsp_data, data)
File "/usr/local/lib/python3.10/dist-packages/pymongo/ocsp_support.py", line 298, in _ocsp_callback
ext = _get_extension(cert, _TLSFeature)
File "/usr/local/lib/python3.10/dist-packages/pymongo/ocsp_support.py", line 114, in _get_extension
return cert.extensions.get_extension_for_class(klass)
File "/usr/local/lib/python3.10/dist-packages/cryptography/x509/extensions.py", line 135, in get_extension_for_class
raise ExtensionNotFound(
cryptography.x509.extensions.ExtensionNotFound: No <class 'cryptography.x509.extensions.TLSFeature'> extension was found

DRF - Getting 'NoneType object is not callable' error on delete instance from ModelViewSet

I am getting TypeError, when I try to delete Warehouse instance.
Note: If I delete Shop instance, Warehouse under that Shop needs be deleted, that's why I used on_delete=models.CASCADE.
class Warehouse(models.Model):
"""Warehouse model"""
name = models.CharField(max_length=255)
shop = models.ForeignKey(Shop, on_delete=models.CASCADE)
class WarehouseViewSet(viewsets.ModelViewSet):
"""Viewset"""
queryset = models.Warehouse.objects.all()
serializer_class = serializers.WarehouseSerializer
Error:
TypeError: 'NoneType' object is not callable
[14/Feb/2021 22:10:46] "DELETE /api/v1/shop/warehouse/2/ HTTP/1.1" 500 113266
Internal Server Error: /api/v1/shop/warehouse/2/
Traceback (most recent call last):
File "C:\Python38\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Python38\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Python38\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Python38\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "C:\Python38\lib\site-packages\rest_framework\viewsets.py", line 114, in view
return self.dispatch(request, *args, **kwargs)
File "C:\Python38\lib\site-packages\rest_framework\views.py", line 505, in dispatch
response = self.handle_exception(exc)
File "C:\Python38\lib\site-packages\rest_framework\views.py", line 465, in handle_exception
self.raise_uncaught_exception(exc)
File "C:\Python38\lib\site-packages\rest_framework\views.py", line 476, in raise_uncaught_exception
raise exc
File "C:\Python38\lib\site-packages\rest_framework\views.py", line 502, in dispatch
response = handler(request, *args, **kwargs)
File "C:\Python38\lib\site-packages\rest_framework\mixins.py", line 91, in destroy
self.perform_destroy(instance)
File "C:\Python38\lib\site-packages\rest_framework\mixins.py", line 95, in perform_destroy
instance.delete()
File "C:\Python38\lib\site-packages\django\db\models\base.py", line 921, in delete
collector.collect([self], keep_parents=keep_parents)
File "C:\Python38\lib\site-packages\django\db\models\deletion.py", line 224, in collect
field.remote_field.on_delete(self, field, sub_objs, self.using)
Found the solution. I did not handle on_delete for Children model.
SOLUTION
class WarehouseChildren(models.Model):
data = models.PositiveIntegerField(default=0)
warehouse = models.ForeignKey(Warehouse, on_delete=models.SET_NULL, null=True)
or
class WarehouseChildren(models.Model):
data = models.PositiveIntegerField(default=0)
warehouse = models.ForeignKey(Warehouse, on_delete=models.CASCADE)

PonyORM with mixins with custom hash

I have a (in this case) mixin class that defines its own hash and eq. When mixing this into a Pony Entity evil things happen:
from pony.orm import Database, Optional, Required
db = Database()
class RoleMixin:
def __hash__(self):
return hash(self.name)
def __eq__(self, other):
return self.name == other or self.name == getattr(other, "name", None)
def get_permissions(self):
if self.permissions:
return self.permissions
return set()
class Role(db.Entity, RoleMixin):
name = Required(str, unique=True)
description = Optional(str, nullable=True)
permissions = Optional(str, nullable=True)
db.bind("sqlite", ":memory:", create_db=True)
db.generate_mapping(create_tables=True)
role = Role(name="admin")
print(role)
And when running this:
File "/Users/jwag/fs/py3.7env/lib/python3.7/site-packages/pony/utils/utils.py", line 78, in cut_traceback
reraise(exc_type, exc, full_tb)
File "/Users/jwag/fs/py3.7env/lib/python3.7/site-packages/pony/utils/utils.py", line 95, in reraise
try: raise exc.with_traceback(tb)
File "/Users/jwag/fs/py3.7env/lib/python3.7/site-packages/pony/utils/utils.py", line 61, in cut_traceback
try: return func(*args, **kwargs)
File "/Users/jwag/fs/py3.7env/lib/python3.7/site-packages/pony/orm/core.py", line 4721, in __init__
entity._get_from_identity_map_(pkval, 'created', undo_funcs=undo_funcs, obj_to_init=obj)
File "/Users/jwag/fs/py3.7env/lib/python3.7/site-packages/pony/orm/core.py", line 4416, in _get_from_identity_map_
cache.objects.add(obj)
File "/Users/jwag/fs/flask-security/flask_security/ponydbg.py", line 8, in __hash__
return hash(self.name)
File "<string>", line 2, in __get__
File "/Users/jwag/fs/py3.7env/lib/python3.7/site-packages/pony/utils/utils.py", line 78, in cut_traceback
reraise(exc_type, exc, full_tb)
File "/Users/jwag/fs/py3.7env/lib/python3.7/site-packages/pony/utils/utils.py", line 95, in reraise
try: raise exc.with_traceback(tb)
File "/Users/jwag/fs/py3.7env/lib/python3.7/site-packages/pony/utils/utils.py", line 61, in cut_traceback
try: return func(*args, **kwargs)
File "/Users/jwag/fs/py3.7env/lib/python3.7/site-packages/pony/orm/core.py", line 2278, in __get__
value = attr.get(obj)
File "/Users/jwag/fs/py3.7env/lib/python3.7/site-packages/pony/orm/core.py", line 2286, in get
vals = obj._vals_
AttributeError: _vals_
Since Pony is using meta-programming - I can't really figure out where/why it is using hash and why defining it confuses it so much.
Any thoughts?
You may have an '#classmethod' decorator before your mixin class methods.
class RoleMixin:
#classmethod
def __hash__(cls):
return hash(cls.name)
#classmethod
def __eq__(cls, other):
return cls.name == other or cls.name == getattr(other, "name", None)
#classmethod
def get_permissions(cls):
if cls.permissions:
return cls.permissions
return set()

Odoo - outgoing email KeyError: 'body'

In Odoo 9 community outgoing email used to work (smtp configured, etc.), but now I get the following error when trying to send any email (invoice, internal note, etc.) from any account, for any template.
Things I changed since it worked that might (or might not) be linked to this issue:
I installed and uninstalled the SMTP Server Per User plugin
I changed the "from: " email address in the email templates
Any clue why this occurs? Or any clue what this "body" key is and where it is supposed to be defined? Thanks!
Odoo Server Error
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 605, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 642, in dispatch
result = self._call_function(**self.params)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 316, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 118, in wrapper
return f(dbname, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 309, in checked_call
result = self.endpoint(*a, **kw)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 893, in __call__
return self.method(*args, **kw)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 471, in response_wrap
response = f(*args, **kw)
File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 998, in call_button
action = self._call_kw(model, method, args, {})
File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 986, in _call_kw
return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 238, in wrapper
return old_api(self, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 369, in old_api
result = method(recs, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/addons/mail/wizard/mail_compose_message.py", line 191, in send_mail_action
return self.send_mail()
File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 236, in wrapper
return new_api(self, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/addons/account/models/account_invoice.py", line 1306, in send_mail
return super(MailComposeMessage, self).send_mail(auto_commit=auto_commit)
File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 236, in wrapper
return new_api(self, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/addons/mail/wizard/mail_compose_message.py", line 248, in send_mail
ActiveModel.browse(res_id).message_post(message_type='comment', subtype=subtype, **mail_values)
File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 236, in wrapper
return new_api(self, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/addons/mail/models/mail_thread.py", line 1712, in message_post
new_message = MailMessage.create(values)
File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 236, in wrapper
return new_api(self, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/addons/mail/models/mail_message.py", line 864, in create
user_signature=self.env.context.get('mail_notify_user_signature', True))
File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 236, in wrapper
return new_api(self, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/addons/mail/models/mail_message.py", line 926, in _notify
partners._notify(self, force_send=force_send, user_signature=user_signature)
File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 236, in wrapper
return new_api(self, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/addons/mail/models/res_partner.py", line 127, in _notify
('notify_email', '!=', 'none')])._notify_by_email(message, force_send=force_send, user_signature=user_signature)
File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 236, in wrapper
return new_api(self, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/addons/mail/models/res_partner.py", line 178, in _notify_by_email
new_emails, new_recipients_nbr = self._notify_send(not_values['body'], not_values['subject'], recipient_template_values['not_followers'], **base_mail_values)
KeyError: 'body'
#v11 odoo community
Solved Error : Odoo - outgoing email KeyError: 'body'
When Other User sends message on contacts page it gives outgoing email KeyError: 'body'.
This Error is occur from Mail Template : [mail module /data/ mail_data.xml]
so change Your Template Body code Or You Can Also inherit Mail Template:
Remove extra content in this mail_data.xml file.
% if ctx.get('website_url'):
% endif
Only This code Work Properly :
<p style="color: #555555;">
Sent by
% if ctx.get('website_url'):
<a href="${ctx['website_url']}" style="text-decoration:none; color: #875A7B;">
% endif
${ctx.get('company_name')}
</a>
using
<a target="_blank" href="https://www.odoo.com" style="text-decoration:none; color: #875A7B;">Odoo</a>.
</p>
Also Reference : https://i.stack.imgur.com/h8yMK.png
I did not solve the issue myself, but the person who did told me it came from a translation file and an "<" sign that was interpreted as a smaller than in the python code. So he changed the translation file to remove the smaller than.

django-categories - cannot add parent category

I've just installed django-categories to my Mezzanine CMS and I cannot use it. Here is description:
installation: pip install django-categories >> added "categories" and categories.editor in settings.py >> python manage.py syncdb >> python manage.py migrate
I go to the admin page and select the Categories from the left menu (url: http://localhost:8000/admin/categories/ ) => as this is first run, there are no categories => I click "+Add" => give a name for the new category => click SAVE and I get the following error:
Traceback:
File "/home/user1/.envs/bs-3/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/user1/.envs/bs-3/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/user1/.envs/bs-3/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/user1/.envs/bs-3/local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/home/user1/.envs/bs-3/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
return view(request, *args, **kwargs)
File "/home/user1/.envs/bs-3/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
return bound_func(*args, **kwargs)
File "/home/user1/.envs/bs-3/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/user1/.envs/bs-3/local/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
return func(self, *args2, **kwargs2)
File "/home/user1/.envs/bs-3/local/lib/python2.7/site-packages/django/db/transaction.py" in inner
return func(*args, **kwargs)
File "/home/user1/.envs/bs-3/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in add_view
if form.is_valid():
File "/home/user1/.envs/bs-3/local/lib/python2.7/site-packages/django/forms/forms.py" in is_valid
return self.is_bound and not bool(self.errors)
File "/home/user1/.envs/bs-3/local/lib/python2.7/site-packages/django/forms/forms.py" in errors
self.full_clean()
File "/home/user1/.envs/bs-3/local/lib/python2.7/site-packages/django/forms/forms.py" in full_clean
self._clean_form()
File "/home/user1/.envs/bs-3/local/lib/python2.7/site-packages/django/forms/forms.py" in _clean_form
self.cleaned_data = self.clean()
File "/home/user1/.envs/bs-3/local/lib/python2.7/site-packages/categories/base.py" in clean
decendant_ids = self.instance.get_descendants().values_list('id', flat=True)
File "/home/user1/.envs/bs-3/local/lib/python2.7/site-packages/mptt/models.py" in _fn
% {'function': func.name, 'class': self.class.name}
Exception Type: ValueError at /admin/categories/category/add/
Exception Value: Cannot call get_descendants on unsaved Category instances
Any ideas ?
Thank you !
GG