Skip to content

[FIX] keep _register_hook's signature and call super - #352

Merged
hbrunn merged 3 commits into
OCA:8.0from
eLBati:8.0-quick_create_register_hook_signature_lb
Feb 13, 2016
Merged

[FIX] keep _register_hook's signature and call super#352
hbrunn merged 3 commits into
OCA:8.0from
eLBati:8.0-quick_create_register_hook_signature_lb

Conversation

@eLBati

@eLBati eLBati commented Feb 5, 2016

Copy link
Copy Markdown
Member

No description provided.

@hbrunn

hbrunn commented Feb 5, 2016

Copy link
Copy Markdown
Member

👍

res_id = super(ir_model, self).create(cr, uid, vals, context=context)
self._register_hook(cr, [res_id])
res_id = super(IrModel, self).create(cr, uid, vals, context=context)
self._patch_quick_create(cr, [res_id])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does it make any sense to patch the creation method after the record has been created?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That is on a different level. After the creation of the model, we patch the model's name_create method which applies when records of that model are being created through the quick create option.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I am not sure to understand.
Consider that this is the create of a new model. That is: when a new model is created, patch its name_create method

Edit: I did not see @StefanRijnhart answer 😏

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Still it does not seem a good trigger point to do it. If you quick-create a record before slow-creating one, it would still enable it.

The logical flow IMHO should be like:

_inherit = 'ir.model'
@api.cr
def _register_hook(self):
  self.search([("avoid_quick_create", "=", True)])._patch_quick_create()
  return super(...)._register_hook()

@api.multi
def _patch_quick_create(self):
  @api.model
  def new_name_create_method(self):
    ...
  for s in self:
    self.env[s.model]._patch_method("name_create", new_name_create)

And add a constraint to avoid_quick_create column that patches or restores the method depending on what changed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Still it does not seem a good trigger point to do it. If you quick-create a record before slow-creating one, it would still enable it

Why? I don't think this happens.

Consider these are the create and write methods of ir.model model, not of the model itself.

For example: when the account.invoice (record of ir.model) is modified, setting avoid_quick_create = True, patch name_create of account.invoice model

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I hope you get my point with eLBati#3. I did not test it, just showing what I mean.

@hbrunn

hbrunn commented Feb 10, 2016

Copy link
Copy Markdown
Member

I'm working on a mixin that simplifies monkey patching and encourages good practices, you might just want to use that: https://github.com/hbrunn/social/blob/8.0-mail_follower_custom_notification/mail_follower_custom_notification/models/base_patch_models_mixin.py - after sufficient testing and review, I'm planning to release the mixin as a module in server-tools. Note: This is development code, use at you own risk

@StefanRijnhart

Copy link
Copy Markdown
Member

👍 tested and code review. Maybe best to leave refactoring using @hbrunn's method once it's ready.

@StefanRijnhart StefanRijnhart added this to the 8.0 milestone Feb 13, 2016
hbrunn added a commit that referenced this pull request Feb 13, 2016
…gnature_lb

[FIX] keep _register_hook's signature and call super
@hbrunn
hbrunn merged commit ecfac1f into OCA:8.0 Feb 13, 2016
StefanRijnhart pushed a commit to StefanRijnhart/server-tools that referenced this pull request Feb 26, 2017
SiesslPhillip pushed a commit to grueneerde/OCA-server-tools that referenced this pull request Nov 20, 2024
Syncing from upstream OCA/server-tools (10.0)
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.

4 participants