Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
4 Odpowiedzi
17932 Widoki

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

Awatar
Odrzuć

post your code to have a closer look

Autor

Just pasted my code...

Najlepsza odpowiedź

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

Awatar
Odrzuć

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

Najlepsza odpowiedź

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

Hope it helps,

Thanks

Awatar
Odrzuć
Autor Najlepsza odpowiedź

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

Awatar
Odrzuć

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

 

Najlepsza odpowiedź

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,

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
paź 22
3824
8
lut 17
8370
0
sty 17
5878
2
lut 24
12580
1
paź 22
3338