pycharm-odoo
pycharm-odoo copied to clipboard
Unresolved reference while working with mixins
odoo/addons/portal/models/portal_mixin.py

def _notify_get_groups(self, msg_vals=None):
access_token = self._portal_ensure_token()
groups = super(PortalMixin, self)._notify_get_groups(msg_vals=msg_vals)
local_msg_vals = dict(msg_vals or {})
if access_token and 'partner_id' in self._fields and self['partner_id']:
customer = self['partner_id']
local_msg_vals['access_token'] = self.access_token
local_msg_vals.update(customer.signup_get_auth_param()[customer.id])
access_link = self._notify_get_action_link('view', **local_msg_vals)
new_group = [
('portal_customer', lambda pdata: pdata['id'] == customer.id, {
'has_button_access': False,
'button_access': {
'url': access_link,
},
'notification_is_customer': True,
})
]
else:
new_group = []
return new_group + groups
Hi @jcfernandez-890825
There are some unresolved reference errors in that file:
params['hash'] = self._sign_token(pid)-> unresolved method_sign_token()groups = super(PortalMixin, self)._notify_get_groups(msg_vals=msg_vals)-> unresolved method_notify_get_groups()self['partner_id']-> unresolved filepartner_idaccess_link = self._notify_get_action_link('view', **local_msg_vals)-> unresolved method_notify_get_action_link
The errors (1, 2, 4) seem to be Odoo's issues because I don't see their method definitions in the model portal.mixin.
I know, but you can get error 3, if you create a mixin yourself, something like this:
class TrinhAnhNgocMixin(models.AbstractModel):
# Private attributes
_name = 'trinh.anh.ngoc.mixin'
_description = "Trinh Anh Ngoc Mixin"
def show_name(self):
return self['name']

Any ideas for this error? Mixins is one of the things I like to use to avoid model bloating.
@jcfernandez-890825 , I think there are two main problems here:
1. Missing abstract methods in abstract model class
That source code might need to be fixed. For example:
def _notify_get_action_link(link_type, **kwargs):
raise NotImplementedError
def _notify_get_groups(self, msg_vals=None):
...
access_link = self._notify_get_action_link('view', **local_msg_vals)
...
2. Unsupported attribute checking
PyCharm currently supports only attribute checking via hasattr(). For example:
def _notify_get_groups(self, msg_vals=None):
....
if access_token and hasattr(self, 'partner_id'):
customer = self.partner_id
....
I already have plans to improve attribute checking in #205. In the meantime, you can apply the solution using hasattr like the example above.