İçereği Atla
Menü
Bu soru işaretlendi
4 Cevaplar
18018 Görünümler

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

Avatar
Vazgeç

post your code to have a closer look

Üretici

Just pasted my code...

En İyi Yanı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

Avatar
Vazgeç

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"/>

En İyi Yanıt

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

Hope it helps,

Thanks

Avatar
Vazgeç
Üretici En İyi Yanı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??

Avatar
Vazgeç

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

 

En İyi Yanı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,

Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Eki 22
3854
8
Şub 17
8399
0
Oca 17
5916
2
Şub 24
12607
1
Eki 22
3365