pycharm-odoo icon indicating copy to clipboard operation
pycharm-odoo copied to clipboard

Unresolved reference while working with mixins

Open jcfernandez-890825 opened this issue 3 years ago • 4 comments

odoo/addons/portal/models/portal_mixin.py image

    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

jcfernandez-890825 avatar Aug 18 '22 17:08 jcfernandez-890825

Hi @jcfernandez-890825

There are some unresolved reference errors in that file:

  1. params['hash'] = self._sign_token(pid) -> unresolved method _sign_token()
  2. groups = super(PortalMixin, self)._notify_get_groups(msg_vals=msg_vals) -> unresolved method _notify_get_groups()
  3. self['partner_id'] -> unresolved file partner_id
  4. access_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.

trinhanhngoc avatar Aug 20 '22 05:08 trinhanhngoc

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']

image

jcfernandez-890825 avatar Aug 20 '22 22:08 jcfernandez-890825

Any ideas for this error? Mixins is one of the things I like to use to avoid model bloating.

jcfernandez-890825 avatar Nov 22 '22 12:11 jcfernandez-890825

@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.

trinhanhngoc avatar Nov 22 '22 17:11 trinhanhngoc