Skip to content
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

[9.0] [ADD] New web_domain_field addon #567

Closed
wants to merge 1 commit into from

Conversation

lmignon
Copy link
Sponsor Contributor

@lmignon lmignon commented Mar 1, 2017

@lmignon
Copy link
Sponsor Contributor Author

lmignon commented Mar 1, 2017

ping @adrienpeiffer

@lmignon lmignon force-pushed the 9.0-add_web_domain_field-lmi branch 2 times, most recently from 3b43896 to 64db070 Compare March 1, 2017 12:22
@rousseldenis
Copy link
Sponsor Contributor

So great, why don't you push it into OCB/web as it could be naturally included in everything?

@zakiuu
Copy link
Contributor

zakiuu commented Mar 6, 2017

@lmignon I'm facing some issues with this PR, the domain using field_id_domain works great, but I'm having bugs for domains that are defined directly on the field in the ORM side

@lmignon
Copy link
Sponsor Contributor Author

lmignon commented Mar 6, 2017

@zakiuu What's your problem? Do you try to put the field name directly into the domain put on an other field definition into the python code? Indeed this use case is not tested.

@zakiuu
Copy link
Contributor

zakiuu commented Mar 6, 2017

@lmignon Nope, If I take for example this domain from product_variant_configurator module,
value_id = fields.Many2one( comodel_name='product.attribute.value', domain="[('attribute_id', '=', attribute_id), " " ('id', 'in', possible_value_ids[0][2])]", string='Value')
I'm getting a javascript error when your module is installed

@lmignon
Copy link
Sponsor Contributor Author

lmignon commented Mar 6, 2017

@zakiuu It's fixed

@zakiuu
Copy link
Contributor

zakiuu commented Mar 6, 2017

@lmignon thanks, I'll test it

@zakiuu
Copy link
Contributor

zakiuu commented Mar 6, 2017

@lmignon works great thanks

@zakiuu
Copy link
Contributor

zakiuu commented Mar 14, 2017

@lmignon I got another bug, it occurs when clicking on search more on a field that uses the new domain
Uncaught TypeError: CreateListFromArrayLike called on non-object http://localhost:8069/web/content/1530-8eb95b8/web.assets_backend.js:3122 Retraçage : TypeError: CreateListFromArrayLike called on non-object at http://localhost:8069/web/content/1530-8eb95b8/web.assets_backend.js:3122:100 at Function._.each._.forEach (http://localhost:8069/web/content/1495-013002c/web.assets_common.js:12:558) at _.(anonymous function) [as each] (http://localhost:8069/web/content/1495-013002c/web.assets_common.js:69:526) at eval_domains (http://localhost:8069/web/content/1530-8eb95b8/web.assets_backend.js:3121:147) at http://localhost:8069/web/content/1530-8eb95b8/web.assets_backend.js:3122:301 at Function._.each._.forEach (http://localhost:8069/web/content/1495-013002c/web.assets_common.js:12:558) at _.(anonymous function) [as each] (http://localhost:8069/web/content/1495-013002c/web.assets_common.js:69:526) at eval_domains (http://localhost:8069/web/content/1530-8eb95b8/web.assets_backend.js:3121:147) at pyeval (http://localhost:8069/web/content/1530-8eb95b8/web.assets_backend.js:3132:24) at Object.sync_eval_domains_and_contexts (http://localhost:8069/web/content/1530-8eb95b8/web.assets_backend.js:3142:165)

@lmignon lmignon force-pushed the 9.0-add_web_domain_field-lmi branch from 64221f9 to 45ce0b0 Compare March 15, 2017 11:00
@lmignon
Copy link
Sponsor Contributor Author

lmignon commented Mar 15, 2017

@zakiuu it's fixed with the override of sync_eval_domains_and_contexts 45ce0b0#diff-f760f293b9587c1f50a65e794fd45953R219

@fva-idealis
Copy link

fva-idealis commented Apr 11, 2017

Hi @lmignon,

Thanks for your module.
I make some tests with your module and it's great but it's still one missing feature.
How can I define a model on parent model and use it for a child ?

My example:

<group>
       <field name="all_location_ids" invisible="1"/>
