Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
4 Răspunsuri
17939 Vizualizări

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

Imagine profil
Abandonează

post your code to have a closer look

Autor

Just pasted my code...

Cel mai bun răspuns

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

Imagine profil
Abandonează

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

Cel mai bun răspuns

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

Hope it helps,

Thanks

Imagine profil
Abandonează
Autor Cel mai bun răspuns

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

Imagine profil
Abandonează

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

 

Cel mai bun răspuns

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,

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
oct. 22
3831
8
feb. 17
8373
0
ian. 17
5878
2
feb. 24
12581
1
oct. 22
3340