htgoebel
(Hartmut Goebel)
May 31, 2023, 12:12pm
1
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')
acaubet
(Adrià Tarroja Caubet)
May 31, 2023, 12:28pm
2
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.
htgoebel
(Hartmut Goebel)
May 31, 2023, 1:31pm
3
Thanks for the tip. Anyhow organisation
in the example is Many2One
, while I’m seeking examples for One2Many
and Function
.
ced
(Cédric Krier)
May 31, 2023, 9:55pm
4
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