Add a Party Relation using Proteus

Trying to add a party.relation to a newly created party in a proteus script like this:

        party = Party()
        Relation = Model.get('party.relation')
        RelationType = Model.get('party.relation.type')
        [...]
        (party is filled here)
        [...]
        party.save()

        relation = Relation()
        relation.from_ = party
        relation.to = Party(x)  # x gives the party to relate to
        relation.type = RelationType(y) # y gives the relation type
        relation.save()

the following Error is thrown:

Traceback (most recent call last):
[...]
  File "/[...]/tryton-server-6.6/env/lib/python3.11/site-packages/proteus/__init__.py", line 102, in newfunc
    return self.func(owner, [instance], *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/[...]/tryton-server-6.6/env/lib/python3.11/site-packages/proteus/__init__.py", line 855, in save
    ids = proxy.create(values, context)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/[...]/tryton-server-6.6/env/lib/python3.11/site-packages/proteus/config.py", line 194, in __call__
    raise TypeError('%s is not callable' % self._name)
TypeError: create is not callable

Could someone please tell me how to add a party.relation using Proteus, or just tell me what is the problem here?

You can not use from RPC a model that does not inherit from ModelView (it is an internal model).
You must use party.relation.all or even better use party.relations.new().

Thank you @ced, it’s so easy but I did not see it.

        relation = party.relations.new()
        relation.to = Party(x)
        relation.type = RelationType(y)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.