mirror of
https://github.com/NaN-tic/trytond-party_relationship.git
synced 2023-12-14 04:33:10 +01:00
Update reverse definition when defining a reverse type
This commit is contained in:
parent
4c029cd83a
commit
34fb1473b1
1 changed files with 23 additions and 0 deletions
23
party.py
23
party.py
|
@ -3,6 +3,7 @@ from sql import Union, As
|
|||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.model import ModelSQL, ModelView, fields
|
||||
from trytond.pyson import Eval
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
__all__ = ['RelationType', 'PartyRelation', 'PartyRelationAll', 'Party']
|
||||
__metaclass__ = PoolMeta
|
||||
|
@ -24,6 +25,28 @@ class RelationType(ModelSQL, ModelView):
|
|||
'Relation Type cannot be linked to itself.'),
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def create(cls, vlist):
|
||||
types = super(RelationType, cls).create(vlist)
|
||||
for type_ in types:
|
||||
reverse = type_.reverse
|
||||
if reverse:
|
||||
reverse.reverse = type_
|
||||
reverse.save()
|
||||
return types
|
||||
|
||||
@classmethod
|
||||
def write(cls, types, values):
|
||||
transaction = Transaction()
|
||||
context = transaction.context
|
||||
super(RelationType, cls).write(types, values)
|
||||
if 'reverse' in values and not context.get('write_reverse', False):
|
||||
with transaction.set_context(write_reverse=True):
|
||||
reverse = cls(values['reverse'])
|
||||
for type_ in types:
|
||||
reverse.reverse = type_
|
||||
reverse.save()
|
||||
|
||||
|
||||
class PartyRelation(ModelSQL):
|
||||
'Party Relation'
|
||||
|
|
Loading…
Reference in a new issue