[FIX] keep _register_hook's signature and call super - #352
Conversation
|
👍 |
| 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]) |
There was a problem hiding this comment.
Does it make any sense to patch the creation method after the record has been created?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 😏
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
I hope you get my point with eLBati#3. I did not test it, just showing what I mean.
|
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 |
|
👍 tested and code review. Maybe best to leave refactoring using @hbrunn's method once it's ready. |
…gnature_lb [FIX] keep _register_hook's signature and call super
minor improvements to README.rst
Syncing from upstream OCA/server-tools (10.0)
No description provided.