</group>
<group string="Locations">
      <field name="bind_location_ids" nolabel="1" >
             <tree string="Locations" editable="bottom">
                   <field name="local_location_id" domain="[('company_id', 'in', (parent.local_company_id, False))]"/>
                   <field name="external_location_id" domain="parent.all_location_ids"/>
             </tree>
       </field>
</group>

domain="parent.all_location_ids" doesn't work. I got the error:

Uncaught TypeError: CreateListFromArrayLike called on non-object

If the domain is defined on the same it's works. But for performance reasons I need to compute the domain on parent.

I ported and tested your module on V10 local. I don't know if this is why. I didn't change anything except the manifest.py

Thank you

PS: parent.something worked before Odoo changes with [0][2] domains

@mbcosta
Copy link

mbcosta commented Apr 11, 2017

Hi @lmignon
I am testing your module to make a domain in product_id on Purchase Order Line to show only products belong to the partner_id, in the tests I saw that when the quantity of products to create domain are few the domain works fine but when quantity are a lot, in some case about 2000, when you click "Add a Item" in purchase line and quickly click in Product to choose one receive this error:

Uncaught TypeError: CreateListFromArrayLike called on non-object
http://localhost:8069/web_domain_field/static/src/js/pyeval.js:178
Traceback:
TypeError: CreateListFromArrayLike called on non-object
at http://localhost:8069/web_domain_field/static/src/js/pyeval.js:178:36
at Function..each..forEach (http://localhost:8069/web/static/lib/underscore/underscore.js:145:9)
at .(anonymous function) [as each] (http://localhost:8069/web/static/lib/underscore/underscore.js:1484:34)
at eval_domains (http://localhost:8069/web_domain_field/static/src/js/pyeval.js:170:16)
at http://localhost:8069/web_domain_field/static/src/js/pyeval.js:196:32
at Function.
.each..forEach (http://localhost:8069/web/static/lib/underscore/underscore.js:145:9)
at .(anonymous function) [as each] (http://localhost:8069/web/static/lib/underscore/underscore.js:1484:34)
at eval_domains (http://localhost:8069/web_domain_field/static/src/js/pyeval.js:170:16)
at http://localhost:8069/web_domain_field/static/src/js/pyeval.js:196:32
at Function.
.each.
.forEach (http://localhost:8069/web/static/lib/underscore/underscore.js:145:9)

But if you instead just wait a few seconds after click in "Add a Item" to select the product the domain works, it seems the javascript is faster than calculate domain field and by this reason return error.

I don't have enough knowledge about JavaScript, but maybe is need in some way put the black screen "Loading" while the domain field is calculate to avoid users click on the field and receive this error.

@mbcosta
Copy link

mbcosta commented May 11, 2017

If someone pass through the same problem as I described above there is a workaround ( this is not a solution ) :

--- a/addons/web/static/src/js/views/form_relational_widgets.js
+++ b/addons/web/static/src/js/views/form_relational_widgets.js
@@ -271,9 +271,41 @@ var FieldMany2One = common.AbstractField.extend(common.CompletionFieldMixin
, com
         // autocomplete
         this.$input.autocomplete({
             source: function(req, resp) {
-                self.get_search_result(req.term).done(function(result) {
-                    resp(result);
-                });
+                try {
+                    self.get_search_result(req.term).done(function(result) {
+                        resp(result);
+                    });
+                }
+                catch(e) {
+                    if (e instanceof TypeError) {
+                        setTimeout(function(){
+
+                            try {
+                                self.get_search_result(req.term).done(function(result) {
+                                    resp(result);
+                                });
+                            }
+                            catch(e) {
+                                if (e instanceof TypeError) {
+                                    setTimeout(function(){
+                                        self.get_search_result(req.term).done(function(result)
{
+                                        resp(result);
+                                        });
+                                        }, 5000);
+                                } else {
+                                  throw e; // let others bubble up
+                                }
+
+                            }
+
+
+                            }, 1000);
+                    } else {
+                      throw e; // let others bubble up
+                    }
+
+                }
+
             },
             select: function(event, ui) {
                 isSelecting = true;

This is ugly code but works, thanks to @rvalyi for help me on this problem, we didn't have enough time to make a better solution.

@github-actions
Copy link

There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label Feb 13, 2022
@github-actions github-actions bot closed this Mar 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale PR/Issue without recent activity, it'll be soon closed automatically.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants