Skip to Content
Menu
This question has been flagged

Hi,

I'm creating a new module. I've inherited the home method using `CustomerPortal` class in portal controller.

But when I try to visit the route i received the following error: `AttributeError: 'super' object has no attribute 'home'`


Any ideas? Thanks


This is my code 


# -*- coding: utf-8 -*-
import datetime
import logging

import werkzeug
from odoo import http
from odoo.addons.portal.controllers.portal import CustomerPortal
from odoo.http import request

_logger = logging.getLogger(__name__)


class CreateCustomerCode(CustomerPortal):
    @http.route(['/my', '/my/home'], type='http', auth="user", website=True)
    def home(self, **kw):
        partner = request.env.user.partner_id

        easy_connector_customer = request.env['easy_connector.customer'].search(
            [('partner_id', '=', partner.id)])

        if not easy_connector_customer or (easy_connector_customer and easy_connector_customer.code is None):
            last_customer = request.env['easy_connector.customer'].search([
            ])

            if last_customer:
                numeric_code = int(last_customer[-1].numeric_code+ 1
            else:
                numeric_code = 0

            prefix_code = 'W'
            numeric_code = str(numeric_code).zfill(14)
            code = prefix_code + numeric_code

            easy_connector_customer = request.env['easy_connector.customer'].sudo().create({
                'prefix_code': prefix_code,
                'numeric_code': numeric_code,
                'code': code,
                'partner_id': partner.id
            })

            easy_connector_log_message = request.env['easy_connector.log'].compose_message({
                'email': partner.email,
                'customer_code': code,
                'display_name': partner.display_name,
                'vat': partner.vat,
                'city': partner.city,
                'street': partner.street
            })

            easy_connector_log = request.env['easy_connector.log'].sudo().create({
                'easy_connector_customer_id': easy_connector_customer.id,
                'method': 'CUSTOMER_REGISTRATION',
                'message': easy_connector_log_message,
            })

            _logger.info('Added new customer code: %s',
                         code)

        return super(CustomerPortal, self).home(**kw)

Avatar
Discard

It may be helpful to add your Odoo version.

Author

You're right. I'm using Odoo 14.0

Author

It works! Thanks a lot. 

Best Answer

Hi,
Use your class name while supering a function. In your code your class name is “CreateCustomerCode'', but you are using “CustomerPortal” in super. Replace your return statement with following line

return super(CreateCustomerCode, self).home(**kw)

I think this will solve your problem.To know more you can refer the following blog

https://www.cybrosys.com/blog/web-controllers-in-odoo

Regards

Avatar
Discard
Related Posts Replies Views Activity
0
Mar 15
4430
2
Mar 16
7577
0
Jan 17
6107
1
Sep 24
316
1
Jul 24
2791