Skip to content

Simplified logic. - #3

Closed
yajo wants to merge 2 commits into
8.0-quick_create_register_hook_signature_lbfrom
unknown repository
Closed

Simplified logic.#3
yajo wants to merge 2 commits into
8.0-quick_create_register_hook_signature_lbfrom
unknown repository

Conversation

@yajo

@yajo yajo commented Feb 12, 2016

Copy link
Copy Markdown

Code explains better by itself that comments.

Comment thread base_optional_quick_create/model.py Outdated
def _wrap_name_create():
def wrapper(self, cr, uid, name, context=None):
def _wrap_name_create(self, cr, uid, name, context=None):
if self.pool.get(self._name).avoid_quick_create:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @yajo

but avoid_quick_create is not a field of the patched model: it is a field of ir.model.

So, I tried with

    def _patch_quick_create(self, cr, ids):
        def _wrap_name_create(self, cr, uid, name, context=None):
            model_pool = self.pool['ir.model']
            model_record_ids = model_pool.search(cr, uid, [
                ('model', '=', self._name),
                ], context=context)
            model_record = model_pool.browse(
                cr, uid, model_record_ids[0], context)
            if model_record.avoid_quick_create:
                raise orm.except_orm(
                    _('Error'),
                    _("Can't create quickly. Opening create form"))
            else:
                return _wrap_name_create.origin(
                    self, cr, uid, name, context=context)

        for model in self.browse(cr, SUPERUSER_ID, ids):
            self.pool.get(model.model)._patch_method(
                'name_create', _wrap_name_create)

        return True

but got

server-tools/base_optional_quick_create/model.py", line 47, in _wrap_name_create
    self, cr, uid, name, context=context)
TypeError: unbound method name_create() must be called with workflow.workitem instance as first argument (got res.partner.title instance instead)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you try now please?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

server-tools/base_optional_quick_create/model.py", line 41, in wrapper
    return _wrap_name_create.origin(
AttributeError: 'function' object has no attribute 'origin'

@yajo yajo closed this Feb 18, 2016
@yajo
yajo deleted the PR-352 branch February 18, 2016 09:50
eLBati pushed a commit that referenced this pull request Jun 15, 2016
eLBati pushed a commit that referenced this pull request Jun 15, 2016
eLBati pushed a commit that referenced this pull request Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants