Closed L0PiTaL closed 3 years ago
I just checked JS code in Odoo 10. Field widget declaration in Odoo 10 is difference from Odoo 11, 12,... so this plugin does not support.
Ok, so the setup is correct. I was doubting because I saw that it was implemented, and didn't know if it was a bug or an incorrect installation.
A quick look at the code (I am by no means expert in Java or Regex), it seems that you take the variable from the require and then pase the add (in OdooJSFieldWidgetIndex.java):
var fieldRegistry = require('web.field_registry'); fieldRegistry.add('my-custom-field', CustomFieldChar);
and match the 'my-custom-field', am I right?
If so, it seems pretty easy to addapt to Odoo10, since the registry happens in a similar way:
var core = require('web.core'); core.form_widget_registry.add('my-custom-field', CustomFieldChar);
Note that it could be several _registry. I think it would be enough with form_widget_registry and list_widget_registry.
Then you could match for 'field_registry' or 'core' in the variable name regex, and then add an optional '.*_registry' to the add regex.
This would work, since web.core does not contain any field called "add", so var.add will only match if it is Odoo11+ matched with web.field_registry.
I have attached a pull request with these changes. Please review it and give me any comments (note that I could not test it, since I don't know how to debug plugins for PyCharm)
@L0PiTaL Thank you for your PR. I also think it is easy enough to adapt to Odoo 10. Hope that I can make a new release for it this week.
@trinhanhngoc Hi, sorry for the late reply. I have been checking out the commit, and I am not sure it will work. It checks for the existence of "core.form_widget_registry" (or "core.list_widget_registry"), but this is not always the case, since "core" is the variable name assigned to the "require(web.core)" result, so it is not warranteed that it will be always "core" (in a similar way as it is in v11+, where you have two different regexes, one for looking for the var name, and other for looking for the add methods).
Check my previous PR, where I modified the variable search regex in order to look for requireing both, web.core and web.field_registry, and afterwards, the adding regex is also modified to include ".form_widget_registry" or ".list_widget_registy" before the ".add".
Since you have preferred to split v10 and v11+ with an if, it could also be done by having two different sets of regexes: try searching for the v11+ var first (looking for require("web.field_registry") and if it is not found, then try the regexes for v10.
@L0PiTaL Hi. I have just looked at your PR again and yes, your solution is better, thanks ;)
Hi, Just to let you know, I have updated today the module and it is working perfectly in Odoo 10! Thank you very much!
Problem:
When specifying the widget type for a field in a XML file, it is always marked as an error. I. e. for a Monetary field, the following is marked with the following error: "Cannot resolve symbol 'monetary' ":
<field name="product_cost" widget='monetary'/>
The same occurs for the widget 'many2many_tags', used with "tags". In this case, it is a Many2many field, and the error is "Cannot resolve symbol 'many2many_tags' ":
<field name="analytic_tag_ids" widget="many2many_tags"/>
This is pretty similar to the issues: https://github.com/trinhanhngoc/pycharm-odoo/issues/19 and https://github.com/trinhanhngoc/pycharm-odoo/issues/17
But in my setup it does not autocomplete anything, and all the widgets are marked as error. Note that all other fields (models, forms, fields, methods, etc...) are detected and working fine. Only the widget property is not working as expected.
Desired behaviour:
When specifying property "widget" for tag "field", it should autocomplete all the known widgets, and don't mark them as error. Only unknown widgets should be marked as error.
Setup:
Pycharm-Odoo version: 4.8 Pycharm version: 2020.3.2 Odoo version: 10.0 (latest github commit)