New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ADD] crm_claim_ref_smartbutton: Smart-button for referenced claims #38
Conversation
4179aa2
to
472b5b6
Compare
@StefanRijnhart, I think you would enjoy this piece of code. |
Smart-button for referenced claims ================================== This module adds an smart-button in the models that can be referenced in a claim with the number of linked claims and a shortcut to them. Usage ===== Go to any record that can be referenced in a claim, and you will see in a smart-button called _linked claims_ a number indicating the number of claims that reference this record. Clicking on the button, it will navigate to a list of these claims. If you click _New_ on the claim list, the created claim will be automatically linked to the referenced record. Known issues / Roadmap ====================== * The check for seeing if the opened model is one of the possible referenced models is done on each view request, so this hits very little, but a bit, the overall performance of the system.
472b5b6
to
32972d6
Compare
Tested functionally on runbot, it works |
👍 |
There's an error opening "My dashboard" menu entry that it's solved in this PR to Odoo: odoo/odoo#7855 |
Patch merged on Odoo, so everything is OK! |
Added tests! |
@pedrobaeza tests are failing |
self.assertTrue( | ||
xml_field, "Smart-button not added to %s view" % model_name) | ||
# Test the smart-button existence for a model not linked | ||
for model in self.env['ir.model'].search(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you have to put []
in order to search every model?
3118753
to
19afa24
Compare
Sorry, unfinished code was submitted. |
], | ||
"category": "Customer Relationship Management", | ||
"installable": True, | ||
"pre_init_hook": "pre_init_hook", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pedrobaeza hooks are only called at installation time not each time the server start. Therefore your monkey-patch will be only applied once. IOW your patch will no more be applied after the first time your sever will be restarted after the installation. odoo/odoo@4105b5f#diff-9f65b6631806b04e785c2acdf3854285R151
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pedrobaeza The solution is may be to create a fake model and implement the _register_hook method to apply your monkey patch each time the module is loaded in the registry at startup time. https://github.com/odoo/odoo/blob/8.0/openerp/modules/loading.py#L446
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're only seeing half of the solution. This is the possible scenarios:
- You can start without the module copied in the addons path before the server starts.
- Or have it copied in addons path and start the server. This code prevents the monkey-patching: https://github.com/OCA/crm/pull/38/files#diff-df883f43bfa35a2a786daa20cc741e74R103
- When you install the module, in one or another case, the monkey-patching is done via the pre-hook script (https://github.com/OCA/crm/pull/38/files#diff-ec1e94af671fc87f2d489b43471edae2R14).
- Next time you start the server, the same line that previously prevents the monkey-patching, now does it (https://github.com/OCA/crm/pull/38/files#diff-df883f43bfa35a2a786daa20cc741e74R103).
- When you uninstall the module, the monkey-patching is undone here: https://github.com/OCA/crm/pull/38/files#diff-ec1e94af671fc87f2d489b43471edae2R20
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pedrobaeza Sorry for the noise.. haven't see the full solution. IMO, the solution can be simplified by monkey-patching in a _register_hook BaseModel in a fake non stored Model. In this way we no more need the pre_init_hook and monkey patching is done in one place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you draft the proposition with the fake model? Take into account that this module can cover any linkable model in claims.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class CrmClaimMonkeyPatcher(models.TransientModel):
_name = 'cr.claim.mockey.patcher'
_auto = False # doesn't create table in database
def _register_hook(self, cr):
BaseModel.base_fields_view_get = base_fields_view_get
BaseModel.fields_view_get = fields_view_get_crm_claim
cb576be
to
2984d91
Compare
I have followed @lmignon's advice and implement the monkey-patching in a model with _auto=False and now the monkey-patching is only done when the module is installed, and now is multi-db aware thanks to a list that registers the dbs where the module is installed. |
…dule is not installed
2984d91
to
dd1d789
Compare
@antespi you can check now |
Smart-button for referenced claims | ||
================================== | ||
|
||
This module adds an smart-button in the models that can be referenced in a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/ an / a /
All remarks are solved, so this is ready to be merged. |
@pedrobaeza nice solution. But the full table scan on How about monkey patching only existing models' Then some details like adding/removing the patch in |
@pedrobaeza I think you should answer @hbrunn and I will make a test in runbot in order to merge. OK? |
Tested un runbot 👍 |
Hi, could we merge this one? I think it could be very usefull have it available to use instead of staying as PR. |
@anajuaristi, there's already some suggestions on how to implement certain things that I haven't applied yet due to lack of time, so better to stay as a PR yet. |
Agree with @hbrunn mainly about the monkeypatching (that will 'affect' instances with this module sitting uninstalled in the module path. Setting to WIP as per @pedrobaeza's last comment. |
BTW. can a project admin create milestones for the older releases, so that we don't have to use the tag? |
cc @Tecnativa |
from lxml import etree | ||
|
||
|
||
base_fields_view_get = models.BaseModel.fields_view_get |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the monkeypatch?
Did you know you can inherit BaseModel Normally right?
BTW, due to this has an static folder this code will try to be executed.
Can you try do the feature without monkeypatch?
IOH: This kind of changes without tests (changes that modifiy the general behavior of odoo) are really dangerous, I prefer some minimal test cases . |
Monkeypatched for me is a 👎 but it is a 👍 for the functionality. |
It's a WIP still, @nhomar. I will use another technique. |
This is a WIP, @pedrobaeza are you going to continue it? |
Bugs are tracked on `GitHub Issues <https://github.com/OCA/crm/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback | ||
`here <https://github.com/OCA/crm/issues/new?body=module:%20crm_claim_ref_smartbutton%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update with beautier newer template 😊
I guess you would like to finish this PR but will it be possible? Anyone can take this work and try to finish it? |
Smart-button for referenced claims
This module adds an smart-button in the models that can be referenced in a
claim with the number of linked claims and a shortcut to them.
Usage
Go to any record that can be referenced in a claim, and you will see in a
smart-button called linked claims a number indicating the number of
claims that reference this record. Clicking on the button, it will navigate
to a list of these claims.
If you click New on the claim list, the created claim will be automatically
linked to the referenced record.
Known issues / Roadmap
models is done on each view request, so this hits very little, but a bit,
the overall performance of the system.