Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
4 Trả lời
17929 Lượt xem

I need to set a specific domain on a fields B (sale_order.carrier_id in my case) base on another field A (sale_order.partner_id in my case).

How can I do that so that it works in all use cases, especially when EDITING an existing record. I made bunch of code on the @api.onchange('partner_id') to realize the code isn't triggered when the record is edited! I try to find a way to set this domain when the record gets edited as well with no success. Not fun :(

I really hope there is a solution to that problem!!

Ảnh đại diện
Huỷ bỏ

post your code to have a closer look

Tác giả

Just pasted my code...

Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ

Hi Niyas, great post, tried and notice that for V14, we do not need to put @api.multi if not it will throw an error.

I'm modifying existing module Project. How to do I write this using xpath?

.. code-block:: xml

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

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

Câu trả lời hay nhất

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

Hope it helps,

Thanks

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

Here is my code:

@api.onchange('partner_id') def onchange_partner_id_dtype(self):

super(SaleOrder, self).onchange_partner_id_dtype()

option_default_obj = self.env['delivery.option.default']

domain = option_default_obj.get_domain_set_values_for_onchange_partner_id(self)

return {'domain': domain}

After having coded this function, I realized that this is not executed when editing existing records. Therefore the domain restriction returned by option_default_obj.get_domain_set_values_for_onchange_partner_id(self) isn't applied. How can I apply it on record edit? Or at form load??

Ảnh đại diện
Huỷ bỏ

Have you got it..? I have the same problem.

This feature with return domain by _onchange_ method are not supported now...
see:
https://github.com/odoo/odoo/pull/41918#issuecomment-824946980

add a domain field with compute is the correct way...




Bonjour,

 

Je suis absent et serai de retour le 25 mars.

 

Merci

 

Câu trả lời hay nhất

Hi there,

To put domain on field "carried_id", you need this code:

    domain['carrier_id'] = #yourdomain
    return {'domain': domain}

Also, please print this domain so we could see : 

        domain = option_default_obj.get_domain_set_values_for_onchange_partner_id(self)       

Regards,

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 10 22
3823
8
thg 2 17
8367
0
thg 1 17
5875
2
thg 2 24
12580
1
thg 10 22
3335