Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odgovori
735 Prikazi

I have a field many2many and filter domain added in onchange of customer_id.It actually work when customer id changed the domain worked correctly for the many2many field but when i duplicate the record the onchnage function is not calling.
i want the filter domain when i duplicate the record also
odoo13

Avatar
Opusti
Best Answer

Hi,
You will have problem in the original record with the domain if you follow this method.

* Save the original record
* refresh the screen and see the field, now you wont have the domain

As a stable method, you can use the web domain module from the OCA, see how you can use it: Return Dynamic Domain For Field In Odoo

Thanks

Avatar
Opusti
Best Answer

Hi,

In Odoo, when you duplicate a record, the onchange methods are not triggered automatically. This is because duplicating a record is essentially creating a new record with the same values as the original record, without triggering any field change events.

To achieve your requirement of applying the filter domain when duplicating a record, you can Override the copy method of your model to manually trigger the onchange method after duplicating the recordExample:@api.model
    def copy(self, default=None):
        # Call super to perform the default copy operation
        new_record = super(YourModel, self).copy(default=default)

        # Retrieve the record's customer_id
        customer_id = new_record.customer_id

        # Call the onchange method of customer_id to trigger the domain filter
        new_record.onchange_customer_id(customer_id)

        return new_record


Hope it helps

Avatar
Opusti