How to use party.replace?

I’m wondering how to use party.replace on One2Many fields and on Function fields. Are there any examples?

My fields are:

class Party(metaclass=PoolMeta):
    __name__ = 'party.party'

    organisation = fields.Many2One('party.party', 'Organisation')
    contacts = fields.One2Many('party.party', 'organisation', 'Contacts')

class Move(metaclass=PoolMeta):
    __name__ = 'stock.move'

    party = fields.Function(
        fields.Many2One('party.party', 'Party'),
        'on_change_with_party')

You can find examples on the source code for party module:

You only need to include them on to fields_to_replace:


class PartyReplace(metaclass=PoolMeta):
    __name__ = 'party.replace'

    @classmethod
    def fields_to_replace(cls):
        return super(PartyReplace, cls).fields_to_replace() + [
            ('organisation', 'party'),
            ]

You may also want to make active=False the source records as the party addresses does.

Thanks for the tip. Anyhow organisation in the example is Many2One, while I’m seeking examples for One2Many and Function.

Function fields do not store any data so it is their source that must be replaced.
One2Many use case was not considered in the implementation because party being referential, it is odd to have it inside such field.

1 Like

this is how I did it:

for this data: