Skip to Content
Menu
This question has been flagged
4 Replies
19387 Views

two fields many2one both are different form form-1 1.plan_category plan-1 plan-2 form-2 2.sub_pan sub plan-1 sub plan-2

in third form select plan category in onchange event on display subplan

Avatar
Discard
Best Answer

Hi,

Other than returning domain in onchange method, you can use the web domain field module from oca for the same:  Web Domain Field


See this: Return Dynamic Domain For Field In Odoo


How to use:

.. code-block:: xml

<field name="product_id_domain" invisible="1"/>
<field name="product_id" domain="product_id_domain"/>


.. code-block:: python

product_id_domain = fields.Char(
compute="_compute_product_id_domain",
readonly=True,
store=False,
)

@api.multi
@api.depends('name')
def _compute_product_id_domain(self):
for rec in self:
rec.product_id_domain = json.dumps(
[('type', '=', 'product'), ('name', 'like', rec.name)]
)

Returning domain from the onchange function: How To Give Domain For A Field Based On Another Field

Thanks

Avatar
Discard
Best Answer

Hi,

I just understood the title :D,

So, the onchange function can return a domain like:

res = {'domain': {'field_name': [domain like ('id', 'in', list_of_ids)]}}
return res

So every time this function is called you can do your calculation and pass the result to the domain...

I hope this could helps you ...

Regards..

Avatar
Discard
Author

thanks sir

Best Answer

Hi, 

You can watch following video for this:

https://youtu.be/ezH3ql5Dmx4

Thanks

Avatar
Discard
Best Answer
Added same code, getting a traceback.

Traceback: TypeError: CreateListFromArrayLike called on non-object at http://localhost:8014/web/content/3571-1e2f158/web.assets_backend.js:367:20 at _.each._.forEach (http://localhost:8014/web/content/3947-253c74a/web.assets_common.js:108:558) at _. [as each] (http://localhost:8014/web/content/3947-253c74a/web.assets_common.js:165:526) at eval_domains (http://localhost:8014/web/content/3571-1e2f158/web.assets_backend.js:364:265) at Object.pyeval [as eval] (http://localhost:8014/web/content/3571-1e2f158/web.assets_backend.js:389:24) at OdooClass.stringToArray (http://localhost:8014/web/content/3571-1e2f158/web.assets_backend.js:331:147) at Class._getDomain (http://localhost:8014/web/content/3571-1e2f158/web.assets_backend.js:1523:167) at Class._search (http://localhost:8014/web/content/3571-1e2f158/web.assets_backend.js:1110:607) at http://localhost:8014/web/content/3571-1e2f158/web.assets_backend.js:1102:260 at _.each._.forEach (http://localhost:8014/web/content/3947-253c74a/web.assets_common.js:108:558)


Avatar
Discard
Related Posts Replies Views Activity
1
Oct 23
1000
2
Oct 23
1319
2
Aug 23
2995
3
Oct 22
9896
3
Mar 22
36459