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'`
# -*- 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)
It may be helpful to add your Odoo version.
You're right. I'm using Odoo 14.0
It works! Thanks a lot.