跳至内容
菜单
此问题已终结
4 回复
19958 查看

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

形象
丢弃
最佳答案

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

形象
丢弃
最佳答案

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..

形象
丢弃
编写者

thanks sir

最佳答案

Hi, 

You can watch following video for this:

https://youtu.be/ezH3ql5Dmx4

Thanks

形象
丢弃
最佳答案
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)


形象
丢弃
相关帖文 回复 查看 活动
1
10月 23
1540
2
10月 23
1790
2
8月 23
3641
3
10月 22
10477
3
3月 22
36863