it-projects-llc / saas-addons

Odoo modules for SaaS Businesses. Sale and manage Odoo databases.
https://saas.it-projects.info
151 stars 174 forks source link

KeyError: 'operator_id' #126

Open killday opened 2 years ago

killday commented 2 years ago

When try to register new client

ERROR main_saas odoo.addons.auth_signup_verify_email.controllers.main: 'operator_id' Traceback (most recent call last): File "/odoo14/custom/saas/auth_signup_verify_email/controllers/main.py", line 59, in passwordless_signup sudo_users.signup(values, qcontext.get("token")) File "/odoo14/custom/saas/saas_apps_signup/models/res_users.py", line 31, in signup return self.signup_to_try(values, *args, **kwargs) File "/odoo14/custom/saas/saas_apps_signup/models/res_users.py", line 43, in signup_to_try operator_id = int(values.pop("operator_id")) KeyError: 'operator_id'

killday commented 2 years ago

OK, I managed to fix that, I'm doing the scenario where user choose apps with try now. Database draft is created but contract creation is failing whit the following error:

Traceback (most recent call last): File "/odoo14/odoo14-server/odoo/http.py", line 1470, in _dispatch_nodb result = request.dispatch() File "/odoo14/odoo14-server/odoo/http.py", line 808, in dispatch r = self._call_function(self.params) File "/odoo14/odoo14-server/odoo/http.py", line 362, in _call_function return self.endpoint(*args, *kwargs) File "/odoo14/odoo14-server/odoo/http.py", line 914, in call return self.method(args, kw) File "/odoo14/odoo14-server/odoo/http.py", line 533, in response_wrap response = f(*args, kw) File "/odoo14/custom/saas/queue_job/controllers/main.py", line 73, in runjob self._try_perform_job(env, job) File "/odoo14/custom/saas/queue_job/controllers/main.py", line 32, in _try_perform_job job.perform() File "/odoo14/custom/saas/queue_job/job.py", line 516, in perform self.result = self.func(*tuple(self.args), *self.kwargs) File "/odoo14/custom/saas/saas_apps_signup/models/contract_contract.py", line 163, in _create_build build = template_operator.create_db( File "/odoo14/custom/saas/saas/models/saas_template.py", line 232, in create_db build.create_db( File "/odoo14/custom/saas/saas/models/saas_db.py", line 32, in create_db self.state = 'done' File "/odoo14/odoo14-server/odoo/fields.py", line 1129, in set records.write({self.name: write_value}) File "/odoo14/custom/saas/saas_limit_max_users/models/saas_db.py", line 26, in write return super(SaasDb, self).write(vals) File "/odoo14/custom/saas/saas_domain_names/models/saas_db.py", line 39, in write res = super(SaasDb, self).write(vals) File "/odoo14/custom/saas/saas_build_admin/models/saas_db.py", line 21, in write return super(SaasDb, self).write(vals) File "/odoo14/custom/saas/saas/models/saas_db.py", line 59, in write self.refresh_data() File "/odoo14/custom/saas/saas/models/saas_db.py", line 66, in refresh_data vals = record.read_values_from_build() File "/odoo14/custom/saas/saas_apps_signup/models/saas_db.py", line 36, in read_values_from_build vals = super(SaasDb, self).read_values_from_build() File "/odoo14/custom/saas/saas_limit_max_users/models/saas_db.py", line 59, in read_values_from_build users_count=self.execute_kw( File "/odoo14/custom/saas/saas/models/saas_db.py", line 80, in execute_kw return self.operator_id.build_execute_kw(self, model, method, args, kwargs) File "/odoo14/custom/saas/saas/models/saas_operator.py", line 148, in build_execute_kw return self._build_execute_kw(build.name, model, method, args, kwargs) File "/odoo14/custom/saas/saas_operator_remote/models/saas_operator.py", line 98, in _build_execute_kw return super(SaasOperator, self)._build_execute_kw( File "/odoo14/custom/saas/saas/models/saas_operator.py", line 142, in _build_execute_kw return cluster.execute_kw(db_name, model, method, args, kwargs) File "/odoo14/custom/saas/saas_cluster_simple/main.py", line 124, in execute_kw return execute(db_name, SUPERUSER_ID, model, method, args, kwargs) File "/odoo14/odoo14-server/odoo/service/model.py", line 94, in wrapper return f(dbname, *args, kwargs) File "/odoo14/odoo14-server/odoo/service/model.py", line 175, in execute res = execute_cr(cr, uid, obj, method, *args, *kw) File "/odoo14/odoo14-server/odoo/service/model.py", line 159, in execute_cr result = odoo.api.call_kw(recs, method, args, kw) File "/odoo14/odoo14-server/odoo/api.py", line 395, in call_kw result = _call_kw_model(method, model, args, kwargs) File "/odoo14/odoo14-server/odoo/api.py", line 368, in _call_kw_model result = method(recs, args, kwargs) File "/odoo14/odoo14-server/odoo/models.py", line 1685, in search_count res = self.search(args, count=True) File "/odoo14/odoo14-server/odoo/models.py", line 1708, in search res = self._search(args, offset=offset, limit=limit, order=order, count=count) File "/odoo14/odoo14-server/odoo/addons/base/models/res_users.py", line 539, in _search return super(Users, self)._search(args, offset=offset, limit=limit, order=order, count=count, File "/odoo14/odoo14-server/odoo/models.py", line 4514, in _search query = self._where_calc(args) File "/odoo14/odoo14-server/odoo/models.py", line 4270, in _where_calc return expression.expression(domain, self).query File "/odoo14/odoo14-server/odoo/osv/expression.py", line 442, in init self.parse() File "/odoo14/odoo14-server/odoo/osv/expression.py", line 654, in parse raise ValueError("Invalid field %s.%s in leaf %s" % (model._name, path[0], str(leaf))) Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/werkzeug/serving.py", line 306, in run_wsgi execute(self.server.app) File "/usr/local/lib/python3.8/dist-packages/werkzeug/serving.py", line 294, in execute application_iter = app(environ, start_response) File "/odoo14/odoo14-server/odoo/service/server.py", line 441, in app return self.app(e, s) File "/odoo14/odoo14-server/odoo/service/wsgi_server.py", line 113, in application return application_unproxied(environ, start_response) File "/odoo14/odoo14-server/odoo/service/wsgi_server.py", line 88, in application_unproxied result = odoo.http.root(environ, start_response) File "/odoo14/odoo14-server/odoo/http.py", line 1307, in call return self.dispatch(environ, start_response) File "/odoo14/odoo14-server/odoo/http.py", line 1273, in call return self.app(environ, start_wrapped) File "/usr/local/lib/python3.8/dist-packages/werkzeug/middleware/shared_data.py", line 220, in call return self.app(environ, start_response) File "/odoo14/odoo14-server/odoo/http.py", line 1499, in dispatch result = _dispatch_nodb() File "/odoo14/odoo14-server/odoo/http.py", line 1472, in _dispatch_nodb return request._handle_exception(e) File "/odoo14/odoo14-server/odoo/http.py", line 746, in _handle_exception return super(HttpRequest, self)._handle_exception(exception) File "/odoo14/odoo14-server/odoo/http.py", line 317, in _handle_exception raise exception.with_traceback(None) from new_cause ValueError: Invalid field res.users.is_excluded_from_limiting in leaf ('is_excluded_from_limiting', '=', False) - - -

glupeksha commented 2 years ago

@killday

how did you manager to fix this error?

ERROR main_saas odoo.addons.auth_signup_verify_email.controllers.main: 'operator_id' Traceback (most recent call last): File "/odoo14/custom/saas/auth_signup_verify_email/controllers/main.py", line 59, in passwordless_signup sudo_users.signup(values, qcontext.get("token")) File "/odoo14/custom/saas/saas_apps_signup/models/res_users.py", line 31, in signup return self.signup_to_try(values, *args, **kwargs) File "/odoo14/custom/saas/saas_apps_signup/models/res_users.py", line 43, in signup_to_try operator_id = int(values.pop("operator_id")) KeyError: 'operator_id'

Actually I manager to go through this error by modifying the res.users.signup_to_try() method

def signup_to_try(self, values, *args, **kwargs):
        # popping out values before creating user
        database_name = values.pop("database_name", None)
        installing_modules = values.pop("installing_modules", "").split(",")
        saas_template_id = values.pop("saas_template_id", "")
        max_users_limit = int(values.pop("max_users_limit", 1))
        subscription_period = values.pop("period", "")

        # operator_id is never added to values in the signup process.
        # operator_id = int(values.pop("operator_id"))
        operator_id = int(self.env.ref("saas_apps.base_template")._random_ready_operator_id())
        res = super(ResUsers, self).signup(values, *args, **kwargs)

        if database_name:
            admin_user = self.env['res.users'].sudo().search([('login', '=', res[1])], limit=1)

            build = self.env["saas.db"].create({
                "name": database_name,
                "operator_id": operator_id,
                "admin_user": admin_user.id,
            })

            self.env["contract.contract"]._create_saas_contract_for_trial(
                build, max_users_limit, subscription_period,
                installing_modules=installing_modules,
                saas_template_id=saas_template_id,
            )
        return res

But the problem is, still this build is not added to the user that trying to signup.

glupeksha commented 2 years ago

After referring to #127 and #128 I think the above is not the correct way to fix the issue.

I think the best way to solve this is to edit theget_auth_signup_qcontext() method as in #128. But rather than assigning the template, I think we should keep it empty and assign operator id seperately.

            if template:
                d["operator_id"] = template._random_ready_operator_id()
            else:
                d["operator_id"] = request.env.ref("saas_apps.base_template")._random_ready_operator_id()
killday commented 2 years ago

@killday

how did you manager to fix this error?

ERROR main_saas odoo.addons.auth_signup_verify_email.controllers.main: 'operator_id' Traceback (most recent call last): File "/odoo14/custom/saas/auth_signup_verify_email/controllers/main.py", line 59, in passwordless_signup sudo_users.signup(values, qcontext.get("token")) File "/odoo14/custom/saas/saas_apps_signup/models/res_users.py", line 31, in signup return self.signup_to_try(values, *args, **kwargs) File "/odoo14/custom/saas/saas_apps_signup/models/res_users.py", line 43, in signup_to_try operator_id = int(values.pop("operator_id")) KeyError: 'operator_id'

Actually I manager to go through this error by modifying the res.users.signup_to_try() method

def signup_to_try(self, values, *args, **kwargs):
        # popping out values before creating user
        database_name = values.pop("database_name", None)
        installing_modules = values.pop("installing_modules", "").split(",")
        saas_template_id = values.pop("saas_template_id", "")
        max_users_limit = int(values.pop("max_users_limit", 1))
        subscription_period = values.pop("period", "")

        # operator_id is never added to values in the signup process.
        # operator_id = int(values.pop("operator_id"))
        operator_id = int(self.env.ref("saas_apps.base_template")._random_ready_operator_id())
        res = super(ResUsers, self).signup(values, *args, **kwargs)

        if database_name:
            admin_user = self.env['res.users'].sudo().search([('login', '=', res[1])], limit=1)

            build = self.env["saas.db"].create({
                "name": database_name,
                "operator_id": operator_id,
                "admin_user": admin_user.id,
            })

            self.env["contract.contract"]._create_saas_contract_for_trial(
                build, max_users_limit, subscription_period,
                installing_modules=installing_modules,
                saas_template_id=saas_template_id,
            )
        return res

But the problem is, still this build is not added to the user that trying to signup.

Please see #129