콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
4 답글
10080 화면

How can we use dynamic domains in new Odoo API?

I'm trying to do it, I have an Many2one field, and a compute One2many field. Options to be select by Many2one field should be in this One2many field.

Here are my code lines:

    days = fields.One2many('af.week.day', string='Class days', compute='_compute_days',
                           help='Week days in which this group has classes')
    day_of_week = fields.Many2one('af.week.day', string='Day of week', domain="[('id','in',days)]")

아바타
취소
작성자

Any idea? In old api we can use something like this: def onchange_type(self,cr,uid,ids, type,context=None): product_obj = self.pool.get('product.product') product_ids = product_obj.search(cr,uid, [('type','=',type)]) return {'domain':{'product_id':[('id','in',product_ids)]}} But in new api... Thanks in advanced!

작성자

No anwers?

Send the real example what you did from your side. here in comment you have given the example of onchange method what you want to do it. you can not set dynamic domain on onchange method. give more description of your requirement. dynamic domain can be set by overriding search method of that particular model.

베스트 답변

In the new Odoo API it is the same as in Version 7.0. Look at this example:

@api.onchange('field')
def onchange_field(self):
    if condition_a:
        return {
            'domain': {
                'field_b': [('domain', '=', 'something')],
            },
        }
    else:
        return {
            'domain': {
                 'field_b': [('domain', '=', 'something_else')],
            },
        }

아바타
취소
베스트 답변

You can follow this: https://youtu.be/XGqXEL2qQmE 

Hope it helps, Thanks

아바타
취소
베스트 답변

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

아바타
취소
베스트 답변

Dynamic domain can only be implemented in view.  You can add domain attribute for the field tag and it can accept any other fields' name within the domain.

아바타
취